rtuman
@thiagoralves, @alexburcea,  I'm having problem reading %MD200-202 from a RPi4 with a Sequent Systems Home Automation HAT attached running PSM. I can read all the Digital Inputs and Outputs, Analog Inputs and Outputs except the %MDxxx registers through Modbus/TCP
I tried reading from floating point registers 2248+(%MD200 at 2048 Offset), and 2048+ to no avail. All the registers were showing zero.  I also tried different floating point formats to no avail.
However, in the OpenPLC Monitoring screen (attached), the %MD200-202 were showing the correct values. What could be the cause and how can I fix it?
Thank you.
Reply 0 0
thiagoralves
Monitoring uses Modbus to query the data that feeds that table. So if it is showing on monitoring you can definitely read it with Modbus calls as well. You probably are using the wrong query or wrong address. What software are you using to read? What does your request looks like?
Reply 0 0
rtuman
@thiagoralves : Is reading from floating point registers starting from 2248 correct?  What MB polling function call should I be seeing?

Thank you!
Reply 0 0
thiagoralves
There is no such thing as floating point registers in Modbus (see  https://store.chipkin.com/articles/how-real-floating-point-and-32-bit-data-is-encoded-in-modbus-rtu-messages ). All modbus registers are 16-bit wide. To read a 32-bit value (like a floating point number) you must concatenate two registers together. That's what OpenPLC does with %MD registers. On the Modbus perspective, they are still 16 bit registers, but data is stored in two registers at a time for each %MD locations. Therefore, since each %MD location takes 2 modbus "spaces" or registers, you will have to multiply the MD location by 2 to get the modbus register you want, as you can see from this code snippet from OpenPLC:
            #Reading Double Memory
            mb_address = debug_data.location.split('%MD')[1]
            result = mb_client.read_holding_registers((int(mb_address)*2) + 2048, 2)

In other words:
%MD0 = Modbus 2048 + 2049
%MD1 = Modbus 2050 + 2051
...
%MD200 = Modbus 2448 + 2449
..and so on
Reply 0 0
rtuman
@thiagoralves
Thank you so much for the explanation.

I made the mistake of using MB starting address 2248 previously.  Now everything works!
Reply 0 0
Riccardo_98
There is no such thing as floating point registers in Modbus (see  https://store.chipkin.com/articles/how-real-floating-point-and-32-bit-data-is-encoded-in-modbus-rtu-messages ). All modbus registers are 16-bit wide. To read a 32-bit value (like a floating point number) you must concatenate two registers together. That's what OpenPLC does with %MD registers. On the Modbus perspective, they are still 16 bit registers, but data is stored in two registers at a time for each %MD locations. Therefore, since each %MD location takes 2 modbus "spaces" or registers, you will have to multiply the MD location by 2 to get the modbus register you want, as you can see from this code snippet from OpenPLC:
            #Reading Double Memory
            mb_address = debug_data.location.split('%MD')[1]
            result = mb_client.read_holding_registers((int(mb_address)*2) + 2048, 2)

In other words:
%MD0 = Modbus 2048 + 2049
%MD1 = Modbus 2050 + 2051
...
%MD200 = Modbus 2448 + 2449
..and so on


Sorry how can I do this thing on ScadaBR?
I'm passing some float numbers and the first one, as you said, issplitted between the registers 2048 and 2049.
How can I merge them together? Thank you
Reply 0 0
thiagoralves
OpenPLC merges them for you. Just declare a REAL variable located at %MD0
Reply 0 0
Riccardo_98
Yes on OpenPLC I’ve declared as REAL and on the Runtime they are correct. But on ScadaBR?
Reply 0 0
thiagoralves
Declare your data point at address 2248 of type float
Reply 0 0
Riccardo_98
This is my declaration (I’ve changed to %MD0 so 2048)
Reply 0 0
thiagoralves
8 byte float is a LREAL. It should be 4 byte float for REAL
Reply 0 0
Riccardo_98
Ahhh thank you now it works 😅👍
Reply 0 0
Reply