Advanced OPC Data Logger

Trust In Confidence!

For Windows 2000 - Windows 11 (2022) (incl. Server, x86 and x64). Latest version: 3.10.0 build 306. March 6, 2024.


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:

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.

OPC group settings
Fig.1. OPC group settings

2. Download and install the "Script Execute" plugin.

3. Enable it (fig. 2).

Script Execute plugin
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:

OPC and DCOM Configuration on Windows 2008 and Windows 7

OPC and DCOM Configuration on Windows Server 2012 and Windows 8