Siemens S7: Write Node

The Siemens S7: Write Node allows you to write one or more values to a PLC that supports the Siemens S7 protocol.

Siemens S7 Write Node

Node Properties

There are three main parts of the configuration for this node.

Connection Config

Siemens S7 Write Node Connection

Connection Config contains five fields:

  • Host Template: (Required) A string template for the IP address at which the S7 PLC resides.
  • Port Template: (Required) A string template or integer for the HTTP port. Defaults to “102”.
  • Timeout Template: (Optional) A string template or integer for the number of milliseconds to wait before a timeout will occur. Defaults to “30000”.
  • Rack Template: (Required) A string template or integer for the PLC Rack number. Defaults to “0”.
  • Slot Template: (Required) A string template or integer for the PLC Slot number. Defaults to “0”.

Write Instructions

Siemens S7 Write Node Instructions

Write Instructions can be specified in one of two ways.

  • Array of Template Strings: For each Write Instruction, fill out the following input configuration fields, all of which can utilize templates. You must define at least one instruction:

    • Value Type: (Required) Either “Single Value” or “Array of Values”, depending on whether you wish to write one value or an array of values at the provided location.

      • If “Single Value” is chosen, a string template, boolean, or number will be expected for Value Template.
      • If “Array of Values” is chosen, a payload path that resolves to an array will be expected for Value Path.
    • Database Template: (Required) A string template or integer for which database to write to. This should resolve to an integer between “0” and “65535” inclusive.
    • Offset Template: (Required) A string template or integer for the offset at which to write to within the database. This should resolve to an integer between “0” and “2147483646” inclusive.
    • Data Type Template: (Required) This field is a dropdown with a list of valid data types as options. This field can also accept a template string, but it must resolve to a valid data type.
    • Value Template/Path: (Required)

      • If Value Type is “Single Value”, this field expects a string template, boolean, or number depending on the data type. See Data Type Formats for the expected value formats.
      • If Value Type is “Array of Values”, this field expects a payload path to an array of values you wish to write.
    • Result Key: (Optional) The key at which to store the result of this write operation. This key will exist on the Result Path defined below the instructions. This can resolve to any string except errors, since that key is reserved for any errors that occur during writes. The value at this key will always be a boolean (true for success and false for failure).
  • Payload Path: Enter a payload path that resolves to an array of Write Instructions to be run on this node. The following are the object properties that each object in the array should contain for successful attempts:

    • valueType: (Required) Either singleValue or arrayOfValues depending on whether you wish to write one value or an array of values at the provided location.

      • If singleValue is chosen, a string, boolean, or number will be expected for value.
      • If arrayOfValues is chosen, an array of values will be expected for value.
    • db: (Required) An integer for which database to write to. The integer must be between “0” and “65535” inclusive.
    • offset: (Required) An integer for the offset at which to write to within the database. The integer must be between “0” and “2147483646” inclusive.
    • dataType: (Required) A string, which must be a valid data type.
    • value: (Required)

      • If valueType is singleValue, this field expects a string, boolean, or number depending on the data type. See Data Type Formats for the expected value formats.
      • If valueType is arrayOfValues, this field expects an array of values you wish to write.
    • key: (Optional) The key at which to store the result of this write operation. This key will exist on the Result Path defined below the instructions. This can resolve to any string except errors, since that key is reserved for any errors that occur during writes. The value at this key will always be a boolean (true for success and false for failure).

The following is an example of an array that you could pass in:

[
  {
    "valueType": "singleValue",
    "db": 12,
    "offset": 10,
    "dataType": "DINT",
    "value": 27,
    "key": "doubleInt"
  },
  {
    "valueType": "arrayOfValues",
    "db": 12,
    "offset": 20,
    "dataType": "BOOL",
    "value": [
      false, true, true, false
    ],
    "key": "boolArray"
  }
]

Data Type Formats

When writing values, they must be in the proper format for the chosen “Data Type”.

BOOL

The BOOL data type accepts booleans or “true” and “false” strings.

BYTE

The BYTE data type accepts two hexadecimal characters.

INT

The INT data type accepts an integer between “-32768” and “32767” inclusive.

WORD

The WORD data type accepts an integer between “0” and “65535” inclusive.

DINT

The DINT data type accepts an integer between “-2147483648” and “2147483647” inclusive.

DWORD

The DWORD data type accepts an integer between “0” and “4294967295” inclusive.

REAL

The REAL data type accepts a float between “-3.402823e+38” and “3.402823e+38” inclusive.

CHAR

The CHAR data type accepts a single ASCII character.

TIME

The TIME data type accepts an integer between “-2147483648” and “2147483647” inclusive.

TIME_OF_DAY

The TIME_OF_DAY data type accepts a Date object, a date string, a time string, or a positive integer representing milliseconds since Epoch.

DATE

The DATE data type accepts a Date object, a date string, or an integer representing days since 01/01/1990 between “0” and “65378” inclusive. If a Date object or date string is provided, the value must be between 01/01/1990 and 12/31/2168 inclusive.

Result Path

Siemens S7 Write Node Result

The results of each write instruction with a Result Key defined are placed in an object at the Result Path (a payload path) at each instruction’s Result Key. The value at each key will always be a boolean (true for success and false for failure).

It is important that each key is named uniquely so the node does not overwrite another write result.

If the value at a key is false, the write failed, and there is an array of errors at the Result Path under errors. For this reason, this node restricts Result Keys from resolving to the path errors. If an individual write fails, an error object will be placed into the array at the key errors.

A single write failing does not necessarily mean all writes will fail. If a connection is unable to be made to the S7 PLC, or if the request is too large, only one error will be returned for the entire operation.

Node Example

The following is an example of a successful write, where an instruction’s Result Keys are boolArray and doubleInt and the Result Path is working.result:

{
  "working": {
    "result": {
      "boolArray": true,
      "doubleInt": true
    }
  }
}

Node Errors

The following is an example of a failure to write, where a Result Key should have been boolArray, and the Result Path is working.result:

{
  "working": {
    "result": {
      "boolArray": false,
      "errors": [
        {
          "key": "boolArray",
          "type": "S7_WRITE_ERROR",
          "message": "Failed to write key boolArray. ***Something useful to help you fix the issue.***"
        }
      ]
    }
  }
}

Was this page helpful?


Still looking for help? You can also search the Losant Forums or submit your question there.