Creating a User Function Block
Step | Action |
---|---|
1 | Create or Open your project. |
2 |
In the Project window panel locate the User Function/Function Block section.
|
3 | Right-click on the User Function/Function Block section. Select Add Itemè Function Block… |
4 |
Enter in information for your function block in the window that pops up.
Give your function block a descriptive name.
Choose the language of the function block’s code.
Choices:
Select or de-select the Use EN/ENO option.
Choose a value for Width (Columns).
Add a Program Description to let other users know what the function block does.
|
5 |
Select Password tab to add security options to your Function Block. Using the password functions is optional.
Use New Password section to password protect your function block. This step is optional.
Enable or disable Protect Program check box. This step is optional.
|
6 |
Open the Local Variables file for your function block.
|
7 |
Add Local Variables to your function block. Choose Variable Kind for your local variable.
Variable Kind Definitions:
Enter a name for your variable in the Variablecolumn.
Choose the data type of your variable in the Type column.
Available data types:
If using a BOOL variable of VAR_INPUT kind, select if an edge trigger is needed
Trigger Options:
.Pay attention to the address column for memory address usage.
Note: Grouping BOOL variables together can save on memory address usage. If using a VAR or VAR_CONSTANT type variable, you can setup an initial value for the variable. This will set it to that value on first function block call.
Note: When using a variable of VAR_CONSTANT type, the Initial Value is the constant value of the variable. It needs to be set to the appropriate value. Retain check box will be grayed out for Function Blocks. Used check box is checked if variable is used in the code.
Add a Comment to the variable to let other users know what the variable is used for.
|
8 |
Open Function Block Program to add code.
The chosen language editor will appear. This example is Structured Text.
|
9 |
After adding Function block code, press Check Program to check your function block for errors.
|
10 |
Fix any errors that appear or proceed to Using a User Function Block to start using your function block.
|
LP306A