Modbus - reads of multiple registers

M

Thread Starter

MR

A company I recently started working for has a device which uses serial Modbus.

To make reading data more efficient, an engineer has implemented some reads from certain addresses which he calls "block reads". Essentially they will read a certain number of bytes (typically 16 or 12) from a certain SINGLE Modbus address.

The only way to read all this data is to read the entire 16 bytes from the one address. Reading from address +1 will give a _completely different_ set of 16 bytes.

Somehow, the engineer thinks that this is conforming to the standard, because the requested data is returned within a Modbus 'packet' and there is nothing saying that each word of the returned data needs to map to a specific register. (i.e. as long as the returned data is in the PDU correctly, it's completely up to the user to determine how to interpret it).

I on the other hand read 6.3 of the Modbus spec and can't see how having a register size that is not 16 bits could ever be standards conformant.

Unfortunately the other engineer is the company owner, so my argument is being trumped.

Can anyone lend an opinion to either side of the argument?

Names and company omitted to protect the innocent. (Or not so innocent.) :)

Cheers,
M
 
Hello,

I wrote this big long thing about how this was a bad idea.

And then I read your message again 2X and I do not understand. There is a mixing of viewpoints.

You talk about reading. Is your device a master or a slave?

But it really does not make a difference. The size of a read request from a master to a slave is always the same size. The size of the response from the slave to the master varies based on the read request.

What he is proposing is not compliant with the MODBUS spec. While the specification does not define the contents of the registers, a logical linear address space is defined.

If I start at address 1 and read 4 registers. Then I start at address 2 and read 3 register, the data returned should be from the same location as the last three register in the first read.

To do otherwise would not be using the MODBUS protocol, IMHO.

Get a 3rd party master or slave and test it.

And I do not see “make reading data more efficient” is achieved.

Good luck,

Mark
http://www.peakhmi.com
 
Assuming you're referring to function code 3 or 4, you're correct. Returning anything other than 16-bit words in multiples specified by the 'Quantity of Registers' field makes the Modbus packet non-compliant.

Once you go outside of the spec, you create Modbus variants like Enron Modbus and others that use a single address to represent different data types and are not compatible with standard Modbus masters.

-Mark
http://automatedsolutions.com
 
J

Jerry Miille

This is really pretty common "extension" of the Modbus protocol. While not really strictly by the spec, it is a valid Modbus response message as long as the byte count is correct. It's really no different that returning 32 bits for a Long Integer or a Floating Point number. I am aware of this type of operation in several Flow Computers and some other devices. We offer it as well in our protocol converter products. Not all Modbus Masters will accept this so it does need to be an option that can be turned off.

Jerry Miille
 
M

Michael Griffin

In reply to Mark: I think he would have to do more than just get a third party master and test it. He would have to get every version of every third party master in existence and test all of them. There is no reason why a master couldn't reject the reply because the received length was longer than expected for the request sent. At best they could say that their slave works with certain specific masters. It isn't actually Modbus though.

I have written a Modbus/TCP master and I had to check the source code before I could say that I *think* the one I wrote would be compatible with what they are doing. I certainly won't make any effort or do any testing to ensure that it stays that way though.

I also agree that it is not obvious what is being made "more efficient". Bandwidth isn't conserved. CPU processing time isn't being conserved (it is probably less efficient). Address space isn't being conserved because the master will have to reserve the total address space anyway.

If anything, I would say that this scheme is *less* efficient, since it prevents the master from reading a large block of data in a single transaction.

I suspect that whatever it is his company is trying to accomplish, they are doing it the hard way. The Modbus standard itself allows a great deal of flexibility and there is a probably a much simpler way of achieving the same goal while still complying with the standard.
 
F

Fred Loveless

It really depends on what you are connecting to for a device. If you look at the Modbus spec you will see that a register is 16bits. However if you are looking at a device using the Enron Modbus spec (usually a flow meter) you can have registers specified as 32 bit lengths. In the Enron model if you request those 32bit registers the request is for one register and the response is 4 bytes. If you communications driver that is expecting regular Modbus then it will probably evaluate the response and invalid data length, i.e. expected 2 bytes got 4 bytes.

Fred Loveless
Senior Application Engineer
Kepware Technologies
http://www.kepware.com
 
Top