Compiling an ST Program or ST Library
You can use the Build menu options to compile your ST program. The compilation feature is useful as it checks that your program has the correct syntax.
There are 2 compile options:
- Compile—Compiles the program. If the program is invalid, the compiler display provides a message that briefly describes the syntax error in your program. If the syntax is correct, the compiler displays a success message.
- Compile with Diagnostics—Compiles the program and provides detailed diagnostic information (the Logic in ST, the ST code formatted with indented text etc., and the op codes which is the machine code version of the ST code). As with the Compile option, there are messages for any errors in the syntax. If the syntax is correct, the compiler displays a success message.
The Compile with Diagnostics tool is useful when working with other types of Logic program that you want to use as ST programs. For example, you may find it easier to create a Function Block Diagram and then use the Compile with Diagnostics tool to access the ST code for the Function Block Diagram. You can then copy this code into an ST program (you have to remove the $ signs in the code).
To compile an ST program or ST library:
- Display the ST program or ST library in Design mode.
- Select the Build menu, then select the Compile option or the Compile with Diagnostics option as required.
The program or library is compiled and the compile messages are shown in the Compiler display.If there are syntax errors, you will need to alter the ST code. Typically, the causes of syntax errors are minor, such as the wrong type of value being specified or a missing semi-colon.
When you have successfully compiled your program, you can use the Debug option to check that its Logic defines the required behavior (see Debugging an ST Program).
If a database item's name includes parentheses ( ), you should ensure that each opening parenthesis is paired with a closing parenthesis.
When you include SQL queries in ST programs, and use braces '{' and '}' within SQL statements, you should use the caret '^' escape character before each brace.
For example:
VAR NOCACHE
rsPoints AT %S(SELECT ID, CurrentValueFormatted, CurrentTime FROM CSIMPLEPOINT WHERE CURRENTTIME = ^{ OPC 'D' ^}): RESULTSET OF Point;
END_VAR
If you reference system status tags in your ST programs, you need to prefix the names of those system status tags with an additional caret '^' escape character. This escapes the reserved caret '^' character that is used at the start of the names of system status tags (also known as 'status attributes') (see Access System Status Information).
For example:
VAR
sServerStateTime AT %M(^^<server name>.ServerStateTime): DATE_AND_TIME;
END_VAR