Process or store OPC data by an event from the OPC server
Problem scenario
I have this item: Kemro.opc.4.IF1.1.92.Mars1.SVs.system.sv_ShotCounter[14]="1" in OPC Data Logger. I want to take data and write it to MySQL only when this value rises to 1. The logger should reset this value to 0 on the OPC server. This action will confirm that the data was received.
Requirements:
- Advanced OPC Data Logger Enterprise or a trial version.
- Script Execute plugin.
It is assumed that:
1. You've created a configuration using the "Green Plus" button in the main window and added an OPC group in the OPC logger and can receive any data from a selected OPC server.
2. You've configured a data export to MySQL.
Solution:
1. Enable highlighted options in the OPC group settings.

Fig.1. OPC group settings
2. Download and install the "Script Execute" plugin.
3. Enable it (fig. 2).

Fig.2. Script Execute plugin
4. Select the plugin in the list and click the "Setup" button below.
5. In the script editor window select "PascalScript" from the "Script type" list
6. Copy and paste the following code. Modify it if necessary. The row sName1:string = 'Kemro.opc.4.IF1.1.92.Mars1.SVs.system.sv_ShotCounter'; contains the name of the controlled OPC tag. The row SendString(sName+'=0'); sends data to the OPC server, where the string '=0' represents the new value. The logger internally will decode this string and send the corresponding value to the OPC server.
7. Click the "Check" button and verify that the script was compiled successfully.
8. Click the "OK" button and save all changes.
The PascalScript code
var v:double; sName:string = 'Kemro.opc.4.IF1.1.92.Mars1.SVs.system.sv_ShotCounter'; begin // checks a variable in a data packet if IsVariableDefined(sName) then begin v := GetVariable(sName); // the script will discard data packets by the following condition if v <> 1 then DiscardDataPacket() else begin SendString(sName+'=0'); end; end else // discard data also when the counter didn't read yet DiscardDataPacket(); end.
Related articles: Process or store OPC data by an event from the OPC server
- Inserting OPC data to MS Access database through ODBC (features: adding groups and items, inserting to an ODBC database)
- Adding a timestamp in the CSV file (features: OPC groups)
- How to log OPC data to a SQL database.
- OPC to MSSQL: Writing a lot of OPC tags to MS SQL 2008 database
- OPC to MSSQL: Writing several OPC tags to separate columns
- OPC to MySQL: Writing OPC tags to MySQL 5 database
- OPC to a database: Writing OPC tags to a database
- OPC to Excel: Writing OPC data to Excel
- Filtering data by a tag value and write data to a database only when the value will change
- Filtering data out if an OPC tag value is not equal to a specified value
- Processing or storing OPC data by an event from the OPC server
- Aggregating data from multiple servers to one OPC server
Related topics: Advanced OPC Data Logger
hereOPC Logger RS232 pinout and signals Cables and signals Data monitor cables