Machine Expert String Length Longer Than 255
Issue:
In Machine Expert, i need a string length longer than 255
Resolution:
STRING
With EcoStruxure Machine Expert V2.2 and later versions, the STRING data type
can be encoded in Latin 1 or in UTF-8 format. For project-wide interpretation as
UTF-8, enable the parameter UTF8 Encoding for STRING in the Project
Settings > Compile options dialog box. For further information, refer to ProjectWide UTF-8 Encoding, page 580.
NOTE: Before you set the encoding format to UTF-8, execute the static
analysis rule SA0175 (refer to the EcoStruxure Machine Expert Menu
Commands Online Help for details) on your code to help detect constructs that
may cause issues with UTF-8 encoding.
NOTE: If you use UTF-8 encoding, add the {attribute 'monitoring_
encoding' := 'UTF-8'} pragma, page 554 to the declaration of a variable.
It allows you to monitor the contents of the variable in UTF-8 encoding.
A STRING data type variable can contain any string of characters. The size entry
in the declaration determines the memory space to be reserved for the variable. It
refers to the number of bytes in the string and can be placed in parentheses or
square brackets. If no size specification is given, the default size of 80 bytes will
be used. If a variable is initialized with a string too long for the variable data type,
the string will be correspondingly cut from right to left.
String length:
• For Latin 1 encoding, the memory space needed for a variable of type
STRING is 1 byte per character + 1 additional byte. This means, the
“STRING[80]” declaration needs 81 bytes.
• With UTF-8 encoding, one character can have a length of up to four bytes.
The length of the string indicates the number of bytes which are reserved for
the STRING. Thus, there is no longer a 1:1 relationship between the
character count and the string length in bytes.
Example of a string declaration with 35 bytes:
str:STRING(35):='This is a String';
In general, the length of a string is not limited. When you execute string
manipulations with the functions of the Standard library, strings up to a length of
255 are allowed. When you execute string manipulations with the functions of the
StringUtils library, longer strings (>255 characters) are also permitted.
When a variable of the data type STRING is reinitialized by resetting the
application, the contents of the old string, that exist after the terminating null
character of the initial value, are not overwritten. This applies both to initialization
with the initialization value and to initialization with the default initialization value of
0.
For further information, refer to WSTRING and STRING Constants (Operands),
page 686.
https://download.schneider-electric.com/files?p_Doc_Ref=EIO0000004321&p_enDocType=User+guide
NOTE: You can use implicit checks to validate the conversion of variable
types (refer to the chapter POUs for Implicit Checks, page 175).
NB.
See more on Page 662 of 1220
https://download.schneider-electric.com/files?p_Doc_Ref=EIO0000004321&p_enDocType=User+guide