Skip to content

Device S7 - Data Type Conversion

In use cases where the S7 device resource uses a WORD data type with a Int16 number, a WORD has two bytes, should converts to a integer.

The following extract from a device profile defines the NodeName DB4.DBW2 as valueType Int16:

Example - Device Profile

name: S7-Device
manufacturer: YIQISOFT
description: Example of S7 Device
model: Siemens S7
labels: [ISO-on-TCP]
deviceResources:
    - name: word
    description: PLC word
    isHidden: false
    properties:
        valueType: Int16
        readWrite: RW
    attributes:
        NodeName: DB4.DBW2

Read Command

A Read Command is executed as follows:

  1. The Client executes a Read Command;
  2. The device service sends the Read Command to read a WORD data;
  3. The S7 Device returns a two byte data;
  4. The device service parses the data;
  5. The device service cast the data to a Int16 value;
  6. The device service returns returns json format to the Client.

data type conversion read

Write Command

A Write Command is executed as follows:

  1. The Client executes a Write Command to write a In16 value;
  2. The device service cast Int16 value to a two bytes;
  3. The device service convert to binary;
  4. The device service send write a request to the S7 device;
  5. The device service returns result json to the Client.

data type conversion write

When to Transform Data

You generally need to transform data in any time, because S7 devive only receives its particular data type.

Supported Transformations

The supported transformations are as follows:

From NodeName Bit(s) To valueType Address Sample
Bool 1 Bool DB1.DBX0.0
Byte 8 Uint DB1.DBB1
Word 16 Int16 DB1.DBW2
DWord 32 Int32 DB1.DBD4
Int 16 Int16 DB1.DBW6
DInt 32 Int32 DB1.DBD8
Real 32 Float32 DB1.DBD20