I'm currently coding modbus rtu in python using package pymodbus. In this case, I will read the data from the TDS sensor using func code 4 / Read Input Registers (refer to the Aquas SMR-08 datasheet). The data was successfully obtained and I convert it to hex , but the data must be converted again to the correct value. I try convert the hex value with scadacore (online hex converter) and I see the correct data on Float Big Endian (ABCD)
The Hex Value is 41FB:
conversion result is 31.375 (this is Temperature value):
So, how algorithm or what code pymodbus to convert like scadacore (online hexa conversion) ?
can anyone help ? Thanks In Advance, and sorry for my bad english hihihi
this is my code
import time
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.constants import Defaults
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
Defaults.RetryOnEmpty = True
Defaults.Timeout = 5
Defaults.Retries = 5
client = ModbusClient(method='rtu', port='/dev/ttyUSB0', timeout=2, stopbits=1, bytesize=8,
parity='N', baudrate=19200)
client.connect()
while True:
tds1 = client.read_input_registers(address=0, count=2, unit=1)
bacatds1 = tds1.registers[0]
bacatds2 = tds1.registers[1]
tds1hex = hex(bacatds1)
tds2hex = hex(bacatds2)
print(tds1hex)
print(tds2hex)
decoder1 = BinaryPayloadDecoder.fromRegisters(tds1.registers, Endian.Little)
hasil1 = decoder1.decode_32bit_float()
print(hasil1)
print('==================================')
time.sleep(1)
# ----------------------------------------------------------------
tds2 = client.read_input_registers(address=1, count=2, unit=1)
bacatds3 = tds2.registers[0]
bacatds4 = tds2.registers[1]
tds3hex = hex(bacatds3)
tds4hex = hex(bacatds4)
print(tds3hex)
print(tds4hex)
decoder2 = BinaryPayloadDecoder.fromRegisters(tds2.registers, Endian.Big)
hasil2 = decoder2.decode_32bit_float()
print(hasil2)
print('===================================')
time.sleep(1)