Article - CS333281

The Server Returns a String from the S7-1200 PLC with the First Two Characters Missing

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

Problem: The first two characters are missing when reading a string from a data block in a Siemens S7-1200 PLC. Possible Cause: â?? A string that is created in a data block in the S7-1200 PLC will have a fixed length of 256 bytes. Its first two bytes tell the length of the current string data and the maximum length of the string. In order to be a specific length in a PLC data block, the string must be created as an array of characters. In both types of data blocks, the end of the string will be marked with a null terminator. If a tag is created as a string in the server, the driver will always treat the first two bytes as the length fields. As a result, it will not read them. For example, an array of 18 characters is created in "DB 12" and is initialized to the value of "KEPWARE". If a tag is then created in the server with an address of "DB12,STRING0,18" a value of "PWARE" will be displayed in the client. This is because the driver assumes that the first two bytes are length data. If a tag is created in the server with an address of "DB12,C0,18" and the data type is set to string, the entire string will be displayed as a value in the client. Solution: When reading true strings from a data block, use the String address type. Alternatively, use the character address types to ensure that the leading characters are not ignored.
This is a printer-friendly version of Article 333281 and may be out of date. For the latest version click CS333281