MODBUS RTU polling: Configuring master station
Task:
MODBUS polling for two MODBUS devices and log the data received to the database.
Prerequisites:
- Data Logger Suite: Logging and Monitoring Professional, Enterprise, or a trial version;
- The MODBUS RTU module for the data logger.
It is assumed that:
- You have already worked with MODBUS devices.
- You know the register addresses where the values that you need are stored.
- Furthermore, you know the connection settings for the devices (baud rate, number of data bits, and so on).
Configuring the COM port
Configure the connection (Figure 1). MODBUS devices are usually connected to the computer via the RS485 interface, with a special converter. If that is the case, check the "RS485 interface mode" checkbox.
Figure 1: COM port 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.
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.
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).
- In the "Name" field, enter the base name for each value: VALUE.
- In the "Count" field, enter the number of values: 2.
- 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.
- In the "Data type" field, select the data type depending on the number of data bits.
- 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).
- Add two response items: Select "Response items" in the tree and click "Actions → Add response item."
- In the "Name" field, enter the base name for each value: VALUE1 or VALUE2.
- In the "Count" field, enter the number of values: 1.
- 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.
- In the "Data type" field, select a data type for each response item.
- Check or uncheck the "Unsigned" checkbox for each value.
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.
- Add two response items: Select "Response items" in the tree and click "Actions → Add response item."
- In the "Name" field, enter the base name for each value: VALUE1 or VALUE2.
- In the "Count" field, enter the number of values: 1.
- 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.
- In the "Data type" field, select a data type for each response item.
- Check or uncheck the "Unsigned" checkbox for each value.
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.
- Add a request; in the request properties, specify reading of five registers, starting from 8214.
- Add two response items: Select "Response items" in the tree and click "Actions → Add response item."
- In the "Name" field, enter the base name for each value: VALUE1 or VALUE2.
- In the "Count" field, enter the number of values: 1.
- 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.
- In the "Data type" field, select a data type for each response item.
- Check or uncheck the "Unsigned" checkbox for each value.
- 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.
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 |
- Add a request. In the request properties, specify reading of nine registers, starting from 0003.
- Add two response items: Select "Response items" in the tree and click "Actions → Add response item."
- In the "Name" field, enter the base name for each value: AIN or AOT.
- In the "Count" field, enter the number of values: 4.
- Check the "Append counter to name" checkbox. As a result, the values will be named AIN1 ... AIN4 and AOT1 ... AOT4.
- In the "Data type" field, select a data type for each response item: Decimal 16 bit, signed.
- 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.
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
- MODBUS power meter data logging (easy method)
- Sunspec-compatible MODBUS power meters, inverters (easy method)
- MODBUS RTU/TCP polling: Configuring master station (MODBUS RTU, MODBUS TCP, requests, response items).
- MODBUS poll: How to make sure that the application sends requests and receives responses?
- MODBUS poll: How to view register values, not raw MODBUS packets?
- MODBUS polling: How to make sure that the application correctly interprets the responses received from the device?
- MODBUS polling: How to view MODBUS register values in a more easy-to-grasp form (graphs, indicators, etc.)?
- MODBUS: How to combine the data of two requests?
- MODBUS: What is the right way to poll multiple devices?
- Copy settings from Simply MODBUS RTU Master to our Modbus Data Logger.
- Copy settings from the MODBUS Poll utility.
- Controlling PLC coil registers status using MODBUS TCP (MODBUS data parser, custom scripts, events generating, and handling).
- MODBUS to MSSQL: Write MODBUS registers to separate columns
- MODBUS to MySQL: Write MODBUS values to the MySQL database
- MODBUS to a database: Writing MODBUS RTU/TCP values to a database
- MODBUS to a database: Write data to two different tables.
- MODBUS to a database: Write data to two different databases, making a complete copy.
- Sentron PAC 3200: MODBUS TCP Data Logging
- Write data to a MODBUS device
- SQL to MODBUS: Send data from a SQL database to MODBUS.
- MODBUS TCP ↔ MODBUS RTU real-time conversion.
BACNET/IP
IEC 62056-21
- IEC 62056-21 power meter data logging (Iskra Emco, Satec, Landis+Gyr)