Device Simulator

The FCF SDK provides a small Python application to implement Device Simulators on the WS, for short, DevSim. These Device Simulators, emulate the PLC, sufficiently well to be able to carry out the basic operations of the device. This makes it possible to carry out a integration test of the instrument software, without the availability of a ‘physical’ PLC. This is useful, e.g. for autonomous tests, running during the nightly build (Jenkins), and, of course, during development, where it may be more efficient to test/debug against a local process, rather than a PLC; maybe a PLC is not even always available.

The FCF Device Simulators, implements the same state machine as is implemented on the PLC. Moreover the OPC UA interface (namespace), is the same, at least for what concerns the nodes, essential for controlling and monitoring the PLC device from the FCF Device Manager.

The Device Simulators load the SCXML state machine model and the OPC UA namespace profile at start-up, and configures themselves accordingly.

It is possible to implement cumstomized business logic for each Device Simulator, to achieve a simulation, accurate enough to do the development and test of the WS Device Manager.

For each Special Device, implemented for an instrument, an FCF Device Simulator shall be provided, in addition to the WS Device Manager and PLC device code.

It may be useful, to start the implementation of a new device by implementing first the Device Simulator, and then use this during the implementation of the Device Manager, because it is easier to control a local application than an application running on a PLC and some device operations may be executed faster by the Device Simulator compared to executing them on the PLC.

Note

The version of the ELT ICS provides the following Device Simulators:

  • Lamp.
  • Motor.
  • Shutter.

For IFW V1, the base toolkit will be enhanced, and Device Simulators for all types of devices, provided by the FCF, supported.

Device Simulator - Command Line Options

A Device Simulator accepts the following command line options (example):

$ fcfDevsimShutter --help
usage: fcfDevsimShutter [-h] --port PORT --cfg CFG [--use-ext-ip]
                        [--log-level LOG_LEVEL]
                        [--log-file LOG_FILE] [--verbose]

Device Workstation Simulator

optional arguments:
  -h, --help            show this help message and exit
  --port PORT           server port number
  --cfg CFG             configuration
  --use-ext-ip          use the external IP address of deployment host
  --log-level LOG_LEVEL
                        set log level (CRITICAL, ERROR, WARNING, INFO, DEBUG)
  --log-file LOG_FILE   log output file
  --verbose             output log on stdout

Option: “cfg”:

YAML based configuration. Context specific parameters maye be added in this configuration, for the specific Device Simulator implementation.

Option: “use-ext-ip”:

By default, a Device Simulator uses the loop-back IP address (127.0.0.1). This means that is it only possible to reach it from within the local host. To make the Device Simulator available on the network, use this option to make it serve on the external IP address.

Device Simulator - Base Application

A Device Simulator is derived from the base class fcf.devsim.devsimLib.deviceSimulatorBase.

At this point, there is no way to generate the Python source files for a Device Simulators, so the files must be prepared manually. It is suggested to copy the source files of one of the existing Device Simulators, and adapt them.

As example, the Lamp Device Simulator could be used. It is structured such that there is a library part, which could be re-used to implement other Device Simulators, with similar properties and the specific part, which is also the deployment module:

Generation of the SCXML State Machine Model

At this point in time, there is no way to share the same SXCML definition between the PLC and the associated DevSim. A solution for this may be provided at a later stage. Until then, the SCXML state chart can be generated from the MagicDraw state machine chart, in which the proper COMODO stereotypes have been applied. For instructions for how to create the SCXML definition, using MagicDraw and COMODO, consult the RAD User Manual. Alternatively, the SCXML state chart document, can be created by hand, by means of a text editor or an XML editor. An example of the SCXML chart for the Shutter Device can be accessed here (generated from the MagicDraw model, using COMODO).

Note: The newest version of Qt Creator support an SCXML mode, which in principle makes it possible to edit SCXML charts in a WYSIWYG fashion.

Generation of the OPC UA Namespace Profile

To facilitate generating the OPC UA XML namespace profile, a simpler and more compact format has been defined, based on YAML. An example of such a YAML Namespace Definition can be accessed here: Standard Shutter Device YAML Namespace Definition.

Although the format of the YAML Namespace Definition is self-explicatory, here a few comments:

Lef/right Columns:

The right column as an ‘internal name’, which may be used internally in the implementation of the Device Simulator code, but not necesarily. The right column is the name in the PLC namespace, the HW address. It is possible to define a specific data type for a name, by adding it in parentheses after the name, e.g. “StatCounter: stat.nCounter(UInt32)” (see list of supported types below). Default mapping of data types:

  • “b<name>” -> Boolean.
  • “n<name>” -> Int32.
  • “lr<name>” -> Float.
  • “s<name>” -> String.

The complete path is created by prepending “MAIN.” + <device name>, e.g. “Lamp1” + the HW address. An example of a complete name, as generated in the OPC UA namespace profile is, e.g.:

“ns=4;s=MAIN.Shutter1.stat.sStatus”

The “ns=4” indicates OPC UA namespace 4. For the moment, the convention is to use namespace 4. The “s=” that it is a string node ID, as opposed to an integer node ID. The “MAIN” is a convention, decided for the ELT ICS PLC code. Both namespace and the “MAIN” prefix may be made configurable, if necessary.

RPC Method Calls:

RPC method calls are defined as:

Rpc<Operation>: rpc.<Operation>([I:<Variable>(<type>)][,] O:<Variable>(<type>)])

whereby “I:” means input variable and “O:”, imaginatively, output value. The following types are supported:

  • Boolean
  • SByte
  • Byte
  • Int16
  • UInt16
  • Int32
  • UInt32
  • Int64
  • UInt64
  • Float
  • Double
  • String
  • DateTime
  • ByteString

The “ctdGenOpcuaProfile” tool, is invoked as follows on the YAML Namespace Definition:

$ ctdGenOpcuaProfile --device Shutter3 --name-mapping shutterNamespace.yaml
<?xml version="1.0" encoding="utf-8"?>
<UANodeSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd"
           xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <NamespaceUris>
    <Uri>http://www.eso.org/xmlShutter3/</Uri>
  </NamespaceUris>

  <UAObject NodeId="ns=1;s=PLC1" BrowseName="1:PLC1">
    <DisplayName>PLC1</DisplayName>
    <References>
      <Reference ReferenceType="HasTypeDefinition">i=58</Reference>
      <Reference ReferenceType="Organizes">ns=4;i=20737</Reference>
      <Reference ReferenceType="Organizes" IsForward="false">i=85</Reference>
    </References>
  </UAObject>
  ...

The output can be piped into a file, used as part of the configuration for the Device Simulator.

Example

$ fcfDevsimShutter --port 7677 --cfg fcf/devsim/devsimShutter/shutter1.yaml --use-ext-ip --log-level DEBUG --verbose
2018-12-04 12:31:52,821:INFO:DevSim:MainThread:deviceSimulatorBase:557:execute: Setting up OPC UA server ...
Listening on 134.171.2.213:7577
2018-12-04 12:31:54,411:INFO:DevSim:MainThread:deviceSimulatorBase:567:execute: Setting up OPC UA server - done
2018-12-04 12:31:54,411:INFO:DevSim:MainThread:deviceSimulatorBase:574:execute: Loading configuration: fcf/devsim/devsimShutter/shutter1.yaml
2018-12-04 12:31:54,413:INFO:DevSim:MainThread:deviceSimulatorBase:578:execute: Loading OPC UA namespace definition: fcf/devsim/devsimShutter/shutter1Namespace.xml
2018-12-04 12:31:54,484:INFO:DevSim:MainThread:deviceSimulatorBase:582:execute: Parsing OPC UA node info
2018-12-04 12:31:54,639:INFO:DevSim:MainThread:deviceSimulatorBase:442:set_node_permissions_: Setting node permissions
2018-12-04 12:31:54,667:INFO:DevSim:MainThread:deviceSimulatorBase:454:install_data_ch_subscr_: Installing data change subscription handlers
2018-12-04 12:31:54,670:INFO:DevSim:MainThread:deviceSimulatorBase:464:install_rpc_methods_: Installing RPC method handlers
2018-12-04 12:31:54,670:INFO:DevSim:MainThread:deviceSimulatorBase:472:install_rpc_methods_: Installing RPC method handler for: self.RPC_GetNamespace
...
2018-12-04 12:31:54,673:INFO:DevSim:MainThread:deviceSimulatorBase:472:install_rpc_methods_: Installing RPC method handler for: self.RPC_Init
2018-12-04 12:31:54,673:INFO:DevSim:MainThread:deviceSimulatorBase:499:gen_opcua_state_node_ids_: Generating OPC UA state machine node IDs
2018-12-04 12:31:54,673:INFO:DevSim:MainThread:deviceSimulatorBase:145:init_device_parameters_: Initializing device parameters
2018-12-04 12:31:54,676:INFO:DevSim:MainThread:deviceSimulatorBase:593:execute: SCXML state machine model: fcf/devsim/devsimShutter/scxmlShutter.xml
2018-12-04 12:31:54,676:INFO:DevSim:MainThread:stateMachine:62:__init__: Loading SCXML model: fcf/devsim/devsimShutter/scxmlShutter.xml
2018-12-04 12:31:54,682:INFO:DevSim:MainThread:stateMachine:73:__init__: Status:
2018-12-04 12:31:54,682:INFO:DevSim:MainThread:deviceSimulatorBase:598:execute: Serving ...
2018-12-04 12:31:54,683:INFO:DevSim:MainThread:stateMachine:86:run: Starting execution of /home/jknudstr/ROOTS/INTROOT_eltdev26/resource/config/fcf/devsim/devsimShutter/scxmlShutter.xml
2018-12-04 12:31:54,685:INFO:DevSim:MainThread:stateMachine:91:run: Status: On On::NotOperational On::NotOperational::NotReady

After generating the SCXML definition and OPC UA XML Profile, it is possible to start up the Device Server and connect to the Device Simulator OPC UA server and execute e.g. the provided RPC calls and read/write variables, e.g.:

alternate text

Shutter Device Namespace in UaExpert

Device Simulators

This section provides specific details about the various Device Simulators provided for Standard Devices.

Since the Device Simulators are used to emulate the PLC Controllers, they implement the same behavior and therefore, their behavior is described in the PLC section of the FCF user manual and not repeated here. Here only specific properties of the Device Simulators are mentioned.

The following common configuration parameters are supported by all Device Simulators:

Parameter Type Description
OpcUaProfile String Name of OPC UA Profile XML document, e.g. “fcf/devsim/devsimLamp/lamp1Namespace.xml”.
StateMachineScxml String Name of SCXML definition (document), e.g. “fcf/devsim/devsimLamp/scxmlLamp.xml”.
CfgSimAcceleration Float Factor, which can be used to tune the execution speed of actions in the Device Simulator, globally.
AutoEnterOp Boolean Enter Operation State automatically when starting up.
CfgSimDelay Float General delay that can be applied when a delay is needed to make the simulation more realistic [s].

Lamp Device Simulator

The state machine of the Lamp Device Simulator is the same as for the (Standard PLC Lamp Device).

The Lamp Device Simlutor defines the following configuration parameters:

Parameter Type Description
SimInitTime Float Time to spend for the initialisation [s].
CfgCoolDown Float Time to spend for the cool-down [s].
CfgInitialState Boolean Initial state to assume after enabling the device (True = On).
CfgMaxOn Float Maximum time the lamp is allowed to remain switched on [s].
CfgWarmUp Float Time spent for the warm-up phase [s].

Motor Device Simulator

The state machine of the Motor Device Simulator is the same as for the (Standard PLC Motor Device).

The Motor Device Simulator defines the following configuration parameters:

Parameter Type Description
CfgVelocityError Float Simulated error in % to be applied to the simulated velocity.
CfgSimPosError Float Simulated positioning error in % to be applied to the simulated position.
CfgSimTolerance Float Tolerance to apply for considering simuilated position on target [UU].
CfgSimulatedStartPos Float Start position of motor after start-up of application.
CfgScaleFactor Float Scale factor to apply for converting between UU and encoder values [UU/enc]
CfgMinPosition Float Minimum position [UU].
CfgMaxPosition Float Maximum position [UU].
CfgTimeoutInit Float Timeout applied during initialisation [s].
CfgTimeoutMove Float Timeout applied while moving simulated axis [s].
CfgTimeoutSwitch Float Timeout applied while moving simulated axis [s].
CfgDisableAfterMove Boolean Disable the current on the simulated axis after completion of a movement.
CfgLocal Boolean Indicates Local Mode if True.
CfgDefaultVelocity Float Default velocity to apply, e.g. during initialisation [UU/s].

Shutter Device Simulator

The state machine of the Shutter Device Simulator is the same as for the (Standard PLC Shutter Device).

The Shutter Device Simulator defines the following configuration parameters:

Parameter Type Description
CfgInitialState Boolean Initial state to assume after enabling the device (True = Open).