Text and language
As a basic principle, texts and languages are managed in the PLC HMI with the aid of text lists. ANSI and Unicode are available as character encoding variants. In the visualization elements can be labelled in two different ways:
- Static text
- Dynamic text
Static text
A visualization element can be assigned a static text by entering the text in the element properties under the category ‘Texts’. He can also be entered directly in the Editor window, if the element is selected and the space bar is pressed. This text cannot be changed at runtime. Only changes of the language are accepted for the text.
Each static text is automatically saved in the text list "GlobalTextList". In this text list the translations in other languages are also managed.
Dynamic text
Dynamic text is entered in the element properties under the category ‘Dynamic texts’. To this end the name of the text list first has to be selected from the lists that are present in the PLC project. The "GlobalTextList" cannot be used here, only user-created text lists. In addition, a variable for the ID of the text entry must be specified, through which the text can be changed at runtime.
Example
As an example, a text list with the name "ErrorList" is created. In this list a number of error messages with their translations are entered.
A rectangle element is added to a visualization with the name "Visualization". In the properties of this element the text list "ErrorList" is selected under "Dynamic texts" and the variable "nErrorId", which is declared in "MAIN".
At runtime one of the error messages stored in the text list "ErrorList" can be displayed in the rectangle, by setting the variable "nErrorId" to a value between greater than or equal to 0 and less than or equal to 4. "nErrorID" has a value of 2 in the example.
Language switching
If the currently used text list defines text translations in several languages, the language to be used at the start of the visualization can be specified. In addition, the language can be changed at runtime with the aid of buttons on the visualization. The action "Change the language" in the element settings under the category "Input configuration" is used for this purpose.
The variable "CURRENTLANGUAGE" from the library "VisuElems" can be used for querying the currently used language. This variable can also be used to change the language in the program code:
fbTrigger(CLK := bPressed);
IF fbTrigger.Q THEN
IF VisuElems.CURRENTLANGUAGE = 'de' THEN
VisuElems.CURRENTLANGUAGE := 'en';
ELSE
VisuElems.CURRENTLANGUAGE := 'de';
END_IF
END_IF
If the text list contains no entry that matches the currently set language, the entry under Default is used. |
The definition of a default language at the start of the visualization and the use of the variable "VisuElems.CURRENTLANGUAGE" is only possible in conjunction with the PLC HMI and/or the PLC HMI Web. With an integrated visualization, the text version ‘Standard’ is automatically used on startup. Language change at runtime via buttons on the visualization is also possible in the integrated visualization. |
Formatting the text
In addition to entering pure texts in the element properties under the category ‘Texts’, it is also possible to add formatting information for the text display in online mode. A formatting specification always starts with “%”, followed by a character that determines the formatting type. It can be used on its own or in combination with the actual text.
The variable to be output as text in the element should be specified in the element properties under the category ‘Text variables’. To display the instance name of a variable, which was transferred as input parameter to a visualization function block, use the pragma attribute 'parameterstringof'.
%b | Binary number |
%c | Individual character |
%d, %i | Decimal number |
%f | REAL value |
%o | Unsigned octal number (without prefixed zero) |
%s | Character string |
%u | Unsigned decimal number |
%x | Unsigned hexadecimal number (without prefixed ‘0x’) |
Example
"Fill level: %2.5f mm" is entered in the "Text" property field in the "Texts" category of the properties of a rectangular element. The variable to be used is specified in the input field "Text variable" under the category "Text variables". In this example it is "fFillLevel". It is declared as REAL in the program MAIN.
At runtime, the rectangle element looks as follows:
To display a percent sign % in combination with one of the formatting specifications described above, enter “%%”. Example Enter "Rate in %%: %s" to obtain the following in online mode: "Rate in %: 12" (if the text variable currently returns "12"). |
Output of the system time
A combination of "%t" and the following special placeholders inside square brackets is replaced in online mode by the current system time. The placeholders define the display format.
Importing TwinCAT PLC 2 Control projects: The previously used time format %t is automatically converted to the new %t[] format, if an old project is imported, although the following placeholders are no longer supported: %U, %W, %z, %Z. |
Valid placeholders:
ddd | Name of the day of the week, abbreviated, e.g. "Wed" |
dddd | Name of the day of the week, e.g. “Wednesday” |
ddddd | Day of the week as a number (0 – 6; Sunday is 0) |
MMM | Name of the month, abbreviated, e.g. “Feb” |
MMMM | Name of the month, e.g. “February” |
d | Day of the month as a number (1 – 31), e.g. “8” |
dd | Day of the month as a number (01 – 31), e.g. “08” |
M | Month as a number (1 – 12), e.g. “4” |
MM | Month as a number (01 – 12), e.g. “04” |
jjj | Day in the year as a number (001-366), e.g. “067” |
y | Year without specification of the century (0-99), e.g. “9” |
yy | Year without specification of the century (00-99), e.g. “09” |
yyyy | Year with specification of the century, e.g. “2009” |
HH | Hour, 24-hour format (01-24), e.g. “16” |
hh | Hour, 12-hour format (01-12), e.g. “4” for 4 pm |
m | Minutes (0-59), without prefixed zero, e.g. “6” |
mm | Minutes (00-59), with prefixed zero, e.g. “06” |
s | Seconds (0-59), without prefixed zero, e.g. “6” |
ss | Seconds (00-59), with prefixed zero, e.g. “06” |
ms | Milliseconds (0-999), without prefixed zero, e.g. “322” |
t | ID for the display in 12-hour format: A (hours <12) or P (hours >12), e.g. “A” if the time is 9 o'clock in the morning |
tt | ID for the display in 12-hour format: AM (hours <12) or PM (hours >12), e.g. “AM” if the time is 9 o'clock in the morning |
' ' | Strings containing one of the placeholders listed above must be enclosed in single inverted commas. All other texts within the format strings can be without inverted commas; e.g. 'update', since a "d" and a "t" are included. |
Example
"%t['Last update:' ddd MMM dd.MM.yy 'at' HH:mm:ss]" is entered in the property field "Text" in the category "Texts" of the properties of a rectangular element.
At runtime, the rectangle element looks as follows:
Font and alignment
The font and the horizontal and vertical alignment of the element text can be defined in the element properties. See categories "Font variables" and "Text properties" for the respective element.