I’m using this code and try to get the repsonse value from rs485 but the value is alwasy incorrect, can I know how this is encoded so that i can get the correct value from the serial.
from pylibmodbus import ModbusRtu, get_float
ctx = ModbusRtu(device=b"/dev/rs485", baud=9600, data_bit=8, stop_bit=1, parity=b"N")
ctx.connect()
ctx.set_response_timeout(100)
ctx.set_slave(1)
def get_float_abcd(data):
return C.modbus_get_float_abcd(data)
ctx = ModbusRtu(device=b"/dev/rs485", baud=9600, data_bit=8, stop_bit=1,parity=b"N")
ctx.connect()
ctx.set_response_timeout(10)
ctx.set_slave(1)
for i in range(1,400):
reg = ctx.read_input_registers(i,2)
value =get_float_abcd(reg)
if value != 0 :
print("Address, AddressValue: ",i,[reg[0],reg[1]],"Value: ",value,sep="\t")
ctx.close()
Currently, part of the problem is solved, by setting the get_float_dcba(), and address 343-2=341, work, But, for start adress1, iI dont’t know how to subtract!
The byte order depends on your devices. It is possible that you need to use a different byte order to interpret the data correctly. So I suggest checking what order works for you.
Keep in mind that RUT/TRB devices use Modbus Register Numbers, while certain third-party devices might use Modbus Register Addresses. The key distinction here is that numbers start from 1, whereas addresses start from 0. So, for instance, if a specific piece of data is stored at Modbus Register Address 101 on the Modbus Slave, you would need to access it from a your RUT956 device by referencing Modbus Register Number 102. So, when using Register Numbers, you would typically add +1 to the Modbus Register Address.