top of page
Search
Writer's pictureIvaylo Fiziev

SCL Editor


Ok. We already know SCL a little bit. Now how do I use it in Process Simulate? Where do I write the code? How do I organize my logic? There should be some editor right? But how on earth I make use of it?

The short answer is: Yes. There is an editor that allows you to implement your logic per resource. Each resource can have a SCL script assigned. The script is known as the "main" function block (FB). The SCL editor allows you to edit this block.

Why a function block you may ask? It is simple. If you recall function blocks allow for preserving a state between simulation cycles. e.g. they have static variables. Functions do not have these and this makes them unusable for the "main" script. They simply have no state. And if you have no state then the logic inside is useless.

The 'main" function block may or may contain other function block instances. If you use another function block as a static variable then the state of this function block will be also preserved. The code of this function block will work on the state inside. This rule can be recursively applied to all nested function block instances.


Let's take a look at the SCL editor now. (version 2304)

At first it might look confusing. The syntax for the function block was something different right? No. Underneath the syntax is the same. The SCL editor simply tries to make it easier to write. How?


Well it splits the syntax in two areas:


a) variable declaration area (the upper half on the picture) - the editor uses a table control for the variables. So instead of declaring the variables in the code you simply do it visually. e.g. provide the variable name, type, default value, comment using standard UI tools. Signals can also be connected to input and output variables with a click of the mouse.


b) code area ( the lower part of the picture) - this is where you put the code. The code works on the state of the variables.


The toolbar provides a few options. Here is the meaning by order of appearance:


a) load the SCL code for a selected resource in the editor

b) execute the code outside simulation so you can test it

c) save the SCL code on the loaded resource

d) copy the SCL code (full FB syntax)

e) paste the SCL code (full FB syntax)

f) show/hide the variables table

g) expand all variables

h) collapse all variables

i) toggle script debugger


Most of the buttons are self explanatory and intuitive to use. The script debugger is one of the recent additions to SCL in Process Simulate. It deserves a separate post for sure.


Some usability hints:


a) The code you put in the script is considered prototype data. So if you copy the resource the code will be copied as well.

b) Connected signals/ default values are considered instance data. So you'll have to set them again if you copy the resource.

c) when you copy the code it copies the full FB code. When you paste the code of the FB will be parsed so variable and code sections are populated correctly. You can use this to distribute the same code on different resources if you have to.

d) every change that you do does not take effect until you save the script.


Advanced features:


a) Context based code assistance is available in the SCL editor.

It triggers automatically based on where the cursor is in the text but can also be activated using the standard Ctrl+Space hotkey. I plan to bring in some insights to this in a separate post as well.


b) The SCL editor tries to do basic grammar/semantic validation of the code.

  • it will underline incorrect tokens:

  • it will underline missing variables, functions, arguments etc.

Here we have some limitations because of the UI control that we use. (it will underline all occurrences of the problematic token causing headaches to the user). Hopefully we will replace the control in future versions.


c) Error reporting.

When you execute a script that has error inside you'll get this kind of popup.

You should be informed that errors are detected only in the active path of execution. e.g. let's say you have an if statement that holds an expression that is never true. In this case the code inside won't be executed so no error will be reported.


31 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page