Skip to content

Introduction

Twincat Driver documentation

Version: 1.0.0

TwinCAT integrates real-time control with PLC, NC, and CNC functions in a single package. This driver is intended to provide an easy to use interface using ESF to communicate with TwinCAT devices via TCP/IP. The TwinCAT driver is based on the open-source Beckhoff ADS library.

Prerequisites

  • ESF version 6.2.0 or greater
  • PLC (or TwinCAT simulator) running TwinCAT version 2.0 or greator

TwinCAT driver interface

  • Remote IPv4 address - The IP address of the PLC running TwinCAT.
  • Remote Ams Net ID - The Remote Ams Net ID of the PLC running TwinCAT.
  • Remote Ams Port - The Remote Ams Port number of the PLC running TwinCAT.
  • Timeout - Time to wait (in seconds) for a connection to be made from the device running ESF to the PLC running TwinCAT.
  • Max string length - Max string length that can be stored in the PLC running TwinCAT.
  • Should add remote - If set to true, the driver will create a new route on the remote PLC based on the other Driver configuration parameters. This operation should be performed only once, and it is necessary only if a suitable route is not already in place on the PLC. The following options are only necessary if this iption is set to true, othwerise they are discarded.
  • Local IPv4 address - The IP address of the device running ESF.
  • Local Ams Net ID - The Local Ams Net ID of the device running ESF. This is usually <local IPv4 address>.1.1.
  • Route name - The name of the route to be created in the PLC to the device running ESF.
  • Username - Username on the PLC running TwinCAT.
  • Password - Password on the PLC running TwinCAT.

TwinCAT asset interface

When creating an asset for the TwinCAT driver, there are several options for the data type:

Data type value.type Description
BOOL BOOLEAN A boolean value (TRUE or FALSE)
BYTE INTEGER An 8-bit unsigned integer value (0 to 255) - same as USINT
USINT INTEGER An 8-bit unsigned integer value (0 to 255) - same as BYTE
SINT INTEGER An 8-bit signed integer value (-128 to 127)
WORD INTEGER A 16-bit unsigned integer value (0 to 65535) - same as UINT
UINT INTEGER A 16-bit unsigned integer value (0 to 65535) - same as WORD
INT INTEGER A 16-bit signed integer value (-32768 to 32767)
DWORD LONG A 32-bit unsigned integer value (0 to 4294967295) - same as UDINT
UDINT LONG A 32-bit unsigned integer value (0 to 4294967295) - same as DWORD
DINT INTEGER A 32-bit signed integer value (-2147483648 to 2147483647)
LWORD STRING A 64-bit unsigned integer value (0 to 18446744073709551615) - same as ULINT
ULINT STRING A 64-bit unsigned integer value (0 to 18446744073709551615) - same as LWORD
LINT INTEGER A 64-bit signed integer value (-9223372036854775808 to 9223372036854775807)
REAL FLOAT A 32-bit floating point value
LREAL DOUBLE A 64-bit floating point value
STRING STRING An ASCII string (1 byte per character)
WSTRING STRING A wide string (2 bytes per character)
RAW BYTE_ARRAY Raw bytes
ADS_STATE INTEGER ADS state

When selecting a data type, the value type must match the table above. The reason we need to use value.type LONG for data type DWORD/UDINT is because Java does not support unsigned types and using INTEGER for it would overflow. For the same reason we need to use value.type STRING for data type LWORD/ULINT.

For all data types, the field for the handle should match what is in the PLC running TwinCAT. The only exception is ADS_STATE which does not require a handle, and could be set to anything (since it's a required field). The ADS_STATE must have values between 0 and 17. Each value represents a different state based on the Beckhoff documentation.

For the RAW data type, the offset and length should be set to some value. For the other data types, these fields can be empty.

Below is an example of the asset interface for the TwinCAT driver in ESF 6.2.0: Alt text

Errors

A list of error codes related to ADS can be seen in the official Beckhoff documentation: