Modbus Data Types

I remember when I had this roommate. Let’s call him Mark. Great guy. One of the best in the world. A Quaker as a matter of fact. Only Quaker I’ve ever known. But there were one or two things that just bugged the hell out of me. It’s that way in every relationship.

Here’s an interesting question. What if you had a double? A complete copy of yourself and you lived with yourself as a roommate. Would you enjoy living with you? Or would you get irritated with yourself?

Well, now I have had a relationship with Modbus for a number of years. I love Modbus. Not ashamed to admit it. I’ve known Modbus for going on 20 years now and have profited greatly from the relationship. But just like all relationships there are some rough spots. Some things I just don’t like.

The real big hassle with Modbus is the data types. It is very unpleasant accessing data that is typed using 16-bit unsigned registers. If you’re not familiar with what I’m talking about, here’s some examples. If  you have a 32-bit speed value, that has to be in two Modbus registers. The order of the bytes in Modbus is clear, it’s MSB (Most Significant Byte) first. But what’s the order for the words. Is it the low word first or the high word first? I don’t know it could be either.

Now with 64-bit values, it gets even worse. 4 times worse. And that’s just analog.

What about discretes? It’s one thing if they are using coils to represent discretes but a lot of developers like to pack 16 discretes into a single Modbus Integer. So which is bit zero? The first bit or the last? Probably the first.

It’s a mess. It’s hurt my relationship with Modbus but we’re still together and going to be together for the foreseeable future. I just don’t want to end it over these little aggravations. I’ve just decided to live with it.

I’ve decided to add typing to all our Modbus device converter gateways. So instead of just saying that you have 4 registers at address 40100 (40 thousand – another irritant), you would say I have two 32 bit integers or two floats or one 64-bit float or four integers or whatever.

That actually buys us a lot. Using our new auto mapping feature we can then automatically map those 32-bit analog values right to BACnet in our Modbus Master BacNET gateway. It will also work well in our ControlLogix to Modbus gateway and the gateway we have to move Modbus Slaves to an EtherNet/IP Scanner.

So I’ve found a way to deal with some of the irritations and I’m still in the relationship. Really don’t see a way to get out. It still works even though it gets tiresome and stale. Even though I do have relationships with Profinet IO, DeviceNet, EtherNet/IP and others, Modbus will always be first with me.