SECS - Example

This chapter describes the exemplary setup of a SECS driver.

Driver and connection configuration

First create a new SECS driver and give it a corresponding driver number.

Then start the project and go to System Management > Driver > SECS Connections and create a new connection. Configure the connection to your network needs and apply the settings.

Address configuration - Collection event

Configure the "_address" config for the event on a string DPE with the direction “Input”.

Use the CEID reference prefix and set the reference number 1 to an event ID from your equipment. Make sure to set the transformation to string and the direction to “Input” as well as the receive mode to “Spontaneous”.

Alarms

Configure an alarm address for a string DPE with the direction “Input” and receive mode “Spontaneous”. Make sure to set the transformation to string and the reference prefix to ALID and set the reference number one to an alarm ID from your equipment.

Furthermore, configure a multiinstance alarm config on an integer DPE with an _alert_class which is not acknowledgeable.

Next configure an address config with an “ALID_A” reference prefix. Use the same ALID in reference number one as in the string alarm DPE. With this configuration, the alarm notification message from the equipment with the chosen ALID will be written to the string DPE but will also be mapped to an WinCC OA alarm which can be seen in the “Alarmscreen” when the alarm is active.

Host Request

Now configure the address for two string DPEs which are used to request (direction “Output”) and receive (Direction “Input” Receive Mode “Spontaneous”) status variable values. The address reference prefix has to be set to “HREQ”. The reference number one can be chosen by the user, but it is recommended to use the stream and function number.

Device Request

Also configure an address for a request which is incoming from the device with the address reference prefix “EREQ”, the reference number one to the stream number and the reference number two to the function number of the request which you want to receive on this DPE. In this example we use the S7F3 (Process Program Send) request which is sent to the host (WinCC OA) and needs to be answered by a S7F4 acknowledge response. Because this is not an event, alarm or trace message, it must be answered manually for example by a CTRL-script. The example CTRL-script can be seen later in this chapter. It is important, that the S7F4 (Direction “Output”) address config has the same connection, reference and driver number as the S7F3 (Direction “Input” Receive mode “Spontaneous”) address config.

Device Constants

Also configure an address on a DPE which should be used to get and/or set device constant data. Use the device constant ID you would like to receive and/or set in the reference number one and set the reference prefix to “ECID”. Make sure that the transformation type matches the data type in the device. Configure the direction to “In/Out” and the receive mode to “Single query”.

Status Variables

The last configuration is to poll a status variable consistently. Configure a DPE with the direction “Input” and receive mode “Polling”. Set the address reference prefix to “SVID” and the reference number one to a SVID from the equipment. Configure a poll group and the corresponding transformation type for the datatype of the status variable.

Enable Connection

As a last step, enable the connection to the equipment. Make sure that the equipment has “Online Control” enabled.

Trigger Alarms, Events

A triggered SECS-II alarm on the equipment will show up as an WinCC OA alarm in the alarmscreen.

Also, the configured alarm string DPE should hold the alarm message received from the equipment. The message should have the structure like the following JSON alarm message.

{
  "header": {
    "function": 1,
    "stream": 5,
    "reply": true,
    "sessionId": 0,
    "systemBytes": 32
  },
  "body": [
    {
      "format": "B",
      "value": 128
    },
    {
      "format": "U4",
      "value": 1000
    },
    {
      "format": "A",
      "value": "Software test alarm 1000"
    }
  ]
}

Next trigger an event on the equipment with the configured CEID in the event address config. You should receive a JSON string on the DPE which looks like this:

{
  "header": {
    "function": 13,
    "stream": 6,
    "reply": true,
    "sessionId": 0,
    "systemBytes": 41
  },
  "body": [
    {
      "format": "U4",
      "value": 4001
    },
    {
      "format": "U4",
      "value": 4001
    },
    []
  ]
}

The empty array in the body can contain content if a report is defined which is linked to the triggered event.

Getting and Setting Device Constants

With the DPE where the “ECID.<ECID>” address reference is defined, the user can set the equipment constant by setting the "_original_value". After setting the value check if the value was set correctly in the equipment. Because of the receive mode “Single query” we can go to the internal "_DriverCommon" DPE with the corresponding number of the running SECS-driver and set the "_Driver<drvNum>.SQ _original..value" with the DPE-name where the equipment constant address is defined. After that check if the value was written to the "_original..value" of the device constant DPE.

Getting Status Variable Values

On the DPE where the “SVID.<SVID>” address reference is defined, the polling should already be active and value changes of the status variable should be visible on the _original_value depending on the poll group configuration.

Example CRTL-Scripts

The following CTRL-script is an example of how to answer incoming data from the device with an acknowledge message:

void main()
{
  dpConnect("acknowledgeCB", false, "Demo_Secs.S7F3");
}

acknowledgeCB(string sDp, string sJson)
{
  const mapping mReceivedJson = jsonDecode(sJson);
  const int iStream = mReceivedJson["header"]["stream"];
  const int iFunction = mReceivedJson["header"]["function"] + 1; // +1 because SxF1 is answered by SxF2 and so on
  mapping mAcknowledge = makeMapping(
    "header", makeMapping(
      "stream", iStream,
      "function", iFunction,
      "reply", false,
      "sessionId", mReceivedJson["header"]["sessionId"],
      "systemBytes", mReceivedJson["header"]["systemBytes"]
    ),
    "body", makeMapping(
      "format", "B",
      "value", 0 // OK acknowledge
    )
  );
  // check received body
  if(mReceivedJson["body"][1]["value"] != "banana")
  {
    mAcknowledge["body"]["value"] = 1; // NOK acknowledge
  }
  dpSet("Demo_Secs.S" + iStream + "F" + iFunction, jsonEncode(mAcknowledge));
}