As we already know SCL scripts in Process Simulate are placed in the SCL Vault folder. Currently FBs, FCs and UDTs are supported. But how do you consume them? Don't worry. It is easier than you think.
Once the script is in the Vault Process Simulate recognizes it and makes it available in the SCL Editor.
Function Blocks and User Defined Types appear as data types when you declare a variable. The variable contains the FB/UDT instance. Functions can be used directly in your main script (the script that you code inside the SCL Editor) as well as any other script that you use. I'll give an example:
Use case 1: Calling a FB
Imagine you have a script defining a FB:
FUNCTION_BLOCK "FOO"
VAR_INPUT
IN:BOOL;
END_VAR
VAR_OUTPUT
OUT:BOOL;
END_VAR
BEGIN
...
END_FUNCTION_BLOCK
Then in your main script you can declare a variable of type "FOO":
VAR
foo:"FOO"; // static variable
END_VAR
The variable is like any other. Only the name of the type is different. Notice the quotes? Yes. They denote a custom type.
To call the FB simply do something like this:
#foo(IN:=True, OUT=>#out); // call the FB
This triggers the execution of the FB so the logic inside will be executed. Inputs are given at this point. Eventually you'll get the expected result as output argument before the FB call returns. Another way to consume the output is this:
#foo(IN:=True); // call the FB
Arguments names might differ in your case but the syntax is the same.
Function blocks have state inside so they should be consumed as static variables in the upper script. This is important to remember!
The call to the FB is synchronous. The upper script blocks until the subscript returns.
Use case 2: Calling a Function
Imagine you have a script defining a FC:
FUNCTION "BAR" : BOOL
VAR_INPUT
IN:BOOL;
END_VAR
VAR_OUTPUT
OUT:BOOL;
END_VAR
BEGIN
...
END_FUNCTION
Then in your main script you can simply call it:
"BAR"(IN:=True, OUT=>#out); // call the FC
The syntax is similar to the one of the FB right. Here however we don't have a variable involved since the function does not have any state inside. It is by definition stateless. The call is again synchronous.
Use case 3: Using a UDT
Imagine you have a script defining a UDT:
TYPE "DATA"
STRUCT
FIELD1:BOOL;
FIELD2:BOOL;
...
END_TYPE
Then in your main script you can declare a variable of type "DATA":
VAR_INPUT
data:"DATA";
END_VAR
Unlike the FB you can use any type of variable here. Static or not it will work.
Then in your main script you can simply use it:
#data.FIELD1 := True;
UDTs can be also nested. Just don't nest them recursively ... this won't fly ...
Comentários