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”.

“core_utils.utils” doxygen documentation.

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

Python import statement: “import core_opcua.srvlib”.

“core_opcua.srvlib” doxygen documentation.

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

Python import statement: “import core_opcua.clientlib”.

“core_opcua.clientlib” doxygen documentation.

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

Python import statement: “import core_opcua.utils”.

“core_opcua.utils” doxygen documentation.

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:

$ coreGenOpcuaProfile --help
usage: coreOpcuaClient [-h] [--action ACTION] --address ADDRESS
                       [--node-ids NODE_IDS] [--method METHOD] [--ns NS]
                       [--log-level LOG_LEVEL] [--log-file LOG_FILE]
                       [--verbose] [--tolerant]

IFW Core OPC UA Client Tool

optional arguments:
  -h, --help            show this help message and exit
  --action ACTION       set tool action (READ, WRITE, METHOD, SUBSCRIBE, SCAN)
  --address ADDRESS     server address
  --node-ids NODE_IDS   Node ID(s) to address
  --method METHOD       Method call, including parameters, e.g.
                        "MAIN.Shutter1#RPC_State"
  --ns NS               Namespace, e.g. 4
  --log-level LOG_LEVEL
                        set log level (CRITICAL, ERROR, WARNING, INFO, DEBUG)
  --log-file LOG_FILE   log output file
  --verbose             output log on stdout
  --tolerant            be tolerant to certain errors

Example:

  1. Start a Device Simulator:

fcfDevsimShutter --port 7878  --cfg fcf/devsim/devsimShutter/shutter1.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 CML document generated via the tool

More information about the tool is contained in the FCF manual/opcuaGenProfile.

“coreGenOpcuaProfile” doxygen documentation.

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.