Skip to main content

Brownfield Siemens S7 Devices

Siemens S7 binding

The Siemens S7 binding allows you to connect to Siemens S7 PLCs (like S7-1200, S7-1500) using the TCP/IP protocol. This binding supports reading and data from/to the PLC. For more advanced use case, we recommend using the OPC UA binding, which provides a more comprehensive interface to the PLC. This binding is useful for legacy system integration or when the OPC UA server is not available on the PLC.

Configuration

brownfieldDevices:
s7:
- name: S7-1200
type: TCP
address: 10.20.30.40
port: 102

Mapping S7 data to your OPC UA Variable

You can use the mapping section in the configuration file to map S7 data to OPC UA Variables.

mapping:
- node: /di:DeviceSet/own:MyObject/own:MyInt32
s7: plc1:DB1,INT12

- node: /di:DeviceSet/own:MyObject/own:MyFloat1
s7: plc1:DB2,REAL16

- node: /di:DeviceSet/own:MyObject/own:MyFloat2
value: |
(
$mb := $s7("plc1:DB2,REAL16");
{
"value": $mb.value / 10.0 + 3.14,
"statusCode": $mb.statusCode
};
)

- node: /di:DeviceSet/own:MyObject/own:MyFloatArray
s7: plc1:DB1,REAL24.4

- node: /di:DeviceSet/own:MyObject/own:MyBoolArray
s7: plc1:DB3,X0.4.4

- node: /di:DeviceSet/own:MyObject/own:MyBool
s7: plc1:DB3,X0.2

S7 Data Types

The S7 binding supports various data types used in Siemens S7 PLCs. The following table lists the S7 data types and their corresponding OPC UA types:

S7 TypeOPC UA TypeDescription
INTInt3216-bit signed integer
DINTInt3232-bit signed integer
REALFloat32-bit floating point number
LREALDouble64-bit floating point number
BOOLBoolean1-bit boolean value
BYTEByte8-bit unsigned integer
WORDUInt1616-bit unsigned integer
DWORDUInt3232-bit unsigned integer
STRINGStringString data type (up to 255 characters)
TIMEDurationTime duration in milliseconds
DATEDateDate value
DATE_AND_TIMEDateTimeDate and time value

automatic typ coercion

  • We recommend using the correct S7 data type in the mapping to ensure that the data is correctly interpreted by the binding.
  • However, the S7 binding automatically converts the S7 data types to the corresponding OPC UA data types when reading or writing data. For example, if you read an INT from the PLC for a UAVariable taht contains a Float data type, the binding will convert the INT value to a Float value before storing it in the OPC UA Variable.

S7 Addressing

The S7 binding uses the following addressing scheme:

  • DB<number>: Data block, e.g., DB1, DB2
  • INT<number>: Integer data type, e.g., INT12
  • REAL<number>: Real data type, e.g., REAL16
  • X<number>.<byte>.<bit>: Bit addressing, e.g., X0.4.4 (byte 0, bit 4)
  • M<number>: Memory area, e.g., M0.0 (memory byte 0, bit 0)
  • I<number>: Input area, e.g., I0.0 (input byte 0, bit 0)
  • Q<number>: Output area, e.g., Q0.0 (output byte 0, bit 0)
  • P<number>: Peripheral area, e.g., P0.0 (peripheral byte 0, bit 0)

Reading Array of Values

You can read arrays of values from the PLC by specifying the data type and the starting address. The binding will automatically convert the array elements to the corresponding OPC UA data types.

mapping:
- node: /di:DeviceSet/own:MyObject/own:MyIntArray
s7: plc1:DB1,INT12[0..9] # Read an array of 10 INT values from DB1 starting at address INT12
  • automatic coercion of the array elements to the corresponding OPC UA data types is supported.
  • the corresponding UA variable must be an array or a matrix type with valid dimensions.

Flexibility of the mapping

Notes

  • The S7 binding supports reading and writing data to the PLC.

using value JSondata functions

You can use the $s7 Josonata function to read data from the PLC in a more flexible way. This allows you to perform calculations, transformations, and other operations on the S7 data before storing it in the OPC UA Variable.

mapping:
- node: /di:DeviceSet/own:MyObject/own:MyFloat2
value: |
(
$mb := $s7("plc1:DB2,REAL16");
{
"value": $mb.value / 10.0 + 3.14,
"statusCode": $mb.statusCode
};
)
```


The `$s7` function takes a string argument that specifies the PLC name, data block, and data type. The function returns a JSON object with the `value` and `statusCode` fields.