The FB Code window

This window displays the code generated from the object information of the selected device in structured text (ST).

This window is divided into three sections.

The (* Usage *) section shows how to create instances of this function block and adds a TcLinkTo... attribute in the case of MS/TP

Sample:

{attribute 'TcLinkTo' := '.BACnet_AmsNetId := TIID^Device 3 BACnet MSTP)^Inputs^AmsNetId'}
fbMstpDevice_3 : FB_BACnet_Adapter;
fb_101_Novos_Touch_BACnet_MSTP : FB_BACnet_101_Novos_Touch_BACnet_MSTP :=(Client:=(Adapter := fbMstpDevice_3, nDeviceInstance := 101));

The (* Declaration *) section shows the variables of the function blocks used.

Sample:

FUNCTION_BLOCK FB_BACnet_101_Novos_Touch_BACnet_MSTP
VAR_INPUT CONSTANT
    Client : FB_BACnet_Client:=
            (tReadCycleTime:=T#2S550ms,tWriteCycleTime:=T#2S550ms);
    _101_Novos_Touch_BACnet_MSTP: FB_BACnetRM_Device:=
            (Client:=Client);
    Internal_Fan_Stage: FB_BACnetRM_MI :=
            (Client:=Client,nObjectInstance:=104);
    ECO_Colour: FB_BACnetRM_MV :=
            (Client:=Client,nObjectInstance:=102);
    External_Fan_Stage: FB_BACnetRM_MV :=
            (Client:=Client,nObjectInstance:=105);
END_VAR

The (* Code *) section shows the instance calls of the function blocks.

Sample:

Client();
_101_Novos_Touch_BACnet_MSTP();
Internal_Fan_Stage();
ECO_Colour();
External_Fan_Stage();

The footer of this dialog contains a switch that influences the code generation. It is possible to generate the code for BACnet revision 12 using the automapping comments or for BACnet revision 14 using the PLC code.

The FB Code window 1:

Selecting Create in PLC starts the code generation. After successful creation, a message is displayed in the footer. Click Close to close the dialog and return to the TwinCAT System Manager.

The FB Code window 2:

After this step it is only necessary to place the function block call (e.g. in the POU MAIN) as shown above.

The FB Code window 3:

The contents of the FB Code window can also be copied to the clipboard for further editing.