Calling a function block method in Structured Text is very simple, but users may occasionally need to call a method in Continuous Function Chart (CFC). The procedure for doing this is not readily apparent to new users and is covered here.
First, make sure that you have created an instance of the function block whose method you are going to call. You can do this in the Declaration Editor of your CFC program. The function block can be one that you create or one from a library.
Next, add a box element to your CFC chart. Give it a type using the format <function-block-name>.<method-name>. Then, give it the same name as your function block instance.
Notice that type for this CFC element (the bold text inside the blue box) is myFunctionBlock.myMethod. The name of the element is FB_Instance1, which is the same name that we gave to the function block in the Declaration Editor.
By default, the method will execute every single time the CFC chart is scanned. However, there is a way to change this behavior and make it so that the method only executes when a variable input evalutates TRUE. Right-click on the method and click EN/ENO.
Your CFC method call will now look like the one shown below. You can use a boolean variable or expression tied to EN to control whether the method is actually called in the scan.
If you want the behavior of the method to be edge-triggered, you can add an R_TRIG function block to the CFC chart.
NOTE: You can add EN/ENO pins to any CFC box element.
You can also auto-declare a function block when adding a CFC element to call a method. Steps are shown below.
Add a new box element to your CFC chart.
Give the box a type corresponding to the function block method you want to call. Use the format <function-block-name>.<method-name>.
Give the function block a name. Make sure that the name is not one you have already used. Then, press Enter.
The standard Auto Declare dialog will appear, allowing you to confirm the function block you want to use, where you want to declare it and what (if any) initialization parameters you want it to use. Most people leave all of these options at their defaults and change them later in the Declaration Editor if necessary. When finished, press OK.
You will now see that your Declaration Editor has been updated and displays the function block you declared. There is also a method call in your CFC chart. In this image, there is a red underline in the method call because none of the inputs are populated. You will need to supply data to every input since methods do not have optional arguments.
pac cfc function block method expression expected syntax