SIMATIC S7 S7-1200 Programmable Controller - SCL
SIMATIC S7 S7-1200 Programmable Controller - SCL
SIMATIC S7 S7-1200 Programmable Controller - SCL
SCL
SCL
• Instruction tree that contains the SCL instructions supported by the CPU
You enter the SCL code for your instruction directly in the code section. The editor includes
buttons for common code constructs and comments. For more complex instructions, simply
drag the SCL instructions from the instruction tree and drop them into your program. You can
also use any text editor to create an SCL program and then import that file into STEP 7.
This document constitutes a free excerpt compiled by the user himself/herself from the documentation provided by Siemens for this product. Siemens disclaims all
liability for the completeness of this document. It shall only be used for the user's own internal purposes. It shall not be passed on to third parties.
1/26/2024
SIMATIC S7 S7-1200 Programmable controller
SCL
In the Interface section of the SCL code block you can declare the following types of parameters:
• Input, Output, InOut, and Ret_Val: These parameters define the input tags, output tags, and return
value for the code block. The tag name that you enter here is used locally during the execution of
the code block. You typically would not use the global tag name in the tag table.
• Static (FBs only; the illustration above is for an FC): The code block uses static tags for storage of static
intermediate results in the instance data block. The block retains static data until overwritten, which
can be after several cycles. The names of the blocks, which this block calls as multi-instance, are also
stored in the static local data.
• Temp: These parameters are the temporary tags that are used during the execution of the code block.
If you call the SCL code block from another code block, the parameters of the SCL code block
appear as inputs or outputs.
In this example, the tags for "Start" and "On" (from the project tag table) correspond to
"StartStopSwitch" and "RunYesNo" in the declaration table of the SCL program.
This document constitutes a free excerpt compiled by the user himself/herself from the documentation provided by Siemens for this product. Siemens disclaims all
liability for the completeness of this document. It shall only be used for the user's own internal purposes. It shall not be passed on to third parties.
1/26/2024
SIMATIC S7 S7-1200 Programmable controller
SCL
The evaluation of the expression occurs in a certain order, which is defined by the following
factors:
• Every operator has a pre-defined priority, with the highest-priority operation performed first.
• For operators with equal priority, the operators are processed in a left-to-right sequence.
The result of an expression can be used either for assigning a value to a tag used by your
program, as a condition to be used by a control statement, or as parameters for another SCL
instruction or for calling a code block.
Math Power ** 2
Multiplication * 4
Division / 4
Modulo MOD 4
Addition + 5
Subtraction - 5
Equal to = 7
OR logic operation OR 10
Assignment Assignment := 11
As a high-level programming language, SCL uses standard statements for basic tasks:
• Assignment statement: :=
This document constitutes a free excerpt compiled by the user himself/herself from the documentation provided by Siemens for this product. Siemens disclaims all
liability for the completeness of this document. It shall only be used for the user's own internal purposes. It shall not be passed on to third parties.
1/26/2024
SIMATIC S7 S7-1200 Programmable controller
SCL
• Addressing of global variables (tags): "<tag name>" (Tag name or data block name enclosed in double
quotes)
• Addressing of local variables: #<variable name> (Variable name preceded by "#" symbol)
Arithmetic operators can process various numeric data types. The data type of the result is
determined by the data type of the most-significant operands. For example, a multiplication
operation that uses an INT operand and a REAL operand yields a REAL value for the result.
Control statements
A control statement is a specialized type of SCL expression that performs the following tasks:
• Program branching
• Conditional execution
The SCL control statements include IF-THEN, CASE-OF, FOR-TO-DO, WHILE-DO, REPEAT-UNTIL,
CONTINUE, GOTO, and RETURN.
A single statement typically occupies one line of code. You can enter multiple statements on
one line, or you can break a statement into several lines of code to make the code easier to read.
Separators (such as tabs, line breaks and extra spaces) are ignored during the syntax check. An
END statement terminates the control statement.
The following examples show a FOR-TO-DO control statement. (Both forms of coding are
syntactically valid.)
A control statement can also be provided with a label. A label is set off by a colon at the beginning
of the statement:
Label: <Statement>;
The STEP 7 online help provides a complete SCL programming language reference.
This document constitutes a free excerpt compiled by the user himself/herself from the documentation provided by Siemens for this product. Siemens disclaims all
liability for the completeness of this document. It shall only be used for the user's own internal purposes. It shall not be passed on to third parties.
1/26/2024
SIMATIC S7 S7-1200 Programmable controller
SCL
Conditions
A condition is a comparison expression or a logical expression whose result is of type BOOL
(with the value of either TRUE or FALSE). The following example shows conditions of various
types.
Addressing
As with LAD and FBD, SCL allows you to use either tags (symbolic addressing) or absolute
addresses in your user program. SCL also allows you to use a variable as an array index.
Absolute addressing
%I0.0 Precede absolute addresses with the "%" symbol. Without
the "%", STEP 7 generates an undefined tag error at
%MB100
compile time.
Symbolic addressing
"PLC_Tag_1" Tag in PLC tag table
"Data_block_1".Tag_1 Tag in a data block
"Data_block_1".MyArray[#i] Array element in a data block array
This document constitutes a free excerpt compiled by the user himself/herself from the documentation provided by Siemens for this product. Siemens disclaims all
liability for the completeness of this document. It shall only be used for the user's own internal purposes. It shall not be passed on to third parties.
1/26/2024
SIMATIC S7 S7-1200 Programmable controller
SCL
Note
To use the PEEK and POKE instructions with data blocks, you must use standard (not optimized)
data blocks. Also note that the PEEK and POKE instructions merely transfer data. They have no
knowledge of data types at the addresses.
%MW200 := PEEK_WORD(area:=16#84,
dbNumber:=1, byteOffset:=#i);
PEEK_DWORD Reads the double word referenced by byteOffset of
(area:=_in_, dbNumber:=_in_, byteOffse the referenced data block, I/O or memory area.
t:=_in_); Example:
%MD300 := PEEK_DWORD(area:=16#84,
dbNumber:=1, byteOffset:=#i);
PEEK_BOOL Reads a Boolean referenced by the bitOffset and
(area:=_in_, dbNumber:=_in_, byteOffse byteOffset of the referenced data block, I/O or
t:=_in_, bitOffset:=_in_); memory area
Example:
%MB100.0 := PEEK_BOOL(area:=16#84,
dbNumber:=1, byteOffset:=#ii, bitOffset:=#j);
This document constitutes a free excerpt compiled by the user himself/herself from the documentation provided by Siemens for this product. Siemens disclaims all
liability for the completeness of this document. It shall only be used for the user's own internal purposes. It shall not be passed on to third parties.
1/26/2024
SIMATIC S7 S7-1200 Programmable controller
SCL
POKE_BOOL(area:=16#84, dbNumber:=2,
byteOffset:=3, bitOffset:=5, value:=0);
POKE_BLK Writes "count" number of bytes starting at the
(area_src:=_in_, dbNumber_src:=_in_, b referenced byte Offset of the referenced source
yteOffset_src:=_in_, area_dest:=_in_, db data block, I/O or memory area to the referenced
Number_dest:=_in_, byteOffset_dest:=_in_, byteOffset of the referenced destination data block,
count:=_in_); I/O or memory area
Example:
POKE_BLK(area_src:=16#84,
dbNumber_src:=#src_db,
byteOffset_src:=#src_byte, area_dest:=16#84,
dbNumber_dest:=#src_db,
byteOffset_dest:=#src_byte, count:=10);
For PEEK and POKE instructions, the following values for the "area", "area_src" and "area_dest"
parameters are applicable. For areas other than data blocks, the dbNumber parameter must be
0.
16#81 I
16#82 Q
16#83 M
16#84 DB
This document constitutes a free excerpt compiled by the user himself/herself from the documentation provided by Siemens for this product. Siemens disclaims all
liability for the completeness of this document. It shall only be used for the user's own internal purposes. It shall not be passed on to third parties.
1/26/2024
SIMATIC S7 S7-1200 Programmable controller
SCL
"MyDB"(MyInput:=10, MyInOut:="Tag1");
"MyFC"(MyInput:=10, MyInOut:="Tag1");
You can also drag blocks from the navigation tree to the SCL program editor, and complete the
parameter assignment.
See also
→ Basic instructions
→ Extended instructions
→ Using blocks to structure your program
This document constitutes a free excerpt compiled by the user himself/herself from the documentation provided by Siemens for this product. Siemens disclaims all
liability for the completeness of this document. It shall only be used for the user's own internal purposes. It shall not be passed on to third parties.
1/26/2024