Stzyc Posted January 10, 2022 Report Share Posted January 10, 2022 Hello, I have a little big problem with with Unilogic soft. I am reading a sensor modbus Float register but I can't have the good value writting in a real. Is there someone who could help me please. I have tried some conversion but nothing well. Have a nice day. Stef Quote Link to comment Share on other sites More sharing options...
pascal Posted January 10, 2022 Report Share Posted January 10, 2022 Stef, had the same problem, but I managed to "convert" the float to real : the problem is that when you read a float trough modbus, the bytes are swapped. you read a float and receive 4 bytes -> this is the way I convert the floating value into a real value I read the float as a buffer of 4 bytes , then I swap the bytes first byte you receive is in fact the 3th byte of the real second is the 4th byte - third byte is the 1st byte and last byte you receive is the 2nd byte a good idea is to check it with this link : https://www.h-schmidt.net/FloatConverter/IEEE754.html Quote Link to comment Share on other sites More sharing options...
Stzyc Posted January 10, 2022 Author Report Share Posted January 10, 2022 Thank you for the feedback, Finally I found a solution that seems to work for me. The register of my sensor is based on a FLOAT type variable (32 bits) coded in AB-CD or CD-AB. I chose CD-AB. - I read this one with a 4 x 8 bit array variable. - Then I transfer the results with: 'Copy array part' by making my bit shifts: - bit 0 to 2 - bit 1 to 3 - bit 2 to 0 - bit 3 to 1 - then I copy the new variable of type ABCD in a temporary 'buffer' then in a variable 'Real'. It works for me. Quote Link to comment Share on other sites More sharing options...
Stzyc Posted January 10, 2022 Author Report Share Posted January 10, 2022 😀 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.