We already know that a resource is assigned a "main" function block. But wait. It cannot work in isolation from other blocks right? How does the "main" function block communicate with the rest of Process Simulate? As you might expect signals are involved.
The SCL editor allows for connecting signals to input/output variables but when does the exchange actually happen?
Well here is how it works on the high level:
The SCL script executes on a periodic basis. Once each "Logic Update Rate" interval. Each execution has three steps:
Step 1: Input variables are updated each time the script is abut to execute. e.g. signal values are copied to the proper variable.
Step 2: The script executes and eventually updates the output variables.
Step 3: Output variables are used to update the related signal values after the script executes. e.g. variable values are copied to the proper signal.
In SCL we might have variables that work as both inputs and outputs. In this case Step 1 & 3 work on the same signals.
The variable to signal association is done by means of metadata stored on the resource instance level. The metadata maps the variable identifier to the internal signal identifier.
Variable identifiers are simple GUIDs for now. You can see them in the generated code as system attributes:
Signal type is very important when doing this mapping. Therefore the type is checked before the first execution of the script. If the type does not match you'll get an error:
The type is also checked when connecting the signal to the variable but you can always change it afterwards in Signal Viewer. This is why we have the type check in place.
I hope you are still reading this.
With this simple mechanism we now can exchange data between different "main" function blocks. There is also a tool that can automate the signal connection process. e.g. "Connect Signals" command.
In SCL there is another approach to data exchange - data blocks. These are global objects visible for all functions and function blocks. This however is still not available out of the box. Hopefully one day we'll have it.
Comments