Connecting Devices Using Modbus Protocol
This article describes how to configure communication with devices using Modbus protocol. Simple and robust, Modbus has since become a de facto standard communication protocol, and it is now a commonly available means of connecting industrial electronic devices (see Wikipedia). Rapid SCADA supports Modbus RTU, ASCII and TCP modes.
Note. The updated version of the article is available here.
The general sequence of configuring:
- Create an object, a communication line and devices in the configuration database using SCADA-Administrator.
- Configure communication between SCADA-Communicator and the devices.
- Create input channels in the configuration database according to the tags of the devices. Create output channels according to the commands.
- Create views to display data in SCADA-Web. Specify the views using SCADA-Web Configurator.
The following is a step by step guide to setup a new Modbus device. To ensure that the process of adding the device completely coincides with the text of the article, you have to install Rapid SCADA with the default configuration.
Preliminary Database Configuration
Editing the configuration database is performed using SCADA-Administrator.
Run SCADA-Administrator. Open Objects table and add a new line for the object 2 “Test object” (see Figure 1). Then open Communication lines table and add the line 4 “Test line” (see Figure 2). After that open Devices table and add the device 41 “Test device” (see Figure 3).
Fill the following fields for the device (see Figure 3):
|Address:||Modbus address of your device, for example, 1|
|Call number:||IP address, if the device is connected via Ethernet|
|Communication line:||"Test line", which was recently created|
Figure 1. Adding an object
Figure 2. Adding a communication line
Figure 3. Adding a device
When editing the configuration database is completed, it is necessary to pass it to SCADA-Server by clicking the button . To apply the changes, restart SCADA-Server service with the button .
Configuring Communication with Devices
Run SCADA-Communicator (exact its graphical shell). At this time SCADA-Server service must be running.
Right-click on Communication Lines tree node and choose Import communication lines and devices item of the context menu (see Figure 4). In the window that appears, tick the created line and device, and then click the Import button (see Figure 5). Communication line and device appear in SCADA-Communicator.
Figure 4. Communication lines context menu
Figure 5. Choosing devices for import
Click Line 4 “Test line” tree node to open Communication Line Parameters page, set up a communication channel, such as a serial port. Tick Commands enabled checkbox if sending commands to the device required (see Figure 6).
Figure 6. Communication line properties
The following table contains typical serial port parameters depending on the protocol type.
|8 data bits,
1 stop bit
|7 data bits,
1 stop bit
|8 data bits,
2 stop bits
|7 data bits,
2 stop bits
In RTU and ASCII modes a baud rate of all the devices of a communication line has to be the same. Specify this baud rate in the serial port properties. Using different Modbus types within a one line is not allowed.
Go to Request Sequence page and select “Test device” row in the table (see Figure 7). If device polling time and period are not specified, the devices are polled cyclically. Commands are sent immediately after a poll is completed.
Figure 7. Device request sequence
Click the button to open device properties form (see Figure 8). In the form choose the type of Modbus protocol, which have to be specified in the device manual.
Figure 8. Device properties
Press the button to select an existing device template, or click to create a new template. When the create button or the edit button is clicked, Device Template Editor is shown (see Figure 9). This article uses the existing template KpModbus_Adam6015.xml.
Figure 9. Device template editor
Device template reflects the structure of Modbus packages. Requested data are combined into groups of elements. Each group has its name, data table, start address and element count. Each element is a tag of a device. Rapid SCADA identifies a tag by its signal number. A command is described by its name, data table and address. A command number identifies the command within Rapid SCADA.
Names of groups, elements and commands are arbitrary. What data tables and element addresses are available usually described in device manual. As written in Modbus standard, element addresses start with 1, but device manufacturers often numerate the first element as 0. In this case just add 1 to an address before entering it to device template.
To save SCADA-Communicator settings click the button . Now it is recommended to start SCADA-Communicator service with the button and check communication with the device.
Click Device 41 “Test device” tree node to check the device state and the availability of data (see Figure 10). The data is not available immediately after start, retrieved values are shown when the first polling complete.
In case of losing communication with the device, use communication line log to analyze the problem cause. To open the log, click Communication Line Stats tree node and go to Communication Line Log page. Data packages can be decoded by Online Modbus Parser.
Figure 10. Device data
Final Database Configuration
After communication with the device is established, create input channels and output channels in the configuration database. To do this, open SCADA-Administrator again.
Automatic channel creation service helps to save a time. Click Service → Create Channels in the main menu of the application.
On the form shown in Figure 11 choose “Test line” in the drop down list, then tick “Test device” row and choose “Test object” in the cell of Object column. Firstly press Calculate channel numbers button, then press Create.
The channels are created automatically based on the device template that has been created and assigned to the device in the previous section of this article. To view created channels, click Input channels → Test device tree node and Output channels → Test device node. It is recommended to manually fill in Quantity and Unit fields of the input channels and Command values field of the output channels. However, in the case of the first experiment it is unnecessary.
Useful to understand that the input channels are bound to the device tags using Signal field. The output channels are bound to device commands in accordance with Command number field.
After editing the configuration database is complete, press the button to pass the changes to SCADA-Server, and then restart SCADA-Server and SCADA-Communicator with and buttons.
Open Device Data page in SCADA-Communicator and make sure that the input channels are bound to the device tags – Channel column must contain numbers of the created input channels (see Figure 12).
As a result of described actions data should being collected from the device and stored in the archive. It remains to customize user interface for an operator.
Figure 12. Device data bound to channels
Customizing User Interface for Operator
Consider creating a table view for SCADA-Web. To do this SCADA-Table Editor application is needed. If displaying data in a graphical view is required, use SCADA-Scheme Editor instead of the table editor.
Open SCADA-Table Editor and fill in the table view as shown in Figure 13. Add a channel in the table (from the left side of the window to the right) by clicking the button , double-clicking channel row or by pressing Enter.
Save created table view in the file TestTable.tbl in the folder C:\SCADA\Interface\Test
To display table view in SCADA-Web, open SCADA-Web Configurator, go to Views page and specify the created view.
Views are grouped into sets. As an example, a new “Test set” was added (see Figure 14). Please note that a directory must be specified for a set of views. In this case, the directory is Test\
Add the view as shown in Figure 15, and save the settings.
Figure 14. Adding a view set
Figure 15. Adding a view
Now start your browser and enter the address http://localhost/scada/
On the login form use admin / 12345 and Test set (see Figure 16).
Figure 16. Login form
If the configuration carried out correctly, after logging in, you will see a table with the data obtained from the device, similar to Figure 17.
Modbus Tags Conversion
Received element values may need a conversion. A device template allows choosing a number of bytes used by an element and order of bytes. These settings define an initial conversion. An additional conversion, if needed, is performed by SCADA-Server based on formulas of input channels in the configuration database.
The simplest conversion is a proportional which is described by the following formula:
X * (B – A) / 2N + A, where A and B are the bounds of the element values range, N – number of bits in value, X – received value.
Another common conversion is two’s complement. See Wikipedia for the details. Formulas could be defined inline in input channel rows of the configuration database or separately by using Formulas table. Using of formulas is presented in Rapid SCADA Administrator’s Guide.