Skip to content

S7 Device Service Component

The S7 Device Service components integrate the S7 protocol with Edge Xrt.

The S7 Device Service Component supports the following features:

  • Communication with S7 PLC's
  • Data Block Read/Write
  • Process Input Image Read/Write
  • Process Output Image Read/Write
  • Read Last Job Result
  • Read PLC State
  • Read Connection State

S7 Device Service Configuration

Note

The core components required for running S7 (and all other device services) are contained in Device Service Component Configuration. Please refer to this page to ensure the appropriate core components are assigned before continuing.

Device Configuration

A template of the S7 Device Service configuration file is provided below:

{
  "Library": "libxrt-s7-device-service.so",
  "Factory": "xrt_s7_device_service_factory",
  "Name":"s7",
  "TelemetryTopic":"xrt/devices/s7/telemetry",
  "RequestTopic": "xrt/devices/s7/request",
  "ReplyTopic": "xrt/devices/s7/reply",
  "AutoRegister": true,
  "PublishRegisteredDevices": true,
  "PublishAttributes": true,
  "ProfileDir":"./deployment/profiles",
  "StateDir":"./deployment/state",
  "Scheduler":"sched",
  "Logger":"logger",
  "ThreadPool":"pool",
  "Bus":"bus"
}

S7 Device Profile

Details on general profile usage can be found on the Device Profiles page

The following sections will cover how device resources are used in S7.

Attributes

The attributes used in an S7 device resource are detailed in the following table:

Attribute Description Valid Values Value Descriptions
type Mandatory

The S7 type of the request.
Valid values are as follows:
  • DB
  • IPU
  • IPI
  • PLC
  • MISC
  • DB - Resource operates on a Data Block
  • IPU - Resource operates on a Process Output Image
  • IPI - Resource operates on a Process Input Image
  • PLC - Resource operates on a Programmable Logic controller or S7 Server
  • MISC - Resource carrys out Miscellaneous Operations not covered in other catergories
DB_number Mandatory if type is DB

The Data Block index to access.
Non-negative integer N/A
start Mandatory if type is DB, IPU or IPI

The starting byte to read from or write to in the block.
Non-negative integer N/A
size Mandatory if Data Type is a String and type is DB, IPU or IPI

The maximum string length.
Non-negative integer N/A
operation Mandatory if type is PLC or MISC

The Operation to be performed.
Valid values are as follows:
type is PLC
  • state
type is MISC
  • conn_state
  • err_text
  • job_res
  • state - The resource will read the operating state of the connected device
  • conn_state - The resource will read the connection state
  • err_text - Used for logging an S7 error message by sending an error code
  • job_res - The resource will read the result of the last job performed

Data Types

The following table shows the supported resource Data Types for each option of Attribute type and operation and whether the type supports multi-read in the service:

Attribute Type Value Attribute Operation Value Supported Data Type Description Read/Write Supported
DB N/A
  • Bool
  • Int 8/16/32/64
  • Uint 8/16/32/64
  • Float 32/64
  • String
Indicates the resource operates on a Data Block
  • Read and Write
  • Multi-read
IPU N/A
  • Bool
  • Int 8/16/32/64
  • Uint 8/16/32/64
  • Float 32/64
  • String
Indicates the resource operates on the Process Image Output Block
  • Read and Write
  • Multi-read
IPI N/A
  • Bool
  • Int 8/16/32/64
  • Uint 8/16/32/64
  • Float 32/64
  • String
Indicates the resource operates on the Process Image Input Block
  • Read and Write
  • Multi-read
PLC state
  • String
Read the current state of the PLC Read Only
MISC conn_state
  • String
Read the current connection status to a provisioned device Read Only
MISC job_res
  • String
Read the last job result Read Only
MISC err_text
  • Int 8/16/32/64
Used for logging an S7 error message based on the input error code Write Only

Note

When using the String data type for a request that uses the type attribute set to either DB, IPU or IPI, the S7 string header information will take up an additional 2 bytes of memory in addition to the maximum string length set by the size attribute. For example a data block of maximum string size 8 will take up 10 bytes of memory on the PLC.

Multi-Read/Multi-Write Support

For requests using type set to DB, IPU or IPI, multi-read and multi-write functionality is supported. This uses one request to an end device to receive or write multiple data instances. To use multi-read or multi-write resources with the type DB, IPU or IPI add the resources into a device command. PLC and MISC operations are not supported for multi-read or multi-write and must not be included in device commands.

Example Resources

This section shows examples of resources in an S7 device profile.

Below is an example device profile resource entry for reading or writing a String to a Data Block. This resource allows reading or writing String data of maximum size 30 (bytes) to Data Block 1, starting at index 30 of the Data Block. As detailed above the following attributes are considered mandatory for this resource:

  • DB_number
  • size
  • start
  • type
    {
      "attributes": {
        "DB_number": 1,
        "size": 20,
        "start": 30,
        "type": "DB"
      },
      "name": "DB_String",
      "properties": {
        "readWrite": "RW",
        "valueType": "String"
      }
    }

Below is an example of a resource using the attribute type set to PLC and operation set to state. This allows reading the current operating state of the PLC. As detailed above the following attributes are considered mandatory for this resource:

  • type
  • operation
    {
      "attributes": {
        "operation": "state",
        "type": "PLC"
      },
      "name": "PLC_request",
      "properties": {
        "readWrite": "R",
        "valueType": "String"
      }
    }

Below is an example of a resource using the attribute type set to MISC and operation set to conn_state. This allows reading the current connection state of the device. As detailed above the following attributes are considered mandatory for this resource:

  • type
  • operation
    {
      "attributes": {
        "operation": "conn_state",
        "type": "MISC"
      },
      "name": "connection_request",
      "properties": {
        "readWrite": "R",
        "valueType": "String"
      }
    }

Device Commands

Device commands in the S7 Device Service component will attempt to use multi-read during a Get request. This makes a single request to the device, receiving all the data within one request. See the Data Types table and Multi-Read Support for information on attributes that support multi-read.

See the Device Profiles page for details on how to define device commands for grouping device resources for fewer requests.

S7 Device Provisioning

The following section will explain how to configure a device for the S7 Device Service.

Note

For information on dynamic device additions, removals and updates please see the MQTT API Guide.

Provisioning

To provision an S7 device, the S7 protocol must be used along with the following protocol properties:

  • IP : property which specifies the IP address of the Server or PLC to connect to.
  • Rack : property which specifies the Rack to connect to on the PLC, typically where the CPU is.
  • Slot : property which specifies the Slot to connect to on the PLC, typically where the CPU is.

An example of an S7 device within the devices.json file is provided below:

{
  "S7-Server": {
    "profileName": "Server",
    "protocols": {
      "S7": {
        "IP": "0.0.0.0",
        "Rack": 0,
        "Slot": 2
      }
    }
  }
}

S7 Device Service Interaction

For information on how to dynamically execute reads, writes, setting up schedules and more, please refer to the MQTT API Guide.

For interactive examples of the S7 Device Services refer to S7 Xrt Example. Follow the instructions in those links which will demonstrate many features of Edge Xrt with the device service running against an S7 simulator.