btleConnect (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400, NX-900

Firmware version:

1.10.00

 


 

This function connects to a Bluetooth Low Energy(BLE) device. This is needed to be able to read the characteristics and services of the device.

 

 

Input:

dev : STRING

The address of the device to connect to.

 

 

Returns: INT

1

-

_BT_OK


Success.

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.

-7

-

_BT_ERR_NO_RES


Could not allocate resources for connection.

-12

-

_BT_ERR_BUSY


The adapter is busy.

-14

-

_BT_ERR_CON_FAILED


The connection failed to be established.

-15

-

_BT_ERR_NOT_AVAIL


The device does not support BLE connections.

-17

 

_BT_ERR_TIMEOUT


Timeout

 

 

 

Declaration:

FUNCTION btleConnect : INT;
VAR_INPUT
  dev      : STRING;
END_VAR;

 

Example:

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