You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
I'm reading values from a sensor that uses RS485 and sends inverse float values with function code 4 (addresses 0, 2 and 4) and it was imposible for me to read those values using the read_input_registers function (which uses function code 4).
I had to add another function for converting values to float instead of short (quite hardcoded for my case, not so much into modbus):
def_to_float(self, byte_array, signed=True):
# response_quantity = int(len(byte_array) / 2)# this always returned 2# fmt = '>' + ('f' * response_quantity)# so fmt ended up like '>ff' and caused a buffer issue, so I hardcoded it to ' >f'# also, no idea about signed floats, just left the signed var to be consistentreturnstruct.unpack('>f', byte_array)
and a new function copy&pasted from read_input_registers, but using the _to_float` function defined above:
Hi,
I'm reading values from a sensor that uses RS485 and sends inverse float values with function code 4 (addresses 0, 2 and 4) and it was imposible for me to read those values using the
read_input_registers
function (which uses function code 4).I had to add another function for converting values to float instead of short (quite hardcoded for my case, not so much into modbus):
and a new function copy&pasted from
read_input_registers, but using the
_to_float` function defined above:Any cleaner/correct/good way to implement this?
The text was updated successfully, but these errors were encountered: