Rules for Writing SCL Language in Tia Portal

In the earlier post, we saw how to use value assignments in SCL language. Be it any statement or condition, there are certain rules to follow when writing this language. It usually applies to all the platforms where ST language is available. If proper syntax and instructions are not followed, then compiling errors will come and you will not be able to solve the issue. In this post, we will thus see some general rules to be followed for writing SCL language in the TIA portal.

Rules for Writing SCL Language

  1. A statement in SCL language must always end with a semicolon. This does not apply to a condition start; like if you use while-do structure, then the semicolon will come inside each statement and not after the while-do line. Then, once the structure is finished, a semicolon too must be used. For example, in our while-do structure, it ends with end_while. So, a semicolon must be used to terminate it. In short, every statement where write instruction is executed and every end of a structure type must be terminated by a semicolon.
  2. It is not necessary to use structures like if-else or while-do compulsory in the program. For example, a simple statement like – tag1:= tag2 AND (NOT tag3); can also work. You could have written it as:

if (tag2 AND (NOT tag3)) then

tag2:=1;

else

tag2:=0;

end_if;

Due to this, your coding size will be reduced. It all depends on how you interpret your conditions well and try to optimize it.

  1. It is also not compulsory to use spaces and tabs. But, using them makes the program look more aesthetic and clean. Just congesting all the words makes no use. A single space is allowed between two variables, but you can use as many spaces and tabs to make an expression look easier. For example, the below construct

            If (tag1 =  tag2)

            Then

            Tag3 := tag4;

            End_if;

It can also be written properly as below, which makes the programmer know that the  below construct is an if-else statement.

            If (tag1 =  tag2)

                        Then

                                    Tag3 := tag4;

            End_if;

  1. You can write as many lines as you require in a single program. It depends on how you need to optimize the code and reduce memory consumption of the PLC.
  2. The SCL language is not case sensitive. So, if you have defined a variable names test and used Test in the code, then too the variable can be compiled without any error.
  3. It is not compulsory to use comments in the program. They are only for understanding purposes. However, it is recommended to use them for easier troubleshooting. Usually, a comment is started with // or starts with (* and ends with *).
  4. All the available data types according to IEC standard can be used in SFC language and there is no limit to it.
  5. The operators inside a condition or statement are executed according to precedence order, also called as order of operations. In mathematics, it is also called as parenthesizes. // or starts with (* and ends with *). A comment can also be used to bypass an expression from the program and not bring it into the execution scan of PLC.
  6. All the available data types in PLC according to the IEC standard can be used in the SLC language code. Just remember to match them properly in an expression. Means, you cannot compare a boolean tag with an integer tag for example. So, the use of correct data types are a must in the program.
  7. Similarly as used in mathematics, an expression executes the operators inside it according to the precedence order. It is also known as order of operations. For example, in (tag1 + tag2 * tag3), multiplication will execute first, and the result will then be added. That means, operators with higher precedence are executed first, and then goes on to lower priorities.
  8. Bracket termination is important to use, otherwise your program will not compile. For example, you have (( brackets in the start, but end with ))) brackets; then your program will not compile. Whatever is the number of brackets in start, the same number of them must be used in the end to terminate an expression or construct.

In this way, we saw some general rules pertaining to writing SCL language in the TIA portal. In the next post, we will see the detailed use of if-else constructs in SCL language.

Read Next:

Don't Miss Our Updates
Be the first to get exclusive content straight to your email.
We promise not to spam you. You can unsubscribe at any time.
Invalid email address

Leave a Comment

Share via
Follow us and never miss an update!