Skip to main content

1.3 Language Elements

1.3.1 Character set

  • The Universal Coded Character Set (UCS) includes all other character sets. It guarantees bi-directional compatibility with other character sets, i.e., if user converts any text string to UCS format and then back to the original encoding, the user does not lose any information.The UCS contains all the characters of known languages.
  • According to the national standard GB/T15969.3-2005, the text elements in the text and graphic programming language used by programmable controllers should be composed of 3-7 columns of characters according to the “Basic Code Table” in the programmable controllers and expressed as Chinese characters according to the “Basic Set of Chinese Character Set for Editing Characters for Information Exchange” in the standard GB2312-1980.
  • Except for comments, string literals, and string variable values, uppercase and lowercase letters have the same meaning. For example, Control and CONTROL are the same variable name or identifier.

1.3.2 Identifier

  • Identifier : A string of letters, numbers, and underscore characters, starting with a letter or underscore character. However, trailing underscores are not allowed, and the font and case of letters in identifiers have no meaning. At the same time, identifiers are not allowed to start with multiple underscores or multiple embedded consecutive underscores. In Baosky PLC namespaces, variables, GVS, PU, FB,FC, etc. follow this specification.
  • Identifiers are used to name various variables, programs, configurations, resources, etc.
Serial numberFeature descriptionExample
1Uppercase letters and numbersW4;
ER8;
RT8
2Uppercase and lowercase letters, numbers, embedded underscoresVar2;
Var2_int;
Var2_int_9;
var1,var_int
3Uppercase and lowercase letters, numbers, leading or embedded underscores_Var2;
_12_int

1.3.3 Comments

  • Improve code readability: Comments can help other developers better understand the logic and intent of the code, saving time reading the code.

  • Convenient code maintenance: As the project iterates, the code may be changed and fixed. Good comments can help developers locate problems and make modifications more easily.

  • Comment related instructions are shown in the table below:

Comment descriptionExample
Single line comment //...x:=12;
//Assign the value of variable x to 12
Multi-line comments (*....*)(*a:=10;
b:=true;*)
Comment two lines of code
Multi-line comments /*....*//*a:=10;
b:=true;*/
Comment two lines of code
Nested comments use (*..(*..*)..*)(*(*b:=true;*)*)
Nested comments
Nested comments use /*../*..*/..*//*/*b:=true;*/*/
Nested comments

1.3.4 Literal (constant)

  • Literal: A literal is a value that represents the value of some constant. There are three types: numeric literal, string literal, and time literal. In computer science, a literal is a notation used to express a fixed value in source code.
  • Numeric literal: defined as a decimal number or base number. In a given implementation, the maximum number of bits for each numeric literal is sufficient to represent the entire range of values ​​of all data types represented by the literal.
  • Numeric literals are divided into two categories: integer literals and real number literals. The base of integer literals is decimal, and can also be expressed in base 2 or 16. For integer literals with base 16, use the extended set of digits A through F, which represent decimal 10 through 15. The base number should not contain the prefix "+" or "-". They are interpreted as bit string literals. Real numerical values ​​are distinguished by the presence of a decimal point.
  • The characteristics and examples of digital direct quantities are as follows
Serial numberDescriptionExampleExplanation
1Integer literal-12
123_4
+986
123_4 is equal to 1234
2Real literal0.0
0.369
3.141592_6
3.1415926 is equal to 3.141592_6
3Real literal expansion-1.34E-12,-1.34e-12
1.0E+6,1.0e+6
1.334E6,1.334e6
e (E) is not case sensitive
+ can be omitted
4Binary literal2#1111_1111
2#1110_0000
Binary all 1, represents decimal 255
Binary 111 represents decimal 224
5Hexadecimal literal16#FF or 16#ff
16#E0 or 16#e0
Hexadecimal FF represents decimal 255
Hexadecimal E0 represents decimal 224
6Boolean 0 or 1Number 0 or 1
7Boolean true or falseTRUE FALSE
8Type literalINT#-12
WORD#16#AFF
WORD#1234
1234=16#4D2
UINT#16#89AF
CHAR #'A'
BOOL#0
BOOL#1
BOOL#FALSE
BOOL#TRUE
  • String literal

    • Single byte: Occupying one byte, a single-byte string literal is a sequence of zero or more characters, beginning or ending with a single quote character. In a single-byte string, the three-character combination of the dollar sign followed by two hexadecimal digits can be understood as the hexadecimal representation of the 8-bit character code.
    • Single-byte string literals are shown in the following table:
    Serial numberDescriptionExample
    1Null (zero length)''
    2Char'a'
    3Space' '
    4Single quotes'$''
    5Dollar'$$'
    7Line break, input line'$L' or '$l'
    8New line'$N' or '$n'
    9Page change, input page'$P' or '$p'
    10Enter'$R' or '$r'
    11TAB key'$T' or '$t'
    12Supports single byte with $ character and two hexadecimal characters'$0A'
    13StringSTRING#'OK'
    14CharacterCHAR#'X'
  • Time literal

  • Duration data shall be defined by the keywords T#, TIME#, or LTIME# on the left. Duration data shall support representation by days, hours, minutes, seconds and milliseconds (LTIME# supports nanoseconds), and any combination thereof, with units permitted to be separated by an underscore character, and units of time such as seconds, milliseconds, etc., may be represented by uppercase or lowercase letters.

  • The inherent elements of time direct literal are shown in the following table:

Serial numberDescriptionExample
1ddays
2hhours
3mminutes
4sseconds
5msmilliseconds
6usmicroseconds
7nsnanoseconds
  • The common expressions of time literal length and short prefixes are as shown in the following table:
Serial numberDescriptionExample
1Short prefixT#14ms T#-14ms LT#14.7s T#14.7m
T#14.7h t#14.7d t#25h15m
t#5d14h12m18s35ms
lt#12h4m34ms230us400ns
2Short prefix (units separated by underscore character)t#25h_15m
t#5d_14h_12m_18s_35ms
3Long prefixTIME#14msTIME#-14ms
time#14.7s
LTIME#5m30s500ms100.1us
4Long prefix (units are separated by underscore characters)TIME#25h_15m
ltime#5d_14h_12m_18s_3.5ms
LTIME#34s_345ns
  • The common expressions of the literal length and short prefixes of time and date are as shown in the following table:
Serial numberDescriptionExample
1Date (long prefix)DATE#1984-06-25
date#2010-09-22
2Date (short prefix)D#1984-06-25
3Time (long prefix)TIME_OF_DAY#12:36:45.32
4Time (short prefix)TOD#15:15:15.36
5Time and date (long prefix)DATE_AND_TIME#1956-03-14-12:56:22
6Time and date (short prefix)DT#2021-03-25-14:56:23
warning

Only the smallest unit does not support floating point numbers

1.3.5 Keywords

  • A keyword is a combination of offset characters that is used as a separate syntax element.

  • Includes: basic data types, language elements, etc.

  • Keywords are shown in the table below:

Serial numberDescriptionKeywords
1BOOLBOOL
2ByteBYTE
3Word
4Double wordDWORD
5Long wordLWORD
6Short integer typeSINT
7Unsigned integer typeUINT
8Integer typeINT
9Unsigned integer typeUINT
10Double IntegerDINT
11Unsigned doubleUDINT
12Long IntegerLINT
13Unsigned longULINT
14real numberREAL
15Long real numberLREAL
16single-byte characterCHAR
17StringSTRING
20Duration (ms)TIME
21DateDATE
22Day and timeTIME_OF_DAY
23Date and timeTOD
24Date and timeDATE_AND_TIME
25Date and timeDT
26Long timeLTIME
32User-defined typeTYPE
33Type end definitionEND_TYPE
34ArrayARRAY ARRAY
35Array or CASE statement OFOF
58Logical trueTRUE
59Logical falseFALSE
60Start of variable segment within GVSGLOBAL VARIABLE
61Start of variable segment in PUVAR
62Start of temporary variable segment in PUTEMP
63Start of input variable sectionINPUT
64Start of output variable sectionOUTPUT
65Start of input and output variable sectionINOUT
66Start of variable segment within GVSGLOBAL CONSTANT
67ConstantLOCAL CONSTANT
68Save variables after power offRETAIN
69Negate (find the complement code)NOT
70Modulo operation (representing the remainder when a is divided by b)MOD
71"AND" operationAND
72"XOR" operationXOR
73"OR" operationOR
74IF instructionIF
75Instruction part of the IF instructionTHEN
76Selection conditions of IF instructionELSIF
77Alternative branches in IF and CASE statementsELSE
78End IF instructionEND_IF
79Introduction of CASE statementCASE
80End CASE statementEND_CASE
81Introducing the FOR statementFOR
82Define the entire range of values ​​for the FOR statementTO
83FOR loop incrementBY
84Introducing the directive section in the FOR and WHILE directivesDO
85End FOR statementEND_FOR
86Introduction of REPEATstatement REPEAT
87End REPEATInstruction part of statement UNTIL
88End REPEAT statementEND_REPEAT
89Introduction of WHILE instructionWHILE
90End WHILE commandEND_WHILE
91Terminate the current program channel in the loop and enter the next loopCONTINUE
92Instruction to exit the loopEXIT
93Introduction of GOTO statementGOTO
94Exit this program unitRETURN

1.3.6 Delimiter

  • Delimiters are used in “instructions” or statements to isolate, identify, etc. Commas are used to separate multiple variables; semicolons indicate the end of a one-day statement in ST;
  • The explanation part of the program and statements is stored between asterisks + brackets (**); the colon plus the equal sign indicates assignments in ST programming statements, etc.
  • Commonly used decomposition sets are shown in the following table:
DelimiterApplicationNotes and examples
SpaceSpaces can be inserted anywhere in the PLC programDirect insertion of spaces in keywords, text, identifiers and enumeration values ​​is not allowed
TABTAB can be inserted anywhere in the PLC programDirect insertion of TAB in keywords, text, identifiers and enumeration values ​​is not allowed
+Decimal prefix symbol (positive number);
Add operator
+456, +147;
22+78
-Prefix sign of decimal number (negative number);
Year-month-day separator;
Subtraction operator
-753;
D#2024-05-13;
15-2
#Base number delimiter;
Data type delimiter;
Time literal delimiter
2#1110;
SINT15;
T#20ms
.Separator for positive numbers and decimals;
Hierarchical addressing address character;
Structure element separator;
Function block instance structure separator;
Global namespace
;Namespace delimiter
3.14; IABC.3//IBC is a bit string data type;
Channel[0].type/abc.number;
TON1.Q;
SYS .SR
E/eExponent delimiter1.0e+6
' 'String start/end character'HelloWorld'
$The beginning of special characters in the string'$L' means line feed;
'$R' means carriage return
:Time text delimiter;
Variable/type delimiter
TOD#12:41:21.11;
Test: INT
:=Input variable connection operator;
Assignment operator
INT_1(SINGLE:=Z2,PRIORITY:=1)
()Subrange section break;
Initialization repetition factor;
Instruction list modifier;
Function argument;
Subexpression classification;
Function block Input table delimiter
DATA:INT(-100..100);
ARRAY[1..2,1..3] OF INT:=1,2,3(4),6;
(A>B);
ARlimit(Var1);
(a
(b-c)+d);< br/>TON_1(IN:=a,PT:=T#5m)
[]Array subscript delimiterARRAY[1..2,1..3] OF INT;
MMOD_5_CFG.CH[5].Range:=BI_10V
,Array subscript delimiter;
Function block initial value delimiter;
Function block input table delimiter;
Function argument table delimiter;
Case to table delimiter Symbol
ARRAY[1..2,1..3] OF INT := 1,2,3(4),6;
TON_1(IN:A,pt:=50ms)
SR_1(S1:=A,REAL:=B);
LIMIT(MN:=4,IN=A,MX:=20)
CASETEP OF 1,5:DISPLAY:=FALSE
;Statement separator
a:=15
..Array range delimiter;
Subrange;
Case range delimiter
ARRAR[1..2];
DATA:INT(-1000..1000);
CASETEPOF(1..5):display:=FALSE
%Directly represents the prefix of the variable%IW0
=>Output connection operatorC10(CU:=iNPUT, Q=>Out)