Jump to content

Modbus 485 with IEEE 754 floating points number


vken

Recommended Posts

Hello ,

I 've got an Energy meter (yes again!) which returns 16bit registers at the maximum range 65535. some times that is also negative...  that is format  IEEE 754

It's the first time see this format and I can't find a way to read automatically the correct values.

I read some articles and some other post with multi array but this is not multiarray it's just a number which need some calculations on it if I got it right? (find the "mantissa" and so on).

Or I got it totally wrong ...

any Ideas ?

thank you

 

p.s I 'm using a US5-B10-TR22

Link to comment
Share on other sites

Hi Joe,

yes I did, I also checked two other post from the forum.

1. 

2. 

 

but as far I can understand is that the reading should be in two arrays or two registers.  how ever I was not able to read two arrays from unistream. 

according to the energy meter's  manual they are 4 bytes (2 registers) per parameter. 

http://support.innon.com/PowerMeters/SDM630-MOD-MID/Manual/SDM630-Modbus_Protocol.pdf

if I connect with an adapter to the energy meter with modscan64 I can read the values also in float format

When is saying 4 bytes (2 registers) they are 2 registers in row?

for example 30001 and 30002 ?

 

p.s  I'm beginner in Modbus but I think not that bad 

Link to comment
Share on other sites

Just to know...are you trying to read info starting from address 1 or address 0?

because the column called "Modbus Protocol Start Address Hex" show that you have to start from address 0x0000...then 0x0000 and 0x0001 will contain the info about the "Phase 1 line to neutral volts"; address 0x0002 and 0x0003 will contain ythe info of  "Phase 2 line to neutral volts"...and so on

Link to comment
Share on other sites

The way that Sargani explained in post number 2 should work.

6 hours ago, vken said:

but as far I can understand is that the reading should be in two arrays or two registers.  how ever I was not able to read two arrays from unistream. 

 

6 hours ago, vken said:

When is saying 4 bytes (2 registers) they are 2 registers in row?

Yes you can (and should in this case) read several registers in a row. If in "Modbus Master" setup you define tag as an array of 16 bit integers, let's say of length 10, PLC will read 10 consecutive registers from Modbus Slave.

Can you post part of the program with code for making 32 bit float from 16 bit ints, with setup for Modbus so we can help you find the problem?

Link to comment
Share on other sites

Hi,

thank you both!

So that's why I need a Gurus to guide me  :)

ORSO you are right that I miss that point and Isakovic stretch me to the reading of several registers in row.

I made some test, here is the code but still don't have the correct result.

correct me if I'm wrong:

0x12345678

Reg 0 - Hi is 34 | Reg 0 - Lo is 12 | Reg 1- Hi is 78 | Reg 1 - Lo is 56

the format in order to be read as float should be 34,12,78,56 ?

what I tried to do in the attached is that but is not working

they are 2 lines here,

one with Sargani's explanation that looks pretty nice and give in "Buffer 1" the above format, but I'm still missing something to have the right result  

the second is a deferent approach but also half and far way. 

thank you for you patience.

Untitled.jpg

L1 Voltage.jpg

 

US5_B10_TR22 - Copy.ulpr

Link to comment
Share on other sites

  • MVP 2023

I thought this sounded familiar.  Your Modbus words probably need to be swapped to have the correct value.   Notice I said WORDS, not bytes.  Keep in mind that Buffer data types are 8 bits (bytes), while Modbus returns registers in 16 bit words.

This is VERY IMPORTANT - have you been able to actually read a value from your meter?  What is that value?  Do you know what the corresponding floating point value is? 

 

9 hours ago, vken said:

I made some test, here is the code but still don't have the correct result.

correct me if I'm wrong:

0x12345678

Reg 0 - Hi is 34 | Reg 0 - Lo is 12 | Reg 1- Hi is 78 | Reg 1 - Lo is 56

the format in order to be read as float should be 34,12,78,56 ?

what I tried to do in the attached is that but is not working

There is no right answer to this.  I know you're trying very hard to get a firm definition, but the byte and word order on a floating point number varies from manufacturer to manufacturer.  When Modbus was created floating point numbers weren't something that was thrown around so its format was not defined.  This has led to much confusion in today's world where young device programmers always put data in floating point format but do not try to adhere to a standard.

You MUST have an actual word from your device and it's corresponding floating point value to decode.  

 

 

 

Here's a post of mine from June 6, 2019.  You mentioned this thread in one of your earlier posts but I don't think you followed this through.   

 

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.

 

 

 

Link to comment
Share on other sites

Hi Joe,
thank you for your msg.

I'll connect it again to the  modscan64 to identify the words... from there I can swap in real time from HEX to Bit and  so on....

... regarding the example you attached is something that i tried but I 'll tried it harder! 

Link to comment
Share on other sites

I want to give a feedback and some more info because I found it difficulty ....

well it looks that it works! the "words" reading is easier and clear approach. 

I905476645_L1V3.thumb.jpg.d04919391e9c368a706279294103159a.jpg1421473724_HzV3.thumb.jpg.c3dd4de932f77c9e55883172164e7666.jpg don't have clear reading about Voltage of Phase 1, some times is around 230xxxxx... but most of the time is like 59139010000000000000000000.000000 but it's a stable reading. 

for Hz the reading is clear

for both of them  I can't find a way to move the decimal point. for example to have 49.84 Hz instead of  49837.520000 any idea how to manage the length of the values

US5_B10_TR22 - v3.ulpr

Link to comment
Share on other sites

hi vken,

 

from your picture I saw that the function 1 (maybe is the main function) has no BIT trigger to do the conversion from 2xint16 and REAL...also to perform the byte swapping...so this funciton will called a many times (one for each PLC cycle)...please try to insert a BIT command to perform these actions.

regards

Link to comment
Share on other sites

  • MVP 2023
On 10/6/2020 at 1:44 PM, vken said:

I905476645_L1V3.thumb.jpg.d04919391e9c368a706279294103159a.jpg1421473724_HzV3.thumb.jpg.c3dd4de932f77c9e55883172164e7666.jpg

I am, frankly, shocked that this works. Each of those rungs should be broken up into at least two, if not three rungs. I can't believe that "Buffer 1" or "Buffer 2" has completed both parts of the Copy Tag operation before the Copy Buffer occurs.

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