btSearch (Function)

Top  Previous  Next

Architecture:

X32 / NX32

Device support:

MX2 pro, DX4 pro, AX9 pro, MX2 turbo/encore/warp, AX9 turbo

Firmware version:

1.05


This searches for Bluetooth devices in the area. All devices found in the search are assigned a device number, which is the reference when using library functions such as btConnect or btGetDeviceName etc. The function will return the number of devices found in the search. A found device is not necessarily assigned the same number in each search - use btGetDeviceName, btGetDeviceType, or btGetDeviceAddress to determine which device number to connect to.

 

Input:

None

 

Returns: INT

Number of devices found in the search.

-1

- Bluetooth library is not open.

-3

- Bluetooth module is not present.

 

Declaration:

FUNCTION btSearch : INT;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc        : INT;
  i         : INT;
  headsetID : INT;
END_VAR;
 
// Open the Bluetooth library
btOpen(name := "RTCU MX2");
 
BEGIN
  ...
  DebugMsg(message:="Starting search....");
  rc:=btSearch();
  DebugFmt(message:="   btSearch=\1", v1:=rc);
  FOR i:=1 TO rc DO
    DebugMsg(message:="   ("+intToStr(v:=i)+") Addr="+btGetDeviceAddress(device:=i)+" Type="+dintToStr(v:=btGetDeviceType(device:=i))+" name="+btGetDeviceName(device:=i));
    IF btGetDeviceName(device:=i) = "Motorola H300" THEN
        headsetID:=i;
        DebugMsg(message:="   Motorola H300 found at device ->"+intToStr(v:=i));
    END_IF;
  END_FOR;
 
  ...
END;
 
END_PROGRAM;