MODBUS to MSSQL: Writing several MODBUS registers to separate columns. Tutorial.
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)
6. Configure the data export plug-in (fig. 2-3)
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.
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.
Click "OK" to save the changes.
9. Check the status bar to make sure the data is being successfully processed (fig. 5).