This function checks if the adapter is scanning for other devices.
Input:
None.
Returns: INT
1
|
-
|
|
|
The adapter is scanning.
|
0
|
-
|
_BT_ERR_NOT_SUPPORTED
|
|
The adapter is not scanning or the API is not supported.
|
-1
|
-
|
_BT_ERR_NOT_OPEN
|
|
The adapter is not powered(see btPower).
|
-5
|
-
|
_BT_ERR_NO_ADAP
|
|
Could not find adapter.
|
Declaration:
FUNCTION btIsScanning : INT;
Example:
INCLUDE rtcu.inc
PROGRAM test;
VAR
rc : INT;
idx : INT;
address : STRING;
devInfo : btDeviceInfo;
i : INT;
END_VAR;
rc := btPower();
DebugFmt(message:="btPower: \1 ", v1:=rc);
BEGIN
IF btIsScanning() <> 1 THEN
rc := _BT_OK;
idx:=1;
WHILE rc >= _BT_OK DO
rc := btDeviceGet(idx:=idx, dev := address);
IF rc >= _BT_OK THEN
DebugFmt(message:="Address(\2): \1 , " + address, v1:=rc, v2:=idx);
devInfo(dev := address);
DebugFmt(message:=" " + devInfo.name+" , Class: \4, type: \3, connected: \1, tx power: \2",
v2:=devInfo.tx_power, v4:=devInfo.clss, v3:=devInfo.addr_type, v1:=SINT(devInfo.connected));
DebugFmt(message:=" status: \1, paired: \2, trusted: \3", v1:=devInfo.status,
v2:=INT(devInfo.paired), v3:=INT(devInfo.trusted));
DebugFmt(message:=" Profiles: \1", v1:=devInfo.profiles);
FOR i:= 1 TO 16 DO
IF devInfo.uuid[i] <> "" THEN
DebugFmt(message:=" [\1]: " + devInfo.uuid[i], v1:=i);
END_IF;
END_FOR;
END_IF;
idx := idx+1;
END_WHILE;
DebugFmt(message:="btDeviceGet: \1 ", v1:=rc);
rc := btScanStart(timeout := 5, transport := 1);
DebugFmt(message:="btScanStart: \1 ", v1:=rc);
ELSE
Sleep(delay:=100);
END_IF;
END;
END_PROGRAM;
|