Skip to main content

OPC UA Binary Data Encoding

The OPC UA Binary Data Encoding is a data format which has been developed to meet the performance demands of OPC UA applications. This format is primarily designed for fast encoding and decoding, whereby the size of the encoded data on the line has also been taken into account.

OPC UA binary data encoding is based on several primitive data types with clearly defined encoding rules that can be sequentially written to or read from a binary stream.

A structure is encoded by sequentially writing the encoded form of each field. If a particular field is also a structure, then the values of its fields are written sequentially before the next field is written to the containing structure.

All fields must be written to the data stream, even if they contain zero values. The encodings for each primitive type indicate how to encode either a zero value or a default value for the type.

The OPC UA binary data encoding does not contain any type or field name information because all OPC UA applications are expected to know in advance which services and structures they support.

[P6] 5.2.1:

"The terms OPC UA Binary Data Encoding and Raw Data Field Encoding have the same meaning and are used accordingly depending on the cited source."

Table 1. Mapping the elementary data types

IEC 61131-3

[P6] 5.2.1

OPC UA

References

BOOL

Boolean value

1

Boolean

[P6] 5.2.2.1

BYTE

Byte

3

Byte

CHAR

Single-byte character

3

Byte

DATE

Date (only)

13

DateTime

DINT

Double integer

6

Int32

DT

Date and time of day [s]

13

DateTime

[P6] 5.2.2.5

DWORD

Bit string of length 32

7

UInt32

INT

Integer

4

Int16

[P6] 5.2.2.1

LDATE

Long date [ns]

8

Int64

LDT

Date and time of day [ns]

8

Int64

LINT

Long integer

8

Int64

LREAL

Long floating-point number

11

Double

LTIME

Duration [ns]

8

Int64

LTOD

Time of day [ns]

8

Int64

LWORD

Bit string of length 64

9

UInt64

REAL

Floating-point number

10

Float

[P6] 5.2.2.3

SINT

Short integer

2

SByte

STRING

Coding: Windows-1252

12

String

[P6] 5.2.2.4

TIME

Duration [ms]

8

Int64

TOD

Time of day [ms]

7

UInt32

UDINT

19

StatusCode

[P6] 5.2.2.11

UDINT

VersionTime

[P4] 7.38

UDINT

Unsigned double integer

7

UInt32

UINT

Unsigned integer

5

UInt16

ULINT

Unsigned Iong integer

9

UInt64

USINT

Unsigned short integer

3

Byte

WCHAR

Double-byte character

5

UInt16

WORD

Bit string of length 16

5

UInt16

WSTRING

Coding: UCS-2

12

String



String

The length of an OPC UA string cannot be determined in advance due to its UTF 8 encoding. It depends on the characters used. Therefore, a maximum length must be specified when defining a DataSetField of this data type. The remaining space is filled with 0 value bytes. The maximum length of a string (maxStringLength) is described in [P14] 6.2.2.1.3 FieldMetaData.

StatusCode

The variable StatusCode is encoded as UInt32.

VersionTime

The variable VersionTime is encoded as UInt32. It shows the time in seconds since the year 2000. The epoch date is midnight UTC (00:00) on January 1, 2000. It is used as a version number based on the last modification time. If the version is updated, then the new value must be greater than the previous value. The value 0 is used to indicate that no version information is available.