I read and decode float_32 value using pymodbus.
Before, I decode that with the following code as simple:
from pymodbus.client.sync import ModbusTcpClient
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
cli = ModbusTcpClient('an-IP')
cli.connect()
req = cli.read_holding_registers(<hex-address>, count=4)
dec = BinaryPayloadDecoder.fromRegisters(req.registers, endian=Endian.Little)
print(dec.decode_32bit_float())
But recently I occurred with this error:
TypeError: fromRegisters() got an unexpected keyword argument 'endian'
[UPDATE]
I think the newer version of pymodbus
have been modified (endian
argument have been deprecated):
A reference: Looks like the arguments changed but not the documentation
Then I changed this line as following:
dec = BinaryPayloadDecoder.fromRegisters(
req.registers,
byteorder=Endian.Big,
wordorder=Endian.Little)
Problem:
Now I want to check the pymodbus version to know which version of decode must be used.