btDevicePair (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400, NX-900

Firmware version:

1.10.00

 


 

This function makes the adapter start pairing with a remote device.

 

Depending on the status of the remote device, it may trigger a _BT_EVENT_PAIR_REQ event, which must be handled before the pairing is successful.

To be able to handle the event, btWaitEvent must either be called from a different thread than btDevicePair or the auto_accept parameter must be set to TRUE, which will automatically send the confirmation for the device without triggering the event.

 

If the device does not need confirmation, btDevicePair can be called from the same thread as btWaitEvent without problems.

 

The PIN code is used for legacy devices that typically requires a fixed 4-digit PIN code such as "0000" or "1234", which is described in the documentation for it.

 

Input:

dev : STRING

The address of the device to pair with.

 

auto_accept : BOOL (default FALSE)

Set to true to automatically accept the device instead of triggering the _BT_EVENT_PAIR_REQ event.

The passkey will not be made available in btHandlePairRequest and can therefore not be compared with the passkey on the remote device, which must instead just assume that it matches.

 

PIN : STRING

The PIN code to use for legacy pairing.

 

 

Returns: INT

1

-

_BT_OK


Pairing was successful

0

-

_BT_ERR_NOT_SUPPORTED


The API is not supported.

-1

-

_BT_ERR_NOT_OPEN


The adapter is not powered(see btPower).

-4

-

_BT_ERR_NOT_FOUND


Could not find device.

-10

-

_BT_ERR_ALREADY_PAIRED


Already paired.

-12

-

_BT_ERR_BUSY


The adapter is busy.

-13

-

_BT_ERR_STATE


The pairing triggers the _BT_EVENT_PAIR_REQ event, but btDevicePair is called from the same thread as btWaitEvent.

-14

-

_BT_ERR_CON_FAILED


Failed to connect to device.

-17

-

_BT_ERR_TIMEOUT


Timeout

-18

-

_BT_ERR_AUTH


Authentication failed. The remote device may have canceled or rejected the pairing.

-19

-

_BT_ERR_NOT_CONNECTED


Not connected.

 

 

 

Declaration:

FUNCTION btDevicePair : INT;
VAR_INPUT
  dev         : STRING;
  auto_accept : BOOL := FALSE;
  PIN         : STRING := "";
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc      : INT;
  address : STRING;
END_VAR;
 
// Turn on the Bluetooth library
btPower();
 
BEGIN
  ...
  // Pair to device
  rc := btDevicePair(dev:=address, pin:="0000");
  DebugFmt(message:="btDevicePair "+address+": \1 ", v1:=rc);
  ...
END;
 
END_PROGRAM;