FB_BACnet_Program

The following function block is used for linking a BACnet object of the local BACnet server. The function block for the corresponding BACnet object is linked with the aid of process data.

The process data can be created manually in the BACnet object, linked manually, or they can be generated automatically via PLC automapping. The comments required for PLC automapping ( (* ~ (BACnet... | ??? | ??? ) *) ) are already included in the declaration of the function block.

FB_BACnet_Program 1:

Use

The function block "FB_BACnet_Program" provides the object functionality for the BACnet stack. To this end the BACnet object was created under a local BACnet server. The BACnet object on the BACnet stack side serves as interface to the BACnet world. The processing of the BACnet object is provided by the PLC instance of the block FB_BACnet_Program.

This approach has the advantage that existing, customer-specific PLC functions can easily be linked with the BACnet world. In this way, procedures that are implemented in PLC code can be triggered with the aid of the handshake interface (stDoneFlags, stFailedFlags and stRequestFlags) of the FB "FB_BACnet_Program".

The function block "FB_BACnet_Program" contains the state transitions described in the BACnet specification and maps them to the FB interface using the structures: stDoneFlags, stFailedFlags and stRequestFlags (see below Transition diagram Fig. 2).

FB_BACnet_Program 2:
Fig. 1: Example of a BACnet program object under a local BACnet server.

VAR_INPUT

bRelease           : BOOL;
bCommonError       : BOOL;
bWaitForSomething  : BOOL;
stDoneFlags        : ST_BACnet_ProgramHandshakeRequests;
stFailedFlags      : ST_BACnet_ProgramHandshakeRequests;
bModeUnloadComplex : BOOL := TRUE;

bRelease: Enables processing of requests. If bRelease = FALSE is set, the program waits in state HALTED.

bCommonError: Error during execution of aProgram_Change requests from the structure stRequestFlags. Setting the input while a Program_Change requests is running leads to an abort condition (see Transition diagram Fig. 2).

bWaitForSomething: If the BACnet object is in state RUNNING, setting the input to TRUE switches to state WAITING, so that the BACnet object is blocked for further requests except Unload and Halt (see Transition diagram Fig. 2).
To return to state RUNNING set the input back to FALSE.

stDoneFlags: The flags within the input structure are used to acknowledge pending Program_Change requests from the output structure stRequestFlags. A signal change of one of the flags from FALSE to TRUE acknowledges execution of the corresponding Program_Change request.

stFailedFlags: The flags within the input structure are used to report cancellation of the pending Program_Change request from the output structure stRequestFlags. A signal change of one of the flags from FALSE to TRUE cancels execution of the corresponding Program_Change request.

bModeUnloadComplex: If the mode "Unload Complex" was activated via the input, the BACnet object status changes from UNLOADING to IDLE once the request Unload has been executed (see Transition diagram Fig. 2). If the input is set to FALSE, the BACnet object remains in state UNLOADING after the request Unload has been executed.

VAR_OUTPUT

bReady             : BOOL;
bOverridden        : BOOL;
bOutOfService      : BOOL;
bFault             : BOOL;
bInAlarm           : BOOL;
bProcessError      : BOOL;
bOtherFault        : BOOL;
stRequestFlags     : ST_BACnet_ProgramHandshakeRequests;
stActiveStateFlags : ST_BACnet_ProgramHandshakeStates;
bError             : BOOL;
nErrorId           : UINT;

bReady: Notification of general readiness. If this output is set, the other status outputs are valid (ActiveStateFlags, Overridden ...). If the output is FALSE, the corresponding function block "FB_BACnet_Device" does not report "Operational", or the block instance was not linked correctly in the System Manager.

bOverridden, bOutOfService, bFault, bInAlarm: See BACnet specification DIN EN ISO 16484-5 for BACnet object Program and property Status_Flags.

bProcessError, bOtherFault: See BACnet specification DIN EN ISO 16484-5 for BACnet object Program and property Reliability.

stRequestFlags: Contains the flags for the corresponding Program_Change requests. If a flag is set to TRUE, a change in status of the program object is requested by the PLC program. If the change was successful, this is acknowledged with a signal change from FALSE to TRUE of the corresponding flags in the input structure stDoneFlags. If the corresponding PLC program is unable to execute the request or if the process is aborted, this must be reported via the corresponding flag in the input structure stFailedFlags. The termination is then shown in the status of the BACnet object.

stActiveStateFlags: Contains flags that reflect the current state of the BACnet program object (see Transition diagram Fig. 2).

bError: An error is pending.

nErrorId: Error number
0 = no error
2 = incorrect process data mapping detected (check mapping in the System Manager; if necessary compile complete PLC project and reload)
3 = the corresponding BACnet server is not ready (bOperational = FALSE at instance of the FB_BACnet_Device)
The error numbers can be queried as block constants via the FB instance (FB_BACnet_???.nERR_xxx).

VAR_IN_OUT

Device       : FB_BACnet_Device;

Device: Specification of the instance of the local corresponding BACnet server block. For each BACnet adapter one BACnet server is possible. See FB_BACnet_Adapter and FB_BACnet_Device for further information.

Transition diagram

FB_BACnet_Program 3:
Fig. 2: from BACnet specification DIN EN ISO 16484-5 for BACnet object Program, Fig. 12-3 "State Transitions for the program object"