MODBUS to MSSQL: Writing several MODBUS registers to separate columns
Download and install our software
Advanced Serial Data Logger you can download here. 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] [decimal](10,1) NULL,
[ITEM2] [float] 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 the 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 respone 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)
Fig. 1 Selecting the data export plug-in
6. Configure the data export plug-in (fig. 2-3)
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.
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" the item to it from the main window of the program (the parser item). You should also specify the data type of the column.
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).
Fig. 5 A message about data being successfully written
Fig. 5 Data in an MS SQL 2008 database
MODBUS RTU, MODBUS ASCII, MODBUS/TCP