bg

MODBUS RTU polling: Configuring master station

Task:

MODBUS polling for two MODBUS devices and log the data received to the database.

Prerequisites:

It is assumed that:

  1. You have already worked with MODBUS devices.
  2. You know the register addresses where the values that you need are stored.
  3. Furthermore, you know the connection settings for the devices (baud rate, number of data bits, and so on).
Download a Free Trial Version. It allows you to try all features! Plugins can be downloaded separately here

Configuring the COM port

Configure the connection (Figure 1). MODBUS devices are usually connected to the computer via the Ethernet interface, and they work as a MODBUS slave. Our logger should work as a TCP client and initiate a connection with a slave device.

TCP connection settings
Figure 1: TCP connection settings

Configuring the polling via MODBUS

When polling a MODBUS device and capturing data, the computer is the "master," and the device is the "slave." It means that the application running on the computer sends MODBUS requests, and the device replies to them. To configure the polling, use the MODBUS RTU module in ASDL (Figure 2). On the "Query Parse Filter" tab, select that module and click the "Setup" button to the right of the module name in the list.

Selecting the data query and parser module
Figure 2: Selecting the data query and parser module

When a window opens (Figure 3), click "Action → Add new request" to add one or more requests.

Adding requests to the queue
Figure 3: Adding requests to the queue

You can grasp the meaning of request options from their names. For more information on request options, see the help file for the MODBUS module (Start → Programs → Data Logger → Help).

Please note that you must define response items for the device and format of these items. Otherwise, the application will be unable to disassemble MODBUS packets. For example, in the example shown in Figure 3, two registers located at the address 8214 are read. Each register contains two bytes (16 bits) of data. In the example, four bytes will be read, starting from the address 8214. The meaning of these bytes depends on the MODBUS device’s firmware version and register map.

Case 1 (Figure 3). Both registers have the same data type. Each value consists of two bytes (2 * 8 = 16 bits).

  1. In the "Name" field, enter the base name for each value: VALUE.
  2. In the "Count" field, enter the number of values: 2.
  3. Check the "Append counter to name" checkbox: The application will automatically add the index number (1 or 2) to the base name. As a result, the values will be named VALUE1 and VALUE2.
  4. In the "Data type" field, select the data type depending on the number of data bits.
  5. If the value is unsigned, check the "Unsigned" checkbox.

Case 2 (Figure 4). Each register holds 16 bits, but of a different data type (signed and unsigned).

  1. Add two response items: Select "Response items" in the tree and click "Actions → Add response item."
  2. In the "Name" field, enter the base name for each value: VALUE1 or VALUE2.
  3. In the "Count" field, enter the number of values: 1.
  4. Uncheck the "Append counter to name" checkbox because full names have been defined via the "Name" field. As a result, the resulting value names will be VALUE1 and VALUE2.
  5. In the "Data type" field, select a data type for each response item.
  6. Check or uncheck the "Unsigned" checkbox for each value.

Response option
Figure 4: Response option

Case 3 (Figure 5). One value is 16 bits long and occupies one register; the other value is 32 bits long and occupies two registers.

  1. Add two response items: Select "Response items" in the tree and click "Actions → Add response item."
  2. In the "Name" field, enter the base name for each value: VALUE1 or VALUE2.
  3. In the "Count" field, enter the number of values: 1.
  4. Uncheck the "Append counter to name" checkbox because full names have been defined via the "Name" field. As a result, the resulting value names will be VALUE1 and VALUE2.
  5. In the "Data type" field, select a data type for each response item.
  6. Check or uncheck the "Unsigned" checkbox for each value.

MODBUS response settings
Figure 5: Response settings

Case 4 (Figure 6). You need to read two registers, but they are not located in the device’s memory one after another: There are other registers (values) between them.
You can read about 100 registers at a time via MODBUS. If the gap between the two registers in the device’s memory is small enough, you can read the whole range of values in one request, and then select the values that you need from the captured array. Otherwise, you’ll have to break your request into two requests for different addresses. Here’s an example of one request. In the device’s memory, the values that we need are located at the addresses 8214 and 8218.

  1. Add a request; in the request properties, specify reading of five registers, starting from 8214.
  2. Add two response items: Select "Response items" in the tree and click "Actions → Add response item."
  3. In the "Name" field, enter the base name for each value: VALUE1 or VALUE2.
  4. In the "Count" field, enter the number of values: 1.
  5. Uncheck the "Append counter to name" checkbox because full names have been defined via the "Name" field. As a result, the resulting value names will be VALUE1 and VALUE2.
  6. In the "Data type" field, select a data type for each response item.
  7. Check or uncheck the "Unsigned" checkbox for each value.
  8. For the second response item, specify the offset in bytes relative to the beginning of the array. In this case, "8" means skipping four 2-byte registers. In the previous examples, the offset was "-1"; the application counted the offset automatically depending on the amount of data in the previous response items.

MODBUS request and response settings
Figure 6: Request and response settings

Case 5 (Figure 7). You need to read the values of analog inputs and outputs according to the following MODBUS register map:

Address Name Description
0003 ain1 Analog Input #1
0004 ain2 Analog Input #2
0005 ain3 Analog Input #3
0006 ain4 Analog Input #4
0007 dot Digital Outputs as 16 bits, 0 if none
0008 aot1 Analog Output #1
0009 aot2 Analog Output #2
0010 aot3 Analog Output #3
0011 aot4 Analog Output #4
  1. Add a request. In the request properties, specify reading of nine registers, starting from 0003.
  2. Add two response items: Select "Response items" in the tree and click "Actions → Add response item."
  3. In the "Name" field, enter the base name for each value: AIN or AOT.
  4. In the "Count" field, enter the number of values: 4.
  5. Check the "Append counter to name" checkbox. As a result, the values will be named AIN1 ... AIN4 and AOT1 ... AOT4.
  6. In the "Data type" field, select a data type for each response item: Decimal 16 bit, signed.
  7. For the second response item, specify the offset in bytes relative to the beginning of the array. In this case, "10" means skipping five 2-byte registers.

Request and response settings
Figure 7: Request and response settings

How to write data to various databases is described in the following parts (see links below).

Related articles: MODBUS RTU polling: Configuring master station

MODBUS RTU, MODBUS ASCII, MODBUS/TCP

BACNET/IP