Use of Regions in SCL Language

TIA PORTAL provides one very interesting option where you can keep all your codes in separate areas. This helps for ease in troubleshooting. Due to this, if there is any issue in a code, you can see clearly which area has faults. Then, you can access that code and solve it. This option is called a region in SCL language. In this post, we will see how to use regions in the best way in SCL language.

What is a region in the SCL language?

A region is a feature by which you can structure your codes in specific defined areas. You have to name these regions and due to this, you will get a clear idea of what you have written in the program. Simply speaking, suppose there are 20 lines in a code. Out of that, the first 10 lines perform a different task and the other 10 lines perform a different task. Means, there are 2 groups in short. So, we can name these two groups as regions. Due to this, a programmer will know that there are two types of statements working in a code.

Regions can be expanded or collapsed in view. Due to this, the navigation becomes fast and you can decide which region to show and which region to hide. One more feature is that if a particular line in a region has an error, then that region will be highlighted with a cross mark. Due to this, you can quickly navigate to that region and rectify that fault.

How to write regions in the SCL language?

Refer to the below image. Here, we have defined two regions. One is named as for and the other is named as while_do. The general syntax for writing a region is:

Region name

Statements

End_Region

So here, the first region covers the for statement written. The second region covers the while-do statement written. You can name the region in any way you require. You can use the tab for expanding or collapsing a view as shown.

Use of Regions in SCL Language

In the second image below, you can see a collapsed view of the regions. Due to this, you can clearly understand how many separate groups are working in a code. The variables may be linked in the whole program, but you can at least distinguish the groups which work in a similar manner.

On the left hand side, you can see the region names and even expand or collapse the view by clicking there. This also clearly helps in understanding the number of regions written in a section. When the arrow is down, it means the view has been expanded. When the arrow is right, it means the view has collapsed.

SCL Regions in TIA Portal

In the third image below, you can see a compile error written on line no.41, where the end keyword was commented. Due to this, that particular region showed a red cross mark as shown. This helps the programmer to quickly visit that region and see where the fault is.

Siemens SCL Region Programming Example

You can also right-click the region name and copy-paste it. This simplifies the process even more easily. Also, you can nest regions within regions. But remember to end them correctly; otherwise, a compile error will occur.

In the next post, we will see how to write a repeat-until statement 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!