Common issues faced by Modbus driver: Incrementing non-standard addresses

Question:

The standard for Modbus protocol establishes that to every address there is a corresponding 16-bit space. However, there are some devices that address their memory in 8-bit groups. In this case, how can I have access to registers? How can I increment a non-standard address?

 

Solution:

Due to the way addresses are incremented, the Modbus driver won’t allow for the use of I/O blocks in its operations. This helps avoid many of the problems related to the increment of a non-standard address. Therefore, when accessing the properties of the IODriver, change the EnableReadGrouping property value to False. Likewise, use only I/O tags in this driver, not I/O blocks.

Firstly, consider the table below. As you can see, addresses are indexed starting from 40000. In this example, the Modbus 40001 address corresponds to a 16-bit group. To the device, this same memory space is shared by two 8-bit groups, addressed as 40002 and 40003; as a result, you can’t access each of these addresses individually.

Size Address in the device Modbus address
16 bits 8 bits 40000 40000
8 bits 40001
16 bits 8 bits 40002 40001
8 bits 40003
16 bits 8 bits 40004 40002
8 bits 40005

Consequently, all addresses are accessed in 16-bit groups. To read the values at the device’s addresses 40002 and 40003, the driver must access the address 40001, thus retrieving a 16-bit value which can be later broken into two 8-bit parts. Likewise, when writing at the address 40001, the values from 40002 and 40003 will be overwritten in the device. Therefore, if you want to change just one of these addresses, the value to be written must be merged to the value in another address before via a binary operation.

Another simpler yet more limited way to work around this situation is to access the Modbus addresses as if they were all 8-bit values. In this case, the only accessible device addresses are  40000, 40002, 40004, etc., which will correspond to the addresses  40000, 40001, 40002, etc. in the driver.

Related articles:


The articles below all refer to common issues faced by the Modbus driver:

Este artigo foi útil? Was this post helpful?
Yes0
No0

Leave a Reply

Your email address will not be published.Required fields are marked *