Retrieving Float Value from holding registers

103 views Asked by At

I am trying to retrieve the float value saved in the holding register, we are using 2 registers to save the value address of the register 41000, 41001

I have a RTU which is getting values from few sensors. When I connect with Modscan32 and query the registers I get output as the data type is selected as integer.

enter image description here

I get first value using code below:

read_reg = self.client.read_holding_registers(1000, 2)
print(read_reg)

But the actual data is in float and when I select the float data type I get below output in modscan32

enter image description here

These values are taking 2 address location for 1 value 30.6250 value is stored in address 41000 and 41001.

But when I try to retrieve this value from python code using below code, I am getting the wrong value.

read_reg = self.client.read_holding_registers(1000, 2)
decoder = BinaryPayloadDecoder.fromRegisters(read_reg.registers, byteorder=Endian.BIG, wordorder=Endian.LITTLE)
value = decoder.decode_32bit_float()
print(str(value))

Can anyone tell me where I am going wrong?

1

There are 1 answers

0
Prashant soni On

Taking the register value as 1000

decoder = BinaryPayloadDecoder.fromRegisters(
  read_reg.registers,
  byteorder = Endian.BIG,
  wordorder=Endian.BIG
)

Resolved the issue and now getting the value. Thanks, everyone.