EASTRON SDM120C - RS485 Modbus meter

Pongo
Posts: 30
Joined: Thu Sep 19, 2013 1:18 pm

Re: EASTRON SDM120C - RS485 Modbus meter

Post by Pongo » Mon Feb 02, 2015 11:07 am

In new version 1.1.0 I added compatibility with both versions 3.0.x and 3.1.x of libmodbus.
The code should recognize automatically libmodbus version and use correct code (on Raspbian it does, I compiled succesfully with 3.0.3, 3.0.6, 3.1.1).

What libmodbus version are you using?
What these commands return ?

Code: Select all

pkg-config --cflags libmodbus
pkg-config --libs libmodbus
on mine

Code: Select all

pi@raspberrypi ~ $ pkg-config --cflags libmodbus
-I/usr/include/modbus
pi@raspberrypi ~ $ pkg-config --libs libmodbus
-lmodbus
It seems that sdm120c.c found 3.1.x version, but on modbus.h there are 3.0.x prototypes.
What these commands return (spaces matters) ?

Code: Select all

grep modbus_get_response_timeout `pkg-config --cflags libmodbus | cut -d- -f2 | cut -dI -f2 | cut -d\  -f1`/modbus.h

Code: Select all

grep LIBMODBUS_VERSION_STRING `pkg-config --cflags libmodbus | cut -d- -f2 | cut -dI -f2 | cut -d\  -f1`/modbus-version.h
on mine

Code: Select all

pi@raspberrypi ~ $ grep modbus_get_response_timeout `pkg-config --cflags libmodbus | cut -d- -f2 | cut -dI -f2 | cut -d\  -f1`/modbus.h
MODBUS_API int modbus_get_response_timeout(modbus_t *ctx, uint32_t *to_sec, uint32_t *to_usec);
pi@raspberrypi ~ $ grep LIBMODBUS_VERSION_STRING `pkg-config --cflags libmodbus | cut -d- -f2 | cut -dI -f2 | cut -d\  -f1`/modbus-version.h
#define LIBMODBUS_VERSION_STRING "3.1.1"
pi@raspberrypi ~ $ sdm120c  | egrep 'sdm120c.*RTU'
sdm120c 1.1.0: ModBus RTU client to read EASTRON SDM120C smart mini power meter registers
pi@raspberrypi ~ $ sdm120c  | grep libmodbus
Complied with libmodbus 3.1.1
on another system I have

Code: Select all

pi@pi-alarm ~ $ grep modbus_get_response_timeout `pkg-config --cflags libmodbus | cut -d- -f2 | cut -dI -f2 | cut -d\  -f1`/modbus.h
void modbus_get_response_timeout(modbus_t *ctx, struct timeval *timeout);
pi@pi-alarm ~ $ grep LIBMODBUS_VERSION_STRING `pkg-config --cflags libmodbus | cut -d- -f2 | cut -dI -f2 | cut -d\  -f1`/modbus-version.h
#define LIBMODBUS_VERSION_STRING "3.0.3"
pi@pi-alarm ~ $ sdm120c  | egrep 'sdm120c.*RTU'
sdm120c 1.1.0: ModBus RTU client to read EASTRON SDM120C smart mini power meter registers
pi@pi-alarm ~ $ sdm120c  | grep libmodbus
Complied with libmodbus 3.0.3
Last edited by Pongo on Mon Feb 02, 2015 11:25 am, edited 1 time in total.

jeanmarc
Posts: 1853
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Mon Feb 02, 2015 11:21 am

Hi,
Thanks. I use libmodbus-3.1.1.
Here's the output :

Code: Select all

[root@plugbox SDM120C]# pkg-config --cflags libmodbus
-I/usr/local/include/modbus 
[root@plugbox SDM120C]# pkg-config --libs libmodbus
-L/usr/local/lib -lmodbus 
[root@plugbox SDM120C]# grep modbus_get_response_timeout `pkg-config --cflags libmodbus | cut -d- -f2 | cut -dI -f2 | cut -d\  -f1`/modbus.h
MODBUS_API int modbus_get_response_timeout(modbus_t *ctx, struct timeval *timeout);
[root@plugbox SDM120C]# grep LIBMODBUS_VERSION_STRING `pkg-config --cflags libmodbus | cut -d- -f2 | cut -dI -f2 | cut -d\  -f1`/modbus-version.h
#define LIBMODBUS_VERSION_STRING "3.1.1"

Pongo
Posts: 30
Joined: Thu Sep 19, 2013 1:18 pm

Re: EASTRON SDM120C - RS485 Modbus meter

Post by Pongo » Mon Feb 02, 2015 11:33 am

There is a difference
MODBUS_API int modbus_get_response_timeout(modbus_t *ctx, struct timeval *timeout);
#define LIBMODBUS_VERSION_STRING "3.1.1"
MODBUS_API int modbus_get_response_timeout(modbus_t *ctx, uint32_t *to_sec, uint32_t *to_usec);
#define LIBMODBUS_VERSION_STRING "3.1.1"
How do you downloaded libmodbus?
I used pre 3.1.2 version

Code: Select all

pi@pi-alarm ~/modbus $ git clone https://github.com/stephane/libmodbus.git
Probably you downloaded the .tar.gz

jeanmarc
Posts: 1853
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Mon Feb 02, 2015 11:36 am

Yes, i download that one (2013-10-06)
What can i do now ? ;)

Pongo
Posts: 30
Joined: Thu Sep 19, 2013 1:18 pm

Re: EASTRON SDM120C - RS485 Modbus meter

Post by Pongo » Mon Feb 02, 2015 11:51 am

OK, I noticed that libmodbus author changed some API without changing version.
You could modify, for now, sdmc120.c
from

Code: Select all

#if LIBMODBUS_VERSION_MAJOR >= 3 && LIBMODBUS_VERSION_MINOR >= 1
    uint32_t resp_timeout = 2;
#else
    time_t resp_timeout   = 2;
#endif
to

Code: Select all

    time_t resp_timeout   = 2;
and from

Code: Select all

#if LIBMODBUS_VERSION_MAJOR >= 3 && LIBMODBUS_VERSION_MINOR >= 1

    uint32_t old_response_to_sec;
    uint32_t old_response_to_usec;

    modbus_get_response_timeout(ctx, &old_response_to_sec, &old_response_to_usec);

    // Considering to get those values from command line
    modbus_set_byte_timeout(ctx, -1, 0);
    modbus_set_response_timeout(ctx, resp_timeout, 0);

#else

    struct timeval old_response_timeout;
    struct timeval response_timeout;

    modbus_get_response_timeout(ctx, &old_response_timeout);
    response_timeout.tv_sec = -1;
    response_timeout.tv_usec = 0;
    modbus_set_byte_timeout(ctx, &response_timeout);
    response_timeout.tv_sec = resp_timeout;
    response_timeout.tv_usec = 0;
    modbus_set_response_timeout(ctx, &response_timeout);

#endif
to

Code: Select all

    struct timeval old_response_timeout;
    struct timeval response_timeout;

    modbus_get_response_timeout(ctx, &old_response_timeout);
    response_timeout.tv_sec = -1;
    response_timeout.tv_usec = 0;
    modbus_set_byte_timeout(ctx, &response_timeout);
    response_timeout.tv_sec = resp_timeout;
    response_timeout.tv_usec = 0;
    modbus_set_response_timeout(ctx, &response_timeout);
or download via git.

sorry for the inconvenience, I will try to correct

jeanmarc
Posts: 1853
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Mon Feb 02, 2015 12:05 pm

Thanks, it work but i still get odd results if i request only -i and/or -e alone ;)

Code: Select all

[root@plugbox SDM120C]# sdm120c -a1 -p -v -c -f -g -e -i -t  /dev/ttyUSB1
Voltage: 233.97 V 
Current: 1.34 A 
Power: -310.12 W 
Power Factor: -0.99 
Frequency: 49.98 Hz 
Import Active Energy: 29132 Wh 
Export Active Energy: 3166 Wh 
Total Active Energy: 32298 Wh 
[root@plugbox SDM120C]# sdm120c -a1 -i /dev/ttyUSB1
Import Active Energy: 233363 Wh 
[root@plugbox SDM120C]# sdm120c -a1 -e /dev/ttyUSB1
Export Active Energy: 232798 Wh 

Pongo
Posts: 30
Joined: Thu Sep 19, 2013 1:18 pm

Re: EASTRON SDM120C - RS485 Modbus meter

Post by Pongo » Mon Feb 02, 2015 12:14 pm

And using ?

Code: Select all

sdm120c -a1 -i -e /dev/ttyUSB1
Try to add -d parameter to see some debug info

On my system

Code: Select all

pi@raspberrypi ~ $ sdm120c -a 2 -b 9600 -e -z 10 /dev/ttyUSB0
Export Active Energy: 0 Wh
pi@raspberrypi ~ $ sdm120c -a 2 -b 9600 -i -z 10 /dev/ttyUSB0
Import Active Energy: 10350 Wh
pi@raspberrypi ~ $ sdm120c -a 2 -b 9600 -i -e -z 10 /dev/ttyUSB0
Import Active Energy: 10350 Wh
Export Active Energy: 0 Wh
pi@raspberrypi ~ $ sdm120c -a 2 -b 9600 -z 10 /dev/ttyUSB0
Voltage: 237.90 V
Current: 0.00 A
Power:  0.00 W
Power Factor: 1.00
Frequency: 50.04 Hz
Import Active Energy: 10350 Wh
Export Active Energy: 0 Wh
Total Active Energy: 10350 Wh
I always have same values, but I don't have a bidirectional connection and I use SDM120C

jeanmarc
Posts: 1853
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Mon Feb 02, 2015 12:20 pm

Well, it is not a big issue. I retrieve all values everytime, so i get correct import/export energy, i believe :)

Code: Select all

[root@plugbox SDM120C]# sdm120c -a1 -i -e /dev/ttyUSB1
Import Active Energy: 233356 Wh
Export Active Energy: 3256 Wh 
[root@plugbox SDM120C]# sdm120c -a1 -p -i -e /dev/ttyUSB1
Power: 233.83 W 
Import Active Energy: 29132 Wh
Export Active Energy: 3257 Wh 
[root@plugbox SDM120C]# sdm120c -a1 -v -i -e /dev/ttyUSB1
Voltage: 239.00 V 
Import Active Energy: 29152 Wh 
Export Active Energy: 3285 Wh 
[root@plugbox SDM120C]# sdm120c -a1 -i -e -d /dev/ttyUSB1
Opening /dev/ttyUSB1 at 2400 bauds (E, 8, 1)
1/1. Register Address 30073 [0048]
[01][04][00][48][00][02][F1][DD]
Waiting for a confirmation...
<01><04><04><43><6F><55><2B><A1><52>
reg[0]=17263 (0x436F)
reg[1]=21803 (0x552B)
Import Active Energy: 239332 Wh 
1/1. Register Address 30075 [004A]
[01][04][00][4A][00][02][50][1D]
Waiting for a confirmation...
<01><04><04><40><52><4D><D3><3B><58>
reg[0]=16466 (0x4052)
reg[1]=19923 (0x4DD3)
Export Active Energy: 3286 Wh 

Pongo
Posts: 30
Joined: Thu Sep 19, 2013 1:18 pm

Re: EASTRON SDM120C - RS485 Modbus meter

Post by Pongo » Mon Feb 02, 2015 2:32 pm

And what is the result of

Code: Select all

sdm120c -a1 -d /dev/ttyUSB1

jeanmarc
Posts: 1853
Joined: Thu Aug 29, 2013 7:16 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Mon Feb 02, 2015 2:36 pm

Here it is :

Code: Select all

[root@plugbox SDM120C]# sdm120c -a1 -d /dev/ttyUSB1
Opening /dev/ttyUSB1 at 2400 bauds (E, 8, 1)
1/1. Register Address 30001 [0000]
[01][04][00][00][00][02][71][CB]
Waiting for a confirmation...
<01><04><04><43><68><3E><81><BF><DC>
reg[0]=17256 (0x4368)
reg[1]=16001 (0x3E81)
Voltage: 232.24 V 
1/1. Register Address 30007 [0006]
[01][04][00][06][00][02][91][CA]
Waiting for a confirmation...
<01><04><04><41><0C><AC><F0><52><FF>
reg[0]=16652 (0x410C)
reg[1]=44272 (0xACF0)
Current: 8.79 A 
1/1. Register Address 30013 [000C]
[01][04][00][0C][00][02][B1][C8]
Waiting for a confirmation...
<01><04><04><44><FE><81><7F><AF><34>
reg[0]=17662 (0x44FE)
reg[1]=33151 (0x817F)
Power: 2036.05 W 
1/1. Register Address 30031 [001E]
[01][04][00][1E][00][02][11][CD]
Waiting for a confirmation...
<01><04><04><3F><7F><42><E2><76><A1>
reg[0]=16255 (0x3F7F)
reg[1]=17122 (0x42E2)
Power Factor: 1.00 
1/1. Register Address 30071 [0046]
[01][04][00][46][00][02][90][1E]
Waiting for a confirmation...
<01><04><04><42><47><F0><90><1B><85>
reg[0]=16967 (0x4247)
reg[1]=61584 (0xF090)
Frequency: 49.98 Hz 
1/1. Register Address 30073 [0048]
[01][04][00][48][00][02][F1][DD]
Waiting for a confirmation...
<01><04><04><41><F0><26><E9><34><65>
reg[0]=16880 (0x41F0)
reg[1]=9961 (0x26E9)
Import Active Energy: 30019 Wh 
1/1. Register Address 30075 [004A]
[01][04][00][4A][00][02][50][1D]
Waiting for a confirmation...
<01><04><04><41><0C><AC><F0><52><FF>
reg[0]=16652 (0x410C)
reg[1]=44272 (0xACF0)
Export Active Energy: 8792 Wh 
1/1. Register Address 30343 [0156]
[01][04][01][56][00][02][90][27]
Waiting for a confirmation...
<01><04><04><42><47><F0><90><1B><85>
reg[0]=16967 (0x4247)
reg[1]=61584 (0xF090)
Total Active Energy: 49984 Wh 
[root@plugbox SDM120C]# sdm120c -a1 -e -i /dev/ttyUSB1
Import Active Energy: 231821 Wh 
Export Active Energy: 4034 Wh 
[root@plugbox SDM120C]# sdm120c -a1 -p -e -i /dev/ttyUSB1
Power: 231.64 W 
Import Active Energy: 30042 Wh 
Export Active Energy: 4034 Wh 

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest