btIsScanning (Function)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

1.10.00

 


 

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;
// These are the local variables of the program block
VAR
   rc      : INT;
   idx     : INT;
   address : STRING;
   devInfo : btDeviceInfo;
   i       : INT;
END_VAR;
 
   rc := btPower();
   DebugFmt(message:="btPower: \1 ", v1:=rc);
   
BEGIN
   // If not scanning; List the found devices and start a new scan
   IF btIsScanning() <> 1 THEN
      rc := _BT_OK;
      idx:=1;
      WHILE rc >= _BT_OK DO
         rc := btDeviceGet(idx:=idxdev := address);
         IF rc >= _BT_OK THEN
            DebugFmt(message:="Address(\2): \1 , " + addressv1:=rcv2:=idx);
 
            devInfo(dev := address);
            DebugFmt(message:="  " + devInfo.name+" , Class: \4, type: \3, connected: \1, tx power: \2", 
               v2:=devInfo.tx_powerv4:=devInfo.clssv3:=devInfo.addr_typev1:=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 := 5transport := 1);
      DebugFmt(message:="btScanStart: \1 ", v1:=rc);
   ELSE
      Sleep(delay:=100);
   END_IF;
   
END;
 
END_PROGRAM;