Scanning other BACnet devices
In some cases it is necessary to scan the BACnet network (e. g. from a visualization) to identify external BACnet devices. The FB_BACnet_Adapter provides two methods to start a scan process:
StartScan
StartScanEx
Calling one of these functions generates a BACnet Who-Is request to the network. All devices receiving this request and matching the request parameters shall respond using the I-Am service. The result of this scan process can be retrieved using the FB_BACnet_Adapter method GetScanResult after waiting an appropriate time.
GetScanResult returns the number of external devices found on the network, regardless of the buffer size to store the results. In case of an error this function returns -1.
Example scanning for other BACnet devices:
VAR
fbDevice : FB_BACnet_Device;
a_stScanResult : ARRAY[0..MAX_SCANRESULTS] OF ST_BACnetRM_ScanResult;
bSuccessScan : BOOL;
bScan : BOOL;
fbWaitTimer : TON;
nScanResult : DINT;
END_VAR
VAR CONSTANT
MAX_SCANRESULTS : UDINT := 200;
tWaitTime : TIME := T#5S;
END_VAR
------------------------------------------------------------------
fbDevice();
fbWaitTimer( IN := NOT fbWaitTimer.Q, PT := tWaitTime );
IF bScan THEN
bScan := FALSE;
nScanResult := -1;
bSuccessScan := BACnet_Globals.DefaultAdapter.StartScan();
END_IF
IF bSuccessScan AND fbWaitTimer.Q THEN
bSuccessScan := FALSE;
nScanResult := BACnet_Globals.DefaultAdapter.GetScanResult( ADR( a_stScanResult ), MAX_SCANRESULTS );
END_IF