The Function Block (FB) is just a function associated with some data. The data is stored in a Data Block (DB). In Process Simulate we simplify this a bit and skip the DB definition. Memory management is handled automatically and the user only has to define the FB itself. So lets see how this is achieved in terms of SCL syntax.
Example:
The FB definition starts with the FUNCTION_BLOCK keyword followed by the quoted FB name. The FB name is used as an identifier of the block. It can be used to reference the FB from other FBs. Optional Block/System attributes can be assigned to to the FB after the name.
Attributes provide FB metadata.
Example:
KEY : VALUE // block attribute
{ KEY := 'VALUE' } // system attribute
The keys for block attributes are well-defined in the SCL grammar where as the keys for system attributes can be user defined.
The data for the FB is defined in terms of variables. Each variable has a well-known data type and is assigned a specific purpose. With regards to the purpose there are different types of variables:
a) Input variables - these are the arguments for the FB. Callers provide values to these before calling the FB instance.
Example:
VAR_INPUT IN:BOOL; END_VAR
b) Output variables - these are the result of the calculations within the FB. Callers consume them after calling the FB instance.
Example:
VAR_OUTPUT OUT:BOOL; END_VAR
c) Input/output variables - these are bi-directional variables that serve both purposes.
Example:
VAR_IN_OUT
IO:BOOL;
END_VAR
d) Static variables - the values of these variables are preserved between FB executions. FB instances are usually put here to preserve their internal state during the whole simulation.
Example:
VAR COUNTER:DINT; END_VAR
e) Temporary variables - these act like local variables for the current FB execution. Allocated/deallocated before/after each execution.
Example:
VAR_TEMP T:DINT; END_VAR
f) Constants- the values of these variables cannot be changed once defined.
Example:
VAR CONSTANT PI:REAL := 3.14; END_VAR
Variables can also have system attributes. These are just metadata key-value pairs associated with the variable.
Example:
DRIVE_TEL_1 { ID:=’5’; BlockType := 'SCL'; } : "SIM_DRIVE_TEL_1";
So to summarize: Variables are used to define the public interface of the FB as well as its internal state. The logic part of the FB starts with the BEGIN keyword followed by a number of language statements. The sum of all statements inside the FB define its behavior.
Variables can be referenced in a statement or an expression via the # symbol.
Example:
BEGIN
The FB definition ends with the END_FUNCTION_BLOCK keyword.
Commentaires