Using SCL Instructions in TIA Portal
Introduction
In SCL, like any other programming language, various instructions are used to implement the PLC program. However, since SCL is counted as one of the advanced programming languages, using its instructions requires taking into account some tips so that the PLC program does not run into errors. Therefore, you should familiarize yourself with the types of SCL instructions and the rules for adding them to the program code.
Prerequisites
What you will need to follow along with this tutorial are
- An installation of TIA Portal software on your computer. The TIA Portal version 16 will be utilized in this tutorial; however other TIA Portal versions are also acceptable.
- An understanding of how to create an SCL block in the TIA Portal.Â
- An understanding of SCL Elements.
Types of instructions in SCL
An SCL instruction is an action that can be executed in a program block's code section. SCL recognizes the following instruction types:
- Value assignments: When a tag needs a constant value, the outcome of an expression, or the value of another tag, value assignments are utilized, as in logical and mathematical statements. It is the most frequent form of instruction in SCL programming that can be used to determine the values of internal variables and set physical outputs.
The outcome value of a mathematical equation (#Overal_Area) is allocated to a floating-point variable. Notice the use of the colon and equal sign to indicate equality. All standard arithmetic operations are available for use.
- Instructions for program control: Program branches, loops, and jumps are implemented inside the SCL program using program control instructions.
In the WHILE…DO loop, shown in figure 1.2, the statement that is existed between DO and END_WHILE statements (#Output1 := TRUE), is run only while the condition after the WHILE statement (#Input_Switch) is true.
Other control instructions include FOR and IF...THEN...ELSE. CASE, EXIT, GOTO, and RETURN are control instructions utilized for various branching actions.
- Additional instructions from the Instructions task card: The Instructions task card provides a comprehensive set of standard instructions for use in your SCL application.
- Block calls: Block calls are used to invoke subroutines that have been put in other blocks and to handle the results of those subroutines. Program blocks, such as organizational blocks (OBs), can call blocks like Functions (FCs) or Function blocks (FBs).
For blocks like Functions, the block can be created with parameters, referred to as formal parameters, that can have values provided to them as part of the appropriate block calls.
Rules for SCL instructions
The following rules must be followed while inputting SCL instructions into the program:
- Instructions may span many lines.
- Each instruction concludes with a semicolon (;).
- The use of upper and lower case is not distinguished, and
- Comments are solely used to document the program. They do not affect how the program is run.
Entering SCL instructions manually
Observe the following procedures to enter SCL instructions manually:
- The SCL block must be open
- You can use the keyboard to enter the instruction's syntax. The auto-complete feature assists you in completing this process by providing available instructions and operands at the present position.
- Choose the desired operand or the needed instruction from the auto-complete list. When you choose an instruction that needs operands specification, placeholders for the operands are put into the program. The operands’ placeholders are marked in yellow, and the initial placeholder is chosen.
- Put an operand in this placeholder. Also, a declared operand can be dropped into the program by dragging it from the block interface or the PLC tag table.
- To traverse to all other placeholders to change them to operands, you can use the <TAB> key.
- Hover the mouse cursor over the operand to be replaced before letting go of the mouse button to replace an already-inserted operand. This action selects the operand, and when you let go of the mouse button, a new operand takes the existing operand's place.
- The syntax is checked by the programming editor. With red underlining, incorrect entries are visible. In addition, a detailed error notice appears in the inspector window.
Utilizing the "Instructions" task card to insert SCL instructions
The "Instructions" task card contains many instructions you may use in your SCL program. The "Instructions" task card includes the SCL-specific program control instructions. Use the "Instructions" task card to add SCL instructions to a program by performing the following actions:
- The SCL block must be open
- The "Instructions" task card should be opened.
- You have two options to insert the instruction. The first way is to navigate to the SCL instruction you wish to enter and drag and drop it into the appropriate line of program code. A green rectangle indicates the position of the insertion.
The second way is to choose the place in the program code where you wish to enter the instruction and then double-click the instruction you want to insert.
The instruction is added to the program. Yellow highlights are placed over the operand placeholders. The optional parameters, which are not required to be interconnected, are shown in light yellow. The essential parameters you must interconnect are denoted by a darker yellow.
Favorites usage in SCL
Take the following actions to add SCL instructions to the Favorites:
- The SCL block must be open.
- The "Instructions" task card is set to operate in multi-pane mode (by deselecting the Change pane mode button), or the Favorites are also visible in the SCL editor (by left-clicking the Display favorites in the editor button in the program editor toolbar).
- The "Instructions" task card should be opened.
- Expand the "Basic instructions" pane.
- Locate the instruction you wish to add to the Favorites by navigating to it in the "Basic instructions" pane.
- Put the instruction in the program editor's Favorites section or the Favorites pane by dragging and dropping it there.
Utilizing Favorites to insert SCL instructions
Use Favorites to add an instruction to a program by doing the following steps:
- The SCL block must be open.
- The Favorites section in the program editor or the Favorites pane in the Instruction task card should be available.
- Move the required instruction from Favorites to the desired location by dragging and dropping it there.
Or, choose the place in the program where you desire to enter the instruction and insert that instruction by selecting it in the Favorites.
How are SCL instructions deleted from the Favorites?
The actions below should be followed to remove instructions from Favorites:
- A code block is open.
- Right-click over the instruction you wish to delete.
- Select the "Remove instruction" command from the pop-up menu.
Adding pragmas
Using pragmas, you have the opportunity to assign validities to your program code. To accomplish so, use Pragma keywords to enclose the program code and assign at least one parameter. You can optionally specify more parameters to determine the content.
It should be noted that in string constants, the character $ is used as an escape sequence, and as a result, it cannot be used as a regular sign for the parameter name. Figure 8.1 displays the standard syntax for pragmas.
Pragmas can be nested as well. However, make sure that the pragmas included within other pragmas are correctly finished. If it’s required, you can expand and collapse pragmas.
To add a pragma into the program, do the following procedures:
- Wherever you wish to insert a pragma, place the mouse cursor.
- Type {PRAGMA_BEGIN in the position you’ve placed your cursor.
- At least add one parameter with single quote marks.
- As you like, you can add additional parameters within single quote marks. It is an optional step.
- Type } at the end of the line where you’ve placed parameters.
- Put the mouse cursor at the end of the program code you wish to encircle with the pragma.
- Enter {PRAGMA_END}, and as a result, you have a pragma containing the associated program code.
Conclusion
This tutorial discussed types of instructions and the rules for adding them to the program code in Structured Control Language (SCL). You learned SCL recognizes four types of instructions: value assignments, program control instructions, additional instructions from the Instruction task card, and block calls for calling subroutines.
You learned the rules for SCL instructions, how to enter instructions manually, and how to use the Instruction task card to insert instructions into the program.
You became familiarized with the rule of Favorites section containing the most frequently used instructions for SCL programming and how to assign validities to the program code by inserting pragmas.