Serializing WSTRING - Manual - SIMATIC AX - System.Serialization - System.Serialization,

System.Serialization library

Portfolio
SIMATIC AX
Product
SIMATIC AX
Software version
10.3.25
Edition
01/2026
Language
English (original)
Package Name
@ax/system-serde

For WSTRING, the serialization buffer always stores its (little-endian-encoded or big-endian-encoded, see above) length in the first two bytes at the given offset, followed by the (little-endian-encoded or big-endian-encoded, see above) WCHARs in sequence. In the following example (and when using little endianness for the serialization):

  • t[4] = 2, t[5] = 0, together they store the little-endian-encoded length 2;
  • t[6] = 97, t[7] = 0, together they store the little-endian-encoded WCHAR "a";
  • t[8] = 98, t[9] = 0, together they store the little-endian-encoded WCHAR "b".
USING System.Serialization;

FUNCTION SerDe_Demo
    VAR_TEMP
        data : ARRAY[0..10] OF BYTE;
        wstr : WSTRING := "ab";
        nextValueOffset : UDINT;
    END_VAR

    // data = [0x0, 0x0, 0x2, 0x0, 0x61, 0x0, 0x62, 0x0, 0x0, 0x0, 0x0]
    // nextValueOffset = 8
    nextValueOffset := Serialize(UDINT#2, wstr, data);
END_FUNCTION