Jump to content

Problem with Unilogic soft : Read a Modbus Float and convert to Real


Stzyc

Recommended Posts

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

Link to comment
Share on other sites

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

image.thumb.png.d681829f1bc90c2a649f07a9ac595390.png

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...