Hello, everyone.
Let's see how to create a basic function block.
In the Solution Overview of EcoStruxure Automation Expert,
click on your solution name to open the node.
Right click on Basic ...
... and select New Item.
Enter the name of the block you want to create ...
... and click on OK.
In our case, we want to implement a mathematical add operation.
By default, an interface is created.
Let's modify it by removing the INIT event.
Rename the event REQ by event_IN.
This will be the event triggered to do the sum.
Delete also the event INITO ...
... and rename the event CNF by event_OUT.
This event will fire out when the algorithm is done.
Then create two input variables ...
... IN1 and IN2 ...
... with the type, REAL ...
... and an output variable OUT with the same type.
As you can see in the depiction of the function block,
the variable IN2 isn’t linked with any event.
To do this, we need to click in the event area via the With column ...
... and left click on this button.
A wizard opens ...
... and here you can check the variables you want to link.
Here is a little tip:
you can also hold down the left mouse key,
drag the input variable to the corresponding input event,
and release the mouse key.
Next on the Execution Control Chart tab,
we need to modify the state diagram.
Start by deleting all the existing states.
Right click and select New State.
Hold down left click on state START ...
... and drag to the new state, STATE1.
Do the same in the other direction,
from STATE1 to START.
Like a state machine,
you just created the conditions of transition.
Double click on the transition and type the condition.
We need to create the algorithm that will be executed.
Right click on STATE1 and select Add Action.
You can add multiple actions.
Two squares appear.
Right click on the gray square and select New Algorithm.
Enter the name of the algorithm,
check the box Associate with current action ...
... and click on OK.
Right click on the pink square and select event_OUT,
which will be the event triggered at the end of the algorithm.
Go in the Algorithm tab,
... right click in the algorithm INIT ...
... and select Delete algorithm in order to delete the default ones.
Do the same with the REQ algorithm.
On the algorithm SUM,
write the code in Structured Text.
So, the variable OUT take the sum of IN1 and IN2.
Save and test your basic function block ...
... using the debugger tool, Test Container.
In the Debug tab, click on Run.
Then, enter the constants in each input and trigger an event.
As you can see, the variable OUT gives the result ...
... and the event_OUT is triggered.
That's it!
Now you know how to create a basic function block.