Multi-register reads and data consistency

D

Thread Starter

David Collier

I'm worried about if, when and how one needs to be cautious about possible inconsistencies of data when read on a modbus.

I know that some objects one might read across a modbus are in fact bigger than a single modbus 16-bit regsiter. Starting with 32-bit fpt, but there may be many more.

Our driver will consolidate together all registers in the same device which lie on contiguous addresses and read them with a single transaction.

I was intitally worried about whether the transfer of the read-out values to a buffer from which they will be sent to the modbus master could ever catch a 32-bit value in an inconsistent state. For instance could one get the top half of an old fpt value, and the bottom half of a new one.

Some discussion has conviced me that most PLC devices will only move data from the PLC application memory to the transmit buffer inbetween PLC steps, so the data values stored by the PLC should always be consistent.

However, I did find (can't locate it now) a PLC device which said that if you asked for more than 32 reghsiters, it would transfer 32 to the transmit buffer between 2 steps, the next 32 between the next 2 steps, and so on until it had built a complete reply.

It sesesms to me that could cause inconsistency if a floating-point value spans locations 32 and 33, for instance.

Does anyone have any light to shed on this whole area?

David
 
C

Curt Wuollet

In that case you certainly could. There are many such cases with the typical PLC mode of operation. Often there is some internal buffering (often poorly documented or secret) to deal with this, at least for their "native" protocols. But the general class solution would be to copy (move, memcopy, etc.) things into a buffer atomically, that is in a single scan before the send and hold the value until the send is complete so you can send the buffer and avoid this. Often, there are status flags that you can use to accomplish this, but some may require you get clever and count scans or wait for a reply, etc. You are right to worry about this until proven wrong. You can imagine how interesting it would be to track this down happening once a month or so :^)

Regards
cww
 
Top