Jump to content

Read Single-precision arrays with Modbus TCP/IP

Recommended Posts

I use a PLC (US5-B10-TR22) and communicate with a smart meter throw MODBUS TCP/IP.  The registers of this smart meter store values as 'single'-precision floating-point variables. Throw the UniLogic is not possible read 'single' values and I did not find a way to do this conversion.. How can I solve this issue?


Link to post
Share on other sites

Thank you Joe T. for your answer!

I tried with Real type tag, but the returning number is not correct!

This is happened because the Real type tag is (64-bit double precision floating point), in contrast this smart meter registers values are single (32-bit single precision floating point)...


Link to post
Share on other sites
14 hours ago, Charalambos said:

This is happened because the Real type tag is (64-bit double precision floating point),

Actually, it's not.  According to the Unitronics Help under Contents->Tags->Data Types



So that leaves me to believe you may have a byte order problem, which is not unusual in reading 32 bit data from a Modbus device.

I'm looking into if it's possible to read the data into a UINT32, swap bytes, and then convert to Real.  Otherwise someone at Support may be able to help.

Joe T.

  • Like 1
Link to post
Share on other sites

Hi Charalambos,

Please publish here content of 2 sequential MIs you read from meter in HEX and tell us what number it should show.

*Read it from meter display, if possible.

Having this information it is simple to negotiate if pairs of Bytes should be swapped or Bytes should be arranged in some order.




  • Like 1
Link to post
Share on other sites
On 6/5/2019 at 4:35 AM, AlexUT said:

use  "Vector->Use Offset->Copy Memory" to copy ML/DW to MF.

Those would be the Visilogic function blocks.

As you've already done, read the data from the device into a UINT32 tag.  For testing I made one called "Read Data" that I could simulate, and a tag called "Conv Value" to hold the swapped bytes.  The data will land in a REAL called "Converted".

In UniStreamSpeak-

1.  Copy the data you read from the device to the working tag and Swap the bytes using "Logic->Swap Single Tag Bytes" with Swap Type.ABCD_CDAB.

2.  Copy the swapped data to a 4 byte BUFFER array type so you can manipulate the memory directly.  Mine is "Conv Buffer[4]".

3.  Use "Buffer Tools->Copy Tag to Buffer" to get the "Conv Value" data into the buffer tag and "Copy Buffer to Tag" to get it from the buffer to the REAL "Converted".


There you go.  Sorry it doesn't have all the digits you're looking for.

If you need to convert several values write a UDFB to move the data into this logic with a pointer.

Joe T.


  • Like 2
Link to post
Share on other sites
On 6/5/2019 at 12:35 PM, AlexUT said:

Thank you both for your help!

What I did:I read as INT32 the value, then I converted it to 32 bits-array , swapped the first 16-bits with the last 16-bits of this array and final converted the 32 bits-array to a REAL. The value in the REAL now is the correct value! Below is the Function block diagram I used for this.    


Best Regards,









Link to post
Share on other sites
  • 4 months later...

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.

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...