Article - CS333015
Siemens S5 Byte Swapping in Strings
Modified: 02-Nov-2020
Applies To
- Kepware Server (formerly KEPServerEX) 5.19.467.0 to 6.8
- ThingWorx Kepware Server (legacy) 8.0 to 8.4
Description
In KEPServerEX V5.15, the Siemens S5 driver was enhanced to support byte swapping for the String data type. Strings can be from 2 to 254 characters (bytes) in length. All strings are assumed to be in a HiLo byte order, meaning that for each register (which is 2 bytes in length) there can be 2 characters. An issue can occur if an odd string length is used or if an odd number of characters is written to the string and the incorrect byte order is used. For example, assume that there is a tag with the address "DB1:KS0.5H" and with a value of "AFTER" written to it. If users read it from a tag with an address of "DB1:KS0.5L" they would see a value of "FAET". This is because the tag is consuming DB1 Register 0, 1, and 2. The actual value stored in the three registers is 0x414651455200. The last byte of the string is the string terminator, which is a Null (0x00). When the byte order is swapped, the registers are essentially viewed as having a value of 0x464145540052. When updating the tag value, the driver stops at the null value. This will also occur anytime a non-printable character is included in the string. PLC programmers should avoid including control characters (0x01 to 0x1F) or any extended characters (0xA0 to 0xFF) in registers that will be read as part of a string.
This is a printer-friendly version of Article 333015 and may be out of date. For the latest version click CS333015