Reference an ST Library or Function Block Library in an ST Program
To reference an ST Library or Function Block Library in an ST program, you need to enable the Libraries and then define them as variables in the code. There is no need to define the function block with FUNCTION_BLOCK...END_FUNCTION_BLOCK.
As with referencing libraries in a Logic diagram, you can only reference those libraries that you enable via the Libraries window.
To reference an ST Library or Function Block Library in an ST Program:
- Display the ST program in Design mode.
- Select the Logic tab on the ViewX ribbon.
- Select Libraries in the Library command group to display the Libraries window.
- Select the check boxes for the libraries that you want to use in the ST program and clear the check boxes for those libraries that are not required.
- Select the OK button to confirm your selection and close the Libraries window.
- Edit the code for the ST program.
You need to include the user function block (that is defined in one of the Libraries) in a VAR...END_VAR definition. The VAR definition needs to use the following format:
- VAR
- <Variable name>: <Name of library>;
- END_VAR
Where <Variable name> is the name that you will use to reference the user function block within the ST code of the program you are editing.
<Name of library> is the name of the user function block that you defined in the ST Library or Function Block Library (this is the same name as the ST Library or Function Block Library).
Do not enter the angle brackets < >. We use the angle brackets to indicate that the name is dependent on the entries you have made.
When you have defined the variables, you can use expressions to define the values and Logic for the program (see ST Programs).
- VAR
- Save the ST program.
Example:
If you are referencing an ST Library named 'Celsius_To_Fahrenheit' then the ST program code could be:
- PROGRAM Celsius_To_Fahrenheit_Conversion
- VAR
- TempC :LREAL:=20.0;
- TempF:LREAL;
- END_VAR
- VAR
- C_TO_F: Celsius_To_Fahrenheit;
- END_VAR
- C_TO_F(Celsius := TempC,Fahrenheit => TempF);
- END_PROGRAM