I\'m IoT newbie and I have a project with Schneider Power Meter.
I read voltage raw data from registers using pymodbus
but I don\'t know how to convert it to the co
Still, I'm waiting for your code, but with my guess, you will need like the following stuff:
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.client.sync import ModbusTcpClient
def validator(instance):
if not instance.isError():
'''.isError() implemented in pymodbus 1.4.0 and above.'''
decoder = BinaryPayloadDecoder.fromRegisters(
instance.registers,
byteorder=Endian.Big, wordorder=Endian.Little
)
return float(decoder.decode_32bit_float())
else:
# Error handling.
print("There aren't the registers, Try again.")
return None
client = ModbusTcpClient('X.X.X.X', port=502)
connection = client.connect()
if connection:
request = client.read_holding_registers(3927, count=2, unit=1)
data = validator(request)
print(data)
client.close()
else:
print('Connection lost, Try again')
[NOTE]:
Your data either is float32 or float32_inverse.
Thus, with the float32 you will have:
wordorder=Endian.Big
And with the float32_inverse you will have:
wordorder=Endian.Little