Cookies are important for this site to function properly, to guarantee your safety, and to provide you with the best experience. By clicking OK, you accept all cookies. For more information, please access our Privacy Policy.
Table of Contents
Tutorials / 
Using SCL Instructions in TIA Portal
Advanced

Using SCL Instructions in TIA Portal

Siemens
TIA Portal
PLC Programming
Structured Control Language (SCL)

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

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.

Figure 1.1: An example of a value assignment
  • 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.

Figure 1.2: An example of a program control instruction
  • Additional instructions from the Instructions task card: The Instructions task card provides a comprehensive set of standard instructions for use in your SCL application.
Figure 1.3: Additional instructions embedded into Instructions task card
  • 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.

Figure 1.4: Calling FC in the Main OB

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.
Figure 2.1: Rules for SCL instructions

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.
Figure 3.1: Autocomplete feature of SCL programming
  • 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.
Figure 3.2: Operands’ placeholders
  • 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.
Figure 3.3: Declaring operands for placeholders - Action
Figure 3.4: Declaring operands for placeholders - Result
  • To traverse to all other placeholders to change them to operands, you can use the <TAB> key.
Figure 3.5: Moving to the next placeholder
  • 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.
Figure 3.6: Replacing existing operand with the new operand - Action
Figure 3,7: Replacing existing operand with the new operand - Result
  • 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.
Figure 3.8: Checking the syntax of a program code

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.
Figure 4.1: Using the Instruction task card to insert instruction - The first method - Action
Figure 4.2: Using the Instruction task card to insert instruction - The first method - The result

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.

Figure 4.3: Using the Instruction task card to insert instruction - The second method

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.

Figure 4.4: Essential parameters vs optional parameters

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).
Figure 5.1: Favorite sections in the programming editor
  • 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.
Figure 5.2: Adding instructions to the Favorite sections - Action
Figure 5.3: Adding instructions to the Favorite sections - Result

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.
Figure 6.1: Adding instructions to the program from Favorite sections - First method - Action
Figure 6.2: Adding instructions to the program from Favorite sections - First method - Result

Or, choose the place in the program where you desire to enter the instruction and insert that instruction by selecting it in the Favorites.

Figure 6.3: Adding instructions to the program from Favorite sections - Second method - Action

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.
Figure 7.1: Removing instructions from Favorite sections

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.
Figure 8.1: Adding pragmas to the program

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.