Common Tools & Definitions - Python Utilities

The CTD 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/ctd/py/packages/ctdUtils”: Provides various general purpose utilities.
  • “ifw/ctd/py/packages/ctdOpcua/srvLib”: Provides an SCXML driven, OPC UA server tool kit based on the Free OPC UA SDK.
  • “ifw/ctd/py/packages/ctdOpcua/clientLib”: Provides an OPC UA client class, based on the Free OPC UA SDK.
  • “ifw/ctd/py/programs/ctdOpcua/opcuaClient”: Provides the executable for the OPC UA client, based on “ifw/ctd/py/packages/ctdOpcua”.
  • “ifw/ctd/py/programs/opcuaGenProfile”: Tool to generate the OPC UA XML Profile from a YAML file.

Module: “ifw/ctd/py/packages/ctdUtils”

Python import statement: “import ctdUtils.utils”.

“ctdUtils.utils” doxygen documentation.

Module: “ifw/ctd/py/packages/ctdOpcua/srvLib”

Python import statement: “import ctdOpcua.srvLib.serverBase”.

“ctdOpcua.srvLib.serverBase” doxygen documentation.

Module: “ifw/ctd/py/programs/ctdOpcua/clientLib”

The tool can be used to communicate with OPC UA servers from the command line.

Note: The tool is

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

Usage:

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

IFW CTD 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:
$ ctdOpcuaClient --address opc.tcp://127.0.0.1:7878 --action METHOD --method "MAIN.Shutter1#RPC_State" --ns 4
['NotOperational:NotOperational_NotReady']
$ ctdOpcuaClient --address opc.tcp://127.0.0.1:7878 --action METHOD --method "MAIN.Shutter1#RPC_Init" --ns 4
[0]
$ ctdOpcuaClient --address opc.tcp://127.0.0.1:7878 --action METHOD --method "MAIN.Shutter1#RPC_State" --ns 4
['NotOperational:NotOperational_Ready_Closed']

Note: The command line tool is quite slow now and will be improved. Using the “ifw/ctd/py/programs/ctdOpcua/clientLib” in Python code, is faster.

Module: “ifw/ctd/py/programs/opcuaGenProfile”

The tool is used to generate the OPC UA XML profile for the CTD 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 informatio about the tool is contained in the FCF manual/opcuaGenProfile.

“opcuaGenProfile” doxygen documentation.