Python Utilities

The Core Python utilities provides a set of Python tools to assist the development of Python libraries and program in the context of ICS.

The following modules/tools are provided:

  • “ifw-core/pyutils/utils”: Various general purpose Python utilities.

  • “ifw-core/pyutils/opcua/srvlib”: Provides an SCXML driven, OPC UA server tool kit based on the Free OPC UA SDK.

  • “ifw-core/pyutils/opcua/clientLib”: Provides an OPC UA client class, based on the Free OPC UA SDK.

  • “ifw-core/pyutils/opcua/utils”: Various OPC UA helper tools.

  • “ifw-core/pyutils/opcua_client”: Provides the executable for the OPC UA client (“coreOpcuaClient”).

  • “ifw-core/pyutils/opcua_gen_profile”: Tool to generate the OPC UA XML Profile from a easier-to-handle YAML-based format.

Module: “ifw-core/pyutils/utils”

Python import statement: “import core_utils.utils”.

Module: “ifw-core/pyutils/opcua/srvlib”

Python import statement: “import core_opcua.srvlib”.

For examples of usage of the OPC UA/SCXML server toolkit, the Device Simulators can be used.

Module: “ifw-core/pyutils/opcua/clientlib”

Python import statement: “import core_opcua.clientlib”.

Module: “ifw-core/pyutils/opcua/utils”

Python import statement: “import core_opcua.utils”.

Module: “ifw-core/pyutils/opcua_client”

Tool for communicating with OPC UA servers from the command line.

For now it is mostly for usage with servers based on the Core OPC UA/SCXML Server Toolkit.

Usage:

$ coreOpcuaClient --help
usage: coreOpcuaClient [-h] [--action {READ,WRITE,METHOD,SUBSCRIBE,SCAN}] --address ADDRESS [--nodes NODES] [--method METHOD] [--ns NS] [--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--log-file LOG_FILE] [--verbose] [--tolerant] [--examples]

IFW Core OPC UA Client Tool

optional arguments:
  -h, --help            show this help message and exit
  --action {READ,WRITE,METHOD,SUBSCRIBE,SCAN}
                        define tool action
  --address ADDRESS     server address; example opc.tcp://134.171.12.101:4840
  --nodes NODES         Node ID(s) to address; example: MAIN.OPTI1.stat.lrPosActual
  --method METHOD       Method call, including parameters; example MAIN.Shutter1#RPC_State
  --ns NS               Namespace, e.g. 4
  --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
                        Set the logging level
  --log-file LOG_FILE   log output file
  --verbose             output log on stdout
  --tolerant            be tolerant to certain errors
  --examples            Print out examples of usage

Example:

  1. Start a Device Simulator:

fcfDevsimShutter --port 7878  --cfg config/fcf/devsim/shutter/shutter1.cfg.yaml --log-level INFO
2019-05-24 15:14:03.907:INFO:SmOpcUaSrv:MainThread:serverBase:500:execute: Setting up OPC UA server ...
Listening on 127.0.0.1:7878
...
2019-05-24 15:14:05.244:INFO:SmOpcUaSrv:MainThread:serverBase:544:execute: Serving ...
  1. Communicate with the Device Simulator:

$ coreOpcuaClient --address opc.tcp://127.0.0.1:7878 --action METHOD --method "MAIN.Shutter1#RPC_State" --ns 4
['NotOperational:NotOperational_NotReady']
$ coreOpcuaClient --address opc.tcp://127.0.0.1:7878 --action METHOD --method "MAIN.Shutter1#RPC_Init" --ns 4
[0]
$ coreOpcuaClient --address opc.tcp://127.0.0.1:7878 --action METHOD --method "MAIN.Shutter1#RPC_State" --ns 4
['NotOperational:NotOperational_Ready_Closed']

Module: “ifw-core/pyutils/opcua_gen_profile”

The tool is used to generate the OPC UA XML profile for the Core OPC UA/SCXML Server Toolkit. The OPC UA XML profile defines the namespace of the server.

The names are defined in a simple YAML-based file and the XML document generated via the tool.

An example of a YAML namespace definition to be used as input for the tool can be found here: Motor Device Simulator

Note

For the Core OPC UA/SCXML Server toolkit, it is recommended to use the feature to generate the OPC/UA XML namespace on-the-fly, from the simpler YAML format, unless for performance reasons it is better to use a pre-generated XML profile.

Module: “ifw-core/pyutils/log_collector”

Tool for collecting logs coming from PLCs and ingesting them in the CII logging environment using the CII logging API.

Usage:

$ logCollector --help
usage: logCollector [-h] [-i INTERFACE] [-p PORT] [-l LOG]

Cii log collector

optional arguments:
  -h, --help            show this help message and exit
  -i INTERFACE, --interface INTERFACE
                      server network interface
  -p PORT, --port PORT  server listening port
  -l LOG, --log LOG     logging configuration

Module: “ifw-core/pyutils/network”

Module to create udp mudpi server or clients. Python import statement: “import ifw.core.network”.

Module: “ifw-core/pyutils/mudpi”

Module to build or read mudpi packets. Python import statement: “import ifw.core.mudpi”.