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 3:52 pm

I think it could be a meter bug (or libmodbus bug).

Looking at debug log we can see, when result is wrong

Code: Select all

[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 
and when result is right

Code: Select all

[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
numbers in brackets [01][04][00][48][00][02][F1][DD] are input data sent to meter, are the same
It means: send message to device 0x01, using command 0x04 (read input register), at address 0x0048, reading 2 registers (0x0002), the CRC is 0xF1DD.
But result data is different, as you can see
<01><04><04><43><6F><55><2B><A1><52>
<01><04><04><41><F0><26><E9><34><65>
it means: device 0x01 replies at command 0x04 with a 0x04 (4) bytes value: 0x43 0x6F 0x55 0x2B (plus CRC) in the first case
device 0x01 replies at command 0x04 with a 0x04 (4) bytes value: 0x41 0xF0 0x26 0xE9 (plus CRC) in the second case

The value is a IEEE 754 format floating-point number. For example here http://www.h-schmidt.net/FloatConverter/IEEE754.html we can convert into normal floating point, passing 0x436F552B or 0x41F026E9 in Hexadecimal Representation, and results are 239.33269 and 30.019.

So... the program calculates correctly values from responses, but device returns different values for the same input.

The difference is that in one case the program opens connection to the meter and reads only one or both of energy values, in another case reads also other values.
Considering that on my meter this problem doesn't occur, I think it could be a meter bug
Last edited by Pongo on Mon Feb 02, 2015 4:36 pm, edited 1 time in total.

flane
Posts: 89
Joined: Mon Aug 11, 2014 7:22 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by flane » Mon Feb 02, 2015 4:11 pm

Hi Jean Marc,
test if it works this C script:
http://kmtronic.com/raspberry-pi-modbus ... ter-2.html

Does not use libmodbus.

With SDM120C works correctly.

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Mon Feb 02, 2015 4:42 pm

Thanks for the long explanation Pongo, i am a bit less stupid now ;)
@Flane, thanks for the tips, i actually compile with cc but got no data return with g++ i got a problem

Code: Select all

[root@plugbox tester]# g++ ModBusEnergyMeter2.c -o emeter
ModBusEnergyMeter2.c:12:2: warning: anonymous type with no linkage used to declare variable '<anonymous union> u' with linkage
 }u;
  ^

Code: Select all

[root@plugbox tester]# ./emeter 
Sent: 01 04 00 00 00 02 71 cb 
Received: 
Voltage: 0.00 V 

Sent: 01 04 00 06 00 02 91 ca 
Received: 
Current: 0.00 A 

Sent: 01 04 00 0c 00 02 b1 c8 
Received: 
Power: 0.00 W 

Sent: 01 04 00 12 00 02 d1 ce 
Received: 
Active Apparent Power: 0.00 VA 

Sent: 01 04 00 18 00 02 f1 cc 
Received: 01 
Reactive Apparent Power: 0.00 VAr 

Sent: 01 04 00 1e 00 02 11 cd 
Received: 
Power Factor: 0.00 

Sent: 01 04 00 46 00 02 90 1e 
Received: 
Frequency: 0.00 Hz 

Sent: 01 04 00 48 00 02 f1 dd 
Received: 
Import Active Energy: 0.00 KWh 

Sent: 01 04 00 4a 00 02 50 1d 
Received: 
Export Active Energy: 0.00 KWh 

Sent: 01 04 01 56 00 02 90 27 
Received: 
Total Active Energy: 0.00 KWh 
I did change the converter port and did a stty -F /dev/ttyUSB1 9600 cs8 parenb -parodd :?

flane
Posts: 89
Joined: Mon Aug 11, 2014 7:22 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by flane » Mon Feb 02, 2015 5:13 pm

In C script change the line:

Code: Select all

 int fd = open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NDELAY);
and if you have not changed the speed of the counter:

Code: Select all

stty -F /dev/ttyUSB1 2400 cs8 parenb -parodd
To compile I use:

Code: Select all

gcc ModBusEnergyMeter2.c -o sdm120c
My output:

Code: Select all

# ./sdm120c
Sent: 01 04 00 06 00 02 91 ca
Received: 01 04 04 3f 93 33 33 53 58
Current: 1.15 A

Sent: 01 04 00 0c 00 02 b1 c8
Received: 01 04 04 43 7e cc cd 1a 8d
Power: 254.80 W

Sent: 01 04 00 12 00 02 d1 ce
Received: 01 04 04 43 87 8b c7 79 4b
Active Apparent Power: 271.09 VA

Sent: 01 04 00 18 00 02 f1 cc
Received: 01 04 04 42 b8 92 e1 c2 f1
Reactive Apparent Power: 92.29 VAr

Sent: 01 04 00 1e 00 02 11 cd
Received: 01 04 04 3f 72 44 9c 64 e2
Power Factor: 0.95

Sent: 01 04 00 46 00 02 90 1e
Received: 01 04 04 42 48 28 f6 f1 ac
Frequency: 50.04 Hz

Sent: 01 04 00 48 00 02 f1 dd
Received: 01 04 04 43 20 4a c1 19 3a
Import Active Energy: 160.29 KWh

Sent: 01 04 00 4a 00 02 50 1d
Received: 01 04 04 00 00 00 00 fb 84
Export Active Energy: 0.00 KWh

Sent: 01 04 01 56 00 02 90 27
Received: 01 04 04 43 20 4b 02 58 fb
Total Active Energy: 160.29 KWh

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Mon Feb 02, 2015 5:23 pm

Well i did that but no data :roll:

Code: Select all

[root@plugbox tester]# gcc ModBusEnergyMeter2.c -o emeter
[root@plugbox tester]# stty -F /dev/ttyUSB1 2400 cs8 parenb -parodd
[root@plugbox tester]# ./emeter
Sent: 01 04 00 00 00 02 71 cb 
Received: 
Voltage: 0.00 V 

Sent: 01 04 00 06 00 02 91 ca 
Received: 
Current: 0.00 A 

Sent: 01 04 00 0c 00 02 b1 c8 
Received: 
Power: 0.00 W 

Sent: 01 04 00 12 00 02 d1 ce 
Received: 
Active Apparent Power: 0.00 VA 

Sent: 01 04 00 18 00 02 f1 cc 
Received: 01 
Reactive Apparent Power: 0.00 VAr 

Sent: 01 04 00 1e 00 02 11 cd 
Received: 
Power Factor: 0.00 

Sent: 01 04 00 46 00 02 90 1e 
Received: 
Frequency: 0.00 Hz 

Sent: 01 04 00 48 00 02 f1 dd 
Received: 
Import Active Energy: 0.00 KWh 

Sent: 01 04 00 4a 00 02 50 1d 
Received: 
Export Active Energy: 0.00 KWh 

Sent: 01 04 01 56 00 02 90 27 
Received: 
Total Active Energy: 0.00 KWh 

[root@plugbox tester]# 

flane
Posts: 89
Joined: Mon Aug 11, 2014 7:22 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by flane » Mon Feb 02, 2015 6:44 pm

Sorry,
default speed for SDM220 is 9600 baud, and default parity is none.

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Mon Feb 02, 2015 7:57 pm

Done a stty -F /dev/ttyUSB1 9600 cs8 -parity -cstopb, it should be 8N with same result..
Don't worry guy it not a big deal ;)

flane
Posts: 89
Joined: Mon Aug 11, 2014 7:22 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by flane » Mon Feb 02, 2015 9:21 pm

Jean Marc,
have also changed this line?

Code: Select all

 serial.c_cflag = B2400 | CS8 | PARENB | CREAD & ~PARODD;

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

Re: EASTRON SDM120C - RS485 Modbus meter

Post by jeanmarc » Tue Feb 03, 2015 3:28 pm

Well, i try that but it dosen't help either. It's probably a com issue sometime the app return a value a two

Code: Select all

[root@plugbox tester]# ./emeter
Sent: 01 04 00 00 00 02 71 cb
Received: 04 04 43 69 0f 23 7a 35 01
Voltage: 10815245345910587633172480.00 V
...

Code: Select all


[root@plugbox tester]# ./emeter
Sent: 01 04 00 00 00 02 71 cb
Received: 01 04 04 43 68 7f c6 cf be
Voltage: 232.50 V

Sent: 01 04 00 06 00 02 91 ca
Received: 01 04 04 3f 0d c3 4d f6 96 01
Current: 0.55 A

Sent: 01 04 00 0c 00 02 b1 c8
Received:
Power: 0.00 W
...
I did change ModBusEnergyMeter2.c port and speed. Then a stty -F /dev/ttyUSB1 9600 cs8 -parenb -cstopb
As i said.. no real worry ;)

pfiori
Posts: 19
Joined: Sun Feb 02, 2014 9:29 am

Re: EASTRON SDM120C - RS485 Modbus meter

Post by pfiori » Sat Feb 07, 2015 12:20 pm

hi all,

still trying to read SDM220 modbus

i made the attempt to use ModBusEnergyMeter2

changed the serial to ttyUSB0

set the serial

Code: Select all

$ stty -F /dev/ttyUSB0 9600 cs8 parenb -parodd
compiled on ubuntu 14.10 (testing on my pc)

Code: Select all

$ gcc ModBusEnergyMeter2.c -o emeter
$
then run

Code: Select all

$ ./emeter 
Sent: 01 04 00 00 00 02 71 ffffffcb 
Received: 7f ffffffdf ffffffff ffffffff fffffffb 1d 69 
Voltage: -nan V 

Sent: 01 04 00 06 00 02 ffffff91 ffffffca 
Received: 7f ffffffdf fffffff3 ffffffff fffffffb ffffffdd 0d 
Current: -nan A 

Sent: 01 04 00 0c 00 02 ffffffb1 ffffffc8 
Received: 7f ffffffdf ffffffe7 ffffffff fffffffb ffffff9d 03 
Power: -nan W 

Sent: 01 04 00 12 00 02 ffffffd1 ffffffce 
Received: 7f ffffffdf ffffffdb ffffffff fffffffb 5d 0c 
Active Apparent Power: -nan VA 

Sent: 01 04 00 18 00 02 fffffff1 ffffffcc 
Received: 7f ffffffdf ffffffcf ffffffff fffffffb 1d 06 
Reactive Apparent Power: -nan VAr 

Sent: 01 04 00 1e 00 02 11 ffffffcd 
Received: 7f ffffffdf ffffffc3 ffffffff fffffffb ffffffdd 65 
Power Factor: -nan 

Sent: 01 04 00 46 00 02 ffffff90 1e 
Received: 7f ffffffdf 73 ffffffff fffffffb ffffffdf 38 
Frequency: -nan Hz 

Sent: 01 04 00 48 00 02 fffffff1 ffffffdd 
Received: 7f ffffffdf 6f ffffffff fffffffb 1d 11 
Import Active Energy: -nan KWh 

Sent: 01 04 00 4a 00 02 50 1d 
Received: 7f ffffffdf 6b ffffffff fffffffb 5f ffffffc5 00 
Export Active Energy: -nan KWh 

Sent: 01 04 01 56 00 02 ffffff90 27 
Received: 7f 5f 53 ffffffff fffffffb ffffffdf 6c 
Total Active Energy: -nan KWh 

$
can you help me?

thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest