Jump to content
Sign in to follow this  
Charalambos

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?

Charalambos 

Share this post


Link to post
Share on other sites

I don't know definitively on the UniStream, but the Modbus command to read float registers is the same as the one to read holding registers (3).  Have you tried reading the value from the meter to a Real type tag?

Joe T.

  • Like 1

Share this post


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

Charalambos 

Share this post


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

image.png.aa836017f7286be2383037c6b4dfdaef.png

 

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

Share this post


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.

AABB CCDD -> CCDD AABB

B.R.

 

  • Like 1

Share this post


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

image.thumb.png.c41cba62b2efc15da549231d516ffac7.png

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 1

Share this post


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.    

image.png.18e915ba4d7da79834a0a1d46a88cd6e.png

Best Regards,

Charalambos

 

 

Quote

 

 

 

 

Share this post


Link to post
Share on other sites

I like your way, too!  It demonstrates that you can think in terms of bits, which are the foundation of all the other data types.

There's a cat being skinned multiple ways somewhere....

😁

Joe T.

  • Like 1

Share this post


Link to post
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.

Sign in to follow this  

×
×
  • Create New...