8-bit data types in Modbus registers

J

Thread Starter

Jay

Hello people,

I am trying to find out how to map 8-bit data types onto Modbus registers.

Since registers are always 16 bits, does it even make sense to provide data types of 8 bits length? In case of 8 bits, I saw many devices where one of the two bytes of a register is set to zero.
Does it make sense from the PLCs point of view? Does this save memory?
Are 8-bit data types obsolete for Modbus? Are PLCs able to handle two 8-bit values within a single register?

I would like to learn about your opinions and experiences.

Thanks in advance.
Jay
 
> Since registers are always 16 bits, does it even make sense to provide data types of 8 bits length?

Well, since the Modbus function codes 03/04 are always going to read a register of 16 bits, you need to 'pack' your 8 bit word to fit a 16 bit register.

> I saw many devices where one of the two bytes of a register is set to zero.

Sounds like 8 bit data 'packed' with zeros in the remaining bits of a 16 bit register value.

> Does it make sense from the PLCs point of view?
If the PLC or its comm port 'speaks' Modbus, then it will be capable of dealing with 16 bit values from 3xxxx input or 4xxxx holding registers.

> Does this save memory?
Modbus registers use/take the memory they need. If you pack two 8 bit words into one slave register, the master has to decode it. In my book, that's a pain. In your book, you'll spend time explaining it to people.

Are 8-bit data types obsolete for Modbus?
Modbus only defines its register size(s), Modbus does not define the data format itself. Modbus doesn't care what kind of data you ship back and forth, it's just a transmit/receive/error protocol.

So the slave and the master have to be able to interpret each others' data formats at whatever that higher OSI level is.

Lots of different kinds of data, like date stamps use all sorts of different formats that require 'decoding' on the receiving end to make any sense of the value. All sorts of data has to be massaged to come up with a true engineering value. That's just the way it works with undefined data formats. That means you can pack two words into one register - your custom format - but doing so will limit who can use that data effectively and hence your customer base.

Are PLCs able to handle two 8-bit values within a single register?
Depends on the functionality of the PLC and skill of the programmer in moving, formatting and interpreting the data.

If you're looking for advice, I'd say keep each data value in its own Modbus register. Many master/clients lack the tool set to separate and strip out multiple words from a single register, but can handle an 8 bit integer or XOR a bit packed word to decode it.
 
L

Lynn August Linse

A bit of historical trivia... Modbus never had 8-bit data types. The original PLC were made back in the days of wire-wrap and iron core memory, so the first few gens of PLC literally had 1-bit and 16-bit memories. The idea that memory is in 'bytes' had not yet become a de facto standard.
 
Top