Modbus setup with communicator

How do I get data from a modbus device using the communicator?

I have added the device to RSlogix but get and IO size error on the IO device. I want to clear this error and then get data from my Modbus RTU device.

You will want to configure the serial side of the device before you can get data on the plc since the IO size is set based on the serial transactions. I’ll go through an example of polling a register for data and then an example for writing to one. You should be able to mimic this example with some modification for your application.

Configure subnetwork
The communicator will need to be in Master Mode for Modbus communication. This is set under the communicator section in ACM (Anybus configuration Manager). (image1) Master Mode sets the device for query response transactions. This means it sends a configured request out and then looks for a corresponding response back. Both the sent message and received messages are preconfigured on the communicator with both constant data or variable data. Constant data is a static byte and Variable data is written during operation either from the fieldbus or subnetwork. For Modbus we have the messages preformatted so we will just need to set the values for them. I will get more in to that later.


Next, you need to set the serial settings this is done in the subnetwork section.(image2) In this example I am using the following:
bitrate 9600
Data bits 8
Parity none
Physical standard RS232
Stop bits 1

Node and Transactions
In this example I am adding one slave device at address 1 and then a read holding register 2 and a write to input register 5.

The node is going to be the slave device that we are talking to. This is automatically use in the Modbus transactions, so each slave device will need to be added as a separate node.
Right click on the subnet and select add node. To generate a node then set the Slave ID to the right. Once a node is added we will need to configure the transactions to the node.

Transactions consist of what is sent on the Tx line and what we are looking for in the response on the Rx line of the serial bus. The built in Modbus transactions are called commands and can be added to the node by right clicking on it and selecting add command. This will list out all the commands available. In Image2 you can see them listed along with the node slave id in the background. Now we will add a holding register; double clicking on it in the list will add it.

Read Holding Register
Expanding the query and response show you what each part is comprised of. Here is a list of what you will find with a brief description.

Slave Address Copied from node
Function Auto filling from command
Starting Address Starting address you are reading from the slave
Quantity Of Registers Number of registers being read from the slave
Checksum Auto generated
Slave address Copied from node
Function Auto filled based on command
Byte count Number of bytes the slave will be responding with
Register Value Register Address where the response is stored on communicator.
This will also correspond to the address you will read on the fieldbus
Checksum Auto generated
In the Query we are setting the starting address to 2 and the quantity of registers to 1. For the response we are setting the byte count to 2 bytes which is equal to 1 16 bit register in Modbus. Since we only have one read request so far we will set the data location to 0. If we were to add a second read command we would offset the next by 2 bytes taking into account the previous request. Memory addresses 0 to 0x1FF is used for input data. This is data coming in from the serial side and then read by the fieldbus. (image3)

Write Single Register
The Write single register command is similar to Read Holding register but you are configuring the command to output to the subnetwork. This is a value you write to the communicator from the fieldbus. In our query we are setting the Register Address to 5. In Register value we will set Data Length to 2 and Data location to 200. You have address 0x200 to 0x3FF for output data. Typically an echo of the request will be sent back so we need to configure the response to match the incoming data. In the response we set the Register address to 5 matching the query. Since we are just expecting the respond to be the value you just wrote I will write the data to the general section. This can be used for trouble shooting purposes later on if needed. The data length is set to 2 and location to 0x400.

1 Like

12 posts were split to a new topic: HMS-en2se-r not communicating with slaves