Programming in the CFC Editor
Note
You commit to the implementation language when creating the POU. Afterwards, it is not possible to switch between the Continuous Function Chart (CFC) and Continuous Function Chart (CFC) - page-oriented implementation languages.
Inserting elements and wiring with connecting lines
Drag a Box element and an Output element into the editor.
Click the output of the Box element.
The output is marked with a red box.
Drag a connecting line from the output pin of the Box element to the input pin of the Output element.
The cursor symbol changes when it reaches the input pin.
Release the left mouse button.
The output pin of the box is wired to the input pin of the output.
You can also hold down the Ctrl key, select each pin, and then right-click Connected Selected Pins.
Calling of instances
Create a new project using the standard template and specify the name
First
for example.The project
First.project
is created.Extend the application with the function block
FB_DoIt
in the ST implementation language with inputs and outputs.Example:
FUNCTION_BLOCK FB_DoIt VAR_INPUT iAlfa : INT; iBravo: INT; sCharlie : STRING := 'Charlie'; xItem : BOOL; END_VAR VAR_OUTPUT iResult : INT; sResult : STRING; xResult : BOOL; END_VAR VAR END_VAR iResult := iAlfa + iBravo; IF xItem = TRUE THEN xResult := TRUE; END_IF
Select the application and click Add Object → POU. Select the Continuous Function Chart (CFC) implementation language and the type
Program
. Specify the namePrgFirst
for example.Click OK to confirm the dialog.
The
PrgFirst
program is created and it opens in the editor. It is still empty.Instantiate function blocks and declare variables.
PROGRAM PrgFirst VAR iCounter: INT; fbDoIt_1 : FB_DoIt; fbDoIt_2 : FB_DoIt; iOut : INT; sOut: STRING; xOut: BOOL; END_VAR
Drag a Box element from the Toolbox view into the editor.
Click the
???
field and type inADD
as the box name.The box type is
ADD
. The box acts as an adder.Click line 3 in the declaration editor.
The declaration line of
iCounter
is selected.Click in the selection and drag the selected variable into the implementation. Focus there on an input of the
ADD
box.An input has been created, declared, and connected to the box.
Click again in the selection and drag the variable to the output of the
ADD
box.An output has been created, declared, and connected to the box.
Drag an Input element from the Toolbox view to the implementation. Click its
???
field and type in1
.Connect the
1
input to an input of theADD
box.A network is programmed. At runtime, the network counts the bus cycles and stores the result in
iCounter
.Click line 5 in the declaration editor.
The line is selected.
Click in the selection and drag the selected instance into the implementation.
The instance appears as a box in the editor. The type, name, and box pins are displayed accordingly.
Drag the
fbDoIt_2
instance to the editor. Interconnect the instances to each other and to inputs and outputs.Example:
A program in ST with the same functionality might look like this:
PROGRAM PrgFirstInSt VAR iCounter: INT; fbDoIt_1 : FB_DoIt; fbDoIt_2 : FB_DoIt; iOut : INT; sOut: STRING; xOut: BOOL; END_VAR iCounter := iCounter + 1; fbDoIt_1(iAlfa := 16, iBravo := 32, sCharlie := 'First', xItem := TRUE, iDelta := 2, iResult => fbDoIt_2.iAlfa, xResult => fbDoIt_2.xItem); fbDoIt_2(iBravo := fbDoIt_1.iResult, sCharlie := 'Second', iDelta := 2, iResult => iOut , sResult=> sOut, xResult => xOut);
Creating connection marks
Requirement: A CFC POU has connected elements.
Select a connecting line between two elements.
The connecting line is displayed as selected. The ends of the connecting line are marked with
red boxes.
Click CFC → Connection Mark.
The connection is separated into a Connection Mark – Source and a Connection Mark – Sink. The name of the mark is generated automatically.
Click in the source connection marks.
You can edit the name.
Specify the name
SimpleMark
for the source connection mark.The source connection mark and sink connection mark have the same name.
Resolving collisions and fixing connecting lines by means of control points
The following example shows how to use the Route All Connections command with control points.
Position the Input and Output elements. Connect the elements.
Position two Box elements on the line.
The connecting line and the boxes are marked red because of the collision.
Click CFC → Routing → Route All Connections.
The collision is resolved.
Change the connecting lines gradually.
The connecting line has been changed manually and is now blocked for auto-routing. This is shown by a lock symbol at the end of the connection.
Select the connecting line and click CFC → Routing → Create Control Point.
A control point is created on the connecting line. The connecting line is fixed to the control point.
You can also drag a control point from the Toolbox view to a line.
Change the connecting line as seen in the following example.
Use the control point for changing the connecting line according to your needs. You can set any number of control points.
In the context menu, click CFC → Routing → Remove Control Point to remove the control point.
Click Unlock Connection or click the lock symbol to unlock the connection.
Select the connecting line and click Route All Connections.
The connecting line is routed automatically as seen in Step 3.
Important
Connections in a group are not auto-routed.
Reducing the display of a box
Requirement: A CFC POU is open. In the editor, its boxes with all declared pins are displayed.
Select a box whose pins are partially disconnected.
Example:
fb_DoIt_1
The box needs space for all of the pins.
Click CFC → Pins → Remove Unused Pins.
Now the box needs less space and is displayed only with the functionally relevant pins.