bg

MODBUS to MSSQL: Write several MODBUS registers to separate columns

Download a Free Trial Version. It allows you to try all features! Plugins can be downloaded separately here

If you need to not only log the changes of the MODBUS item values in the MSSQL database but also analyze and process them after that, it will be more convenient to create a table where there will be a separate column for every item. This method can be applied if there are not many MODBUS values.


CREATE TABLE [dbo].[modbus_data_2](
   [REC_ID] [int] IDENTITY(1,1) NOT NULL,
   [TIMESTAMP] [datetime] NULL,
   [ITEM1] [nchar](30) NULL,
   [ITEM2] [nchar](30) NULL
) ON [PRIMARY]

ITEM1 - will store the value of item 1;

ITEM2 - will store the value of item 2;

TIMESTAMP - will contain the date and time when the value was modified.

1. Create a new user in the database or give permissions to write and read data from the created table to an existing user.

2. Configure the queue with MODBUS requests, as described in "MODBUS polling."

3. Memorize names of response items (e.g., VALUE1, VALUE2). If you want, you may create the table above with identical column names.

4. Verify that the logger sends MODBUS requests and receives responses.

5. Select the data export plug-in (fig. 1)

Selecting the data export plug-in
Fig. 1 Selecting the data export plug-in

6. Configure the data export plug-in (fig. 2-3)

Configuring the data export plug-in. General.
Fig. 2 Configuring the data export plug-in. General.

To set up a connection, you should create and configure the ODBC data source for connecting to your MSSQL database. Click the "Configure" button to do it. After you create the data source, click "Update" and select the data source from the list.

Configuring the data export plug-in. Connection.
Fig. 3 Configuring the data export plug-in. Connection.

7. Binding (fig. 4) allows you to specify which data to which columns the program should add. You should specify the column name and "bind" it to the item from the program's main window (the parser item). You should also specify the data type of the column.

Configuring the data export plug-in. Binding.
Fig. 4 Configuring the data export plug-in. Binding.

Click "OK" to save the changes.

9. Check the status bar to make sure the data is being successfully processed (fig. 5).

Message in log
Fig. 5 A message about data being successfully written

Data in an MS SQL 2008
Fig. 5 Data in an MS SQL 2008 database

Related articles: MODBUS to MSSQL: Write several MODBUS registers to separate columns

MODBUS RTU, MODBUS ASCII, MODBUS/TCP

IEC 62056-21