Trouble reading holding Modbus registers with float32 data

Viewed 56
#my code goes like this for a holding register 3026 - 3027

client = ModbusClient(method ='rtu', port ='COM4', timeout=1, stopbits = 1, bytes = 8, parity = 'E', baudrate = 9600)
a = client.connect()
print(a)

while True:
    read_value = client.read_holding_registers(address = 43026,count = 2,unit = 1)
    real_decoder = BinaryPayloadDecoder.fromRegisters(read_value.registers,byteorder = Endian.Little, wordorder=Endian.Big)
    value = real_decoder.decode_32bit_float()
    print(value)
    time.sleep(100)

The result I got is this: 1.1755122874426309e-38

but my ModScan32 shows a 156.9796 in float(MSRF) mode.

can anyone here gives me a solution on how this floating point data with 32bits may be converted into a value same of that ModScan32 result...

Hope someone might notice and help me.. :( Im sorry for being newbie..

1 Answers

You probably have a problem with endianness. The float(MSRF) format is Little Endian (MSRF stands for most significant register first) but in your code you set wordorder=Endian.Big.

Try changing wordorder to Endian.Little

Related