Help Wanted in converting hexadecimal numbers from Modbus to Floating point numbers

1,208 views
Skip to first unread message

JvW

unread,
Aug 11, 2014, 1:47:38 PM8/11/14
to pymo...@googlegroups.com
Sorry for my bad english 

Help Wanted in converting hexadecimal numbers from Modbus to Floating point numbers.

I have a Eastron sdm630 kwh meter and I would like tricks the information that I can use on a website. 
In particular, the volt, watt and total watts are important. 

With python modbus rtu I get the input registers from the Eastron. 
Maybe it goes all wrong here, and I start wrong, it is not entirely clear to me also. 
I can not get it together to convert them into readable floating points. 

How do I get it done, for example, the output 17250, 43125, convert to volts. 
17250, 43125, according to the display +/- 226.4 volts. 

The Eastron uses 32 bit registers composed of 2 x 16-bit registers. 
That means my knowledge that the input voltage consists of register 0 and 1. 

In the Annex, the modbus explained. (link) 

Can someone please help me further with the right python script rules? 

I already searched more than 20 hours on the Internet and tested several examples, nothing really helps me further. 

Thanks! 

The following test script I get the data on the screen: 

#! / usr / bin / env python 

from pymodbus.client.sync import ModbusSerialClient axis ModbusClient 
import logging 

logging.basicConfig () 
log = logging.getLogger () 
# log.setLevel (logging.DEBUG) 

client = ModbusClient (method = 'rtu', port = '/ dev / ttyUSB0', baudrate = 9600, timeout = 1) 
client.connect () 

rr = client.read_input_registers (0, count = 10) #for debugging 
print rr.registers 
client.close () 


output: 
#python ./test.py 
[17250, 43125, 17250, 40548, 17250, 61852, 0, 0, 0, 0]
Eastron Modbus Registers.pdf

Galen Collins

unread,
Aug 11, 2014, 1:57:11 PM8/11/14
to pymo...@googlegroups.com

Here you go: http://pymodbus.readthedocs.org/en/latest/examples/modbus-payload.html

--
You received this message because you are subscribed to the Google Groups "pymodbus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymodbus+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JvW

unread,
Aug 12, 2014, 2:17:48 PM8/12/14
to pymo...@googlegroups.com
Thx, 

I go and test it, the script use TCP I use serial but I can change that part.

let you now if it work's.

Gr,

Jeroen

JvW

unread,
Aug 13, 2014, 8:13:14 AM8/13/14
to pymo...@googlegroups.com
Bashwork,

I fix it thanx to your imput.

I now get the correct output 228.710876465 (volt) (that's the same as on the display of my KW/H meter.

I have to change the script from Endian to Big, and make some other changes to get my results.

Thx for your help!

Here is my script:

#!/usr/bin/env python
#---------------------------------------------------------------------------# 
# loading pymodbus modules
#---------------------------------------------------------------------------# 
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.payload import BinaryPayloadBuilder
from pymodbus.client.sync import ModbusSerialClient as ModbusClient

#---------------------------------------------------------------------------# 
# client logging
#---------------------------------------------------------------------------# 
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.INFO)

#---------------------------------------------------------------------------# 
# Connect info KW/H meter
#---------------------------------------------------------------------------# 
client = ModbusClient(method='rtu', port='/dev/ttyUSB0', baudrate=9600, timeout=1)
client.connect()

#---------------------------------------------------------------------------# 
#---------------------------------------------------------------------------# 
builder = BinaryPayloadBuilder(endian=Endian.Big)
builder.add_string('abcdefgh')
builder.add_32bit_float(22.34)
builder.add_16bit_uint(0x1234)
builder.add_8bit_int(0x12)
builder.add_bits([0,1,0,1,1,0,1,0])
payload = builder.build()
address = 0x01
result  = client.write_registers(address, payload, skip_encode=True)

#---------------------------------------------------------------------------# 
# Read data and convert to float and creating output files
#---------------------------------------------------------------------------# 

result  = client.read_input_registers(0x00, 2)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, endian=Endian.Big)
volt = open("volt.txt", "w")
print >>volt, decoder.decode_32bit_float(),

result  = client.read_input_registers(0x34, 2)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, endian=Endian.Big)
watt = open("watt.txt", "w")
print >>watt, decoder.decode_32bit_float(),

#---------------------------------------------------------------------------# 
# close the client
#---------------------------------------------------------------------------# 
client.close()


On Monday, August 11, 2014 7:57:11 PM UTC+2, Bashwork wrote:

Galen Collins

unread,
Aug 13, 2014, 11:56:48 AM8/13/14
to pymo...@googlegroups.com

Awesome, good work!

nagarju...@connectm.com

unread,
Feb 12, 2018, 2:29:33 AM2/12/18
to pymodbus

Awesome, good work!


i got error can you please solve this
error is:    builder = BinaryPayloadBuilder(endian=Endian.Big)
                 TypeError: __init__() got an unexpected keyword argument 'endian' 

Galen Collins

unread,
Feb 27, 2018, 1:31:29 PM2/27/18
to pymo...@googlegroups.com
Looks like the arguments changed but not the documentation:

```
    def __init__(self, payload=None, byteorder=Endian.Little,
                 wordorder=Endian.Big):
```

--
You received this message because you are subscribed to the Google Groups "pymodbus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymodbus+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages