Problem when writing floats and 32bit integers

1,042 views
Skip to first unread message

Nick Stamou

unread,
Nov 4, 2017, 12:53:06 PM11/4/17
to modbus-tk
Hello all

Last year i had to create a HMI program to read and write data from/to a DELTA PLC with modbus TCP and publish the values to a mosquitto broker that runs on Raspberry.
Other projects occupied my time so it was left behind. But now i must finish it. I want to show two problems i have. The might actually be my problems, since i'm not very good at python, but in .NET-))
 Anyway, so far I managed to read and write most of the data types (coil/int/float). However, i have the following two problems:

1) When i write a float, the result is seen on the attached picture. On that picture you see that i write the number 2.12, but the result is 2.109375. This happens with all the floats.
   The value 2.109375 is what my program have read from the PLC and published to the mosquitto (on the right of the picture it is a testing mqtt client program).

2) On the PLC there is a 32bit number that contain alarm bits. Bits start from 0 to 28. All these bits represent some conditions. If a bit is ON, we have an alarm.
   I can read values up to 65535 (16bit only). I have played with the data_format but most of the times i get the error "struct.error: unpack requires a bytes object of length 4".
   Or i get "struct.error: 'H' format requires 0 <= number <= 65535". How can i write 32bit integers?

Any ideas?  I'm using version 0.5.7.

float_value_issue.png

Nick Stamou

unread,
Nov 6, 2017, 4:42:51 AM11/6/17
to modbus-tk
On Github there is an example about how to handle floats, which i did not pay too much attention.  I had to use Function 16 to write on multiple registers. Now floats are being written correctly. It was my bad :-))
Regarding the 32bit registers, i discussed with the tech guy who programmed the Delta PLC and he said that he can break this 32bit register in two 16bit registers. So this is solved too.

However i would like to know if there is a possibility that modbus_tk can read 32bit registers.

Thanks!
Reply all
Reply to author
Forward
0 new messages