How to connect a machine with the OPC DA Connector?

OPC DA Client for innius

The OPC DA client is intended as a tool to connect machines running with an OPC DA Server to the innius platform and send sensor events to it. In this manual we will first list the required programs for this to function and then we will proceed to the configuration of the OPC DA Client.

Requirements

Since OPC DA requires Windows a Windows OS is assumed throughout this section. 

General installation

  • Install Python 2.7.x (can be obtained here)
  • Install and verify Open OPC (see below)
  • Download the inniusOPCDAConnector folder from the attachments, unzip it and move it to where you would like to keep it.

Install Open OPC

OpenOPC is a requirement to connect to an actual OPC DA server, or to a simulation that uses the OPC DA protocol

  • Install Python for Windows Extensions (pywin32, obtained here or from the attachments to this document.)
  • Install OpenOPC (OPC Python client, see attachments)

  • Open up a command prompt by searching for "cmd" in the program search bar.
  • Run "opc -q" from the command line to see if the installation works. This command lists all opc servers it can find, which you can use to configure which server the innius DA connector should use.
  • Run "cd <<insert the path to your innius OPC DA connector here>>/dist. This will change the current working folder.
  • Run "pip install OPC_DA_Client-0.0.16-py2-none-any.whl". Note that the exact number after OPC_DA_Client may change if we update the connector. If that is the case simply change the 0.0.16 in the command to the number that is in the file you have.

Now we will create the configuration files necessary for the connector to publish data to innius.

Configuration Files

The innius OPC DA Connector requires two configuration files. One with parameters that relate to the connection with innius, named "posterconfig.json", and another, named "opcconfig.json" that tells the connector where to get the sensors you want to export to innius. Examples of both can be found within the innius folder, which we will now use to explain the contents of the two files in some more detail. 

Posterconfig

Example:

{
    "key"   : "Bearer <<insert your machine token here>>",
    "url"   : "https://live.innius.com",
    "stream": "<<insert stream here>>",
    "id"    : "<<insert machine-trn here>>",
    "region": "eu-west-1"
}

Here all the <<insert something here>> should be replaced by the corresponding parameter that is shown when connecting a machine to innius.

Opcconfig

This configuration determines which sensors the connector reads the values of and as such it also requires details on what OPC server to connect to. The OPC servers you have access to can be listed from the command line (search for "cmd" in the program search window) by using the command "opc -q" if you have OpenOPC installed. Since it is a requirement for the innius OPC DA connector to run you should have it and see one or more servers at this point. If you do not yet have it installed please refer to the "Install Open OPC" section of this manual. 

The config itself has the following format (this is the example file included in the innius folder):

{
"version": "v2",
"logfilelocation": "./logs",
"opcclient": {
"servername": "Opc.Da.Server",
"sensors": [{
"machinetrn": "<<insert machine-trn here>>",
"sensorid": "<<sensor name>>",
"origin": "<<sensor tag in opc da>>"
}]
}
}

You will have to change "Opc.Da.Server" for the name of the server you want to connect to. The sensor list can most easily be obtained by exporting the sensors from the innius web application. To do this go to the sensor overview of your machine on the web application, click "Import/Export" and then click "Export OPC DA Configuration" (see Figure 1). This will create a file similar to the example file except most of it (except for the servername) will be filled in for you. What's important here is the origin of each sensor, which is the sensor tag in the opc da server. The export uses the innius field "physicalid" for this. Note that namespaces show up between brackets when accessing a tag, so if you have a sensor called TestSensor under the innius namespace then the tag (and thus the physicalid) will be [innius]TestSensor. Outside of this there is the logfilelocation, which determines where the logs are written. By default this is ."/logs", meaning the logs directory relative to the place the program is run from but if you want to log somewhere else you can change that here.

Figure 1: The Export OPC DA Configuration button

Usage Instructions

The inniusOPCDAConnector folder also contains a file "runner.py" which has the following contents:

import sys
from opcdaclient import opcdaclient

if __name__ =='__main__':
opcdaclient.run(opcConfigFile="opcconfig.json", sensorPosterConfigFile="posterconfig.json", actorType="ReaderSEVTPosterFOPWriter")

If you keep the names of the "opcconfig.json" and the "posterconfig.json" the same there is no need to touch this file. If you do want to change them, for example if you have a config for testing and one for production, change the corresponding field to the new name.

Then run the program as follows:

  • Open a command prompt (Search for "cmd" in the windows program search)
  • Move to the innius directory (cd <<path to innius directory>>)
  • run "python -u runner.py". If you get a message that python is an unknown command find python.exe on your system and replace python by the full path to python.exe (for example C:\ProgramFiles\Python27\python.exe)

Installing as Windows Task

The following steps are needed in order to schedule a particular script, responsible for running the opcdaclient. It is assumed that the script is fully set up, tested and configured manually before it is scheduled as a task.

  • On the Windows task scheduler, Create a (Basic) Task.
  • For the Trigger set When the computer starts.
  • For the Action set Start a program
  • As the program use the cmd command cmd.
  • As the argument use the regular way the script would be called, along with its path, and an exit after execution. For example: (python -u runner.py & exit Make sure the task is executed from the directory where the script and its config files are. For example C:\inniusOPCDAConnector

  • Once the (basic) task is created set up a number of useful properties for it:
  • In the conditions tab of the task properties:
    • Make sure the task is run even if the system is on battery power
    • Start only if a network connection is available
  • In the settings tab of the properties:
    • Make sure the task can be started on demand (helpful with manual interventions).
    • Make sure the task is restarted if it fails every 1 minute, with a high number of restarts (i.e.: 50).
    • Make sure the task is NOT stopped if it runs longer than 3 days.
    • Make sure that if the task is running does not end requested, it is forced to stop.
    • Make sure that if the task is already running no new instance is started.
Have more questions? Submit a request

Comments