Infosys在阅读器中打开 / AI 翻译

TF6xxx - Connectivity · 0 次阅读

Strings

According to the PLCopen mapping, the PLC data types STRING and WSTRING are both mapped to the OPC UA data types String. The difference lies in the internal storage:

Both data types are explained below. For more details, please refer to the TwinCAT 3 PLC documentation.

STRING

The STRING data type can be interpreted in TwinCAT as either Latin-1 or UTF-8.
The interpretation is controlled via the {attribute 'TcEncoding'} attribute:

Examples:

// Standard: Latin-1
sMyStringText   : STRING := 'This is a STRING';

// UTF-8 from STRING
{attribute 'TcEncoding' := 'UTF-8'}
sMyUTF8Text1    : STRING  := sLiteral_TO_UTF8('The dinner costs 30 €.');

// UFT-8 from WSTRING
{attribute 'TcEncoding' := 'UTF-8'}
sMyUTF8Text2    : STRING  := wsLiteral_TO_UTF8("The dinner costs 30 €.");

// UFT-8 simple STRING
{attribute 'TcEncoding' := 'UTF-8'}
sMyUTF8Text3    : STRING  := 'Hello World.';

Strings 1:

WSTRING

The WSTRING data type follows the UCS2 coding (2 bytes per character). Initialization always takes place with double quotation marks.

Sample:

wsMyWSTRING : WSTRING := "This is a WSTRING.";
Strings 2: