Beispiel
Der folgende Code zeigt, wie die Funktion der dynamischen Erzeugung/Löschung genutzt werden kann.
Variablen:
PROGRAM DYN_OBJECTS
VAR
fbDynObject : FB_BACnet_DynObjectManager := (bCycleObjects := TRUE);
bCreate : BOOL;
bDelete : BOOL;
DynView : POINTER TO FB_BACnet_View;
DynAV01 : POINTER TO FB_BACnet_AV;
DynBV01 : POINTER TO FB_BACnet_BV;
nCounter : UDINT;
END_VAR
Code:
// Management FB has to be called in every cycle
fbDynObject();
IF (fbDynObject.Ready) THEN
IF (bCreate) THEN
bCreate := FALSE;
// [Variant 1] Create standard object types:
IF (fbDynObject.CreateObject(
DynView,
E_BACnet_CreateObjType.eStructuredView,
BACnet_Globals.nBACnetInstId_Auto,
'DynView',
'Dynamic View',
0))
THEN
// [Optional] set object properties...
END_IF
IF (fbDynObject.CreateObject(
DynAV01,
E_BACnet_CreateObjType.eAnalogValue,
BACnet_Globals.nBACnetInstId_Auto,
'\/DynAV01',
'\/Dynamic AV 1',
DynView))
THEN
// [Optional] set object properties...
DynAV01^.eUnit := E_BA_Unit.eTemperature_DegreesCelsius;
END_IF
IF (fbDynObject.CreateObject(
DynBV01,
E_BACnet_CreateObjType.eBinaryValue,
BACnet_Globals.nBACnetInstId_Auto,
'\/DynBV01',
'\/Dynamic BV 1',
DynView))
THEN
// [Optional] set object properties...
DynBV01^.sInactiveText := 'Off';
DynBV01^.sActiveText := 'On';
END_IF
END_IF
IF (bDelete) THEN
bDelete := FALSE;
// [Variant 1] Delete all objects conveniently via object manager:
fbDynObject.Reset();
// [Variant 2] Delete all objects manually:
(*
fbDynObject.DeleteObject(DynAV01);
fbDynObject.DeleteObject(DynBV01);
fbDynObject.DeleteObject(DynView);
*)
END_IF
// Sample PLC code:
// > Take care of valid object pointers!
IF (fbDynObject.CreatedObjects > 0) THEN
nCounter := (nCounter+1);
// Simulate changing value:
DynAV01^.bEnPgm := TRUE;
DynAV01^.fValPgm := (TO_REAL(nCounter MOD 1000)/100);
// [Variant 2] Call created objects manually
IF (NOT fbDynObject.bCycleObjects) THEN
DynView^();
DynAV01^();
DynBV01^();
END_IF
END_IF
END_IF