bleIndicationRegister (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

LX2

Firmware version:

2.20.00


 

This function registers a callback function to handle indication data for a characteristic.

Indication data is used for events that requires confirmation that the data has been received.

This confirmation is sent when the callback returns.

The callback can be released by calling bleIndicationRelease.

 

Input:

dev: SYSHANDLE

Handle to the device.

 

char : UINT

The ID of the characteristic.

 

func: CALLBACK

The function to call when an indication is received. See the callback declaration below.

 

arg: DINT

User argument to pass on to the callback.

 

Returns: INT

1

-

_BLE_OK


Success

0

-

_BLE_ERR_NOT_SUPPORTED


The API is not supported.

-1

-

_BLE_ERR_NOT_OPEN


The interface is not powered(see blePower).

-7

 

_BLE_ERR_NO_RES


Too many indication callbacks have been registered.

-8

-

_BLE_ERR_INVAL


Characteristic does not support indications.

-9

-

_BLE_ERR_NODATA


Characteristic not found

-13

 

_BLE_ERR_STATE


Not allowed to read at this time.

-19

-

_BLE_ERR_NOT_CONNECTED


Device is not connected.

-17

 

_BLE_ERR_TIMEOUT


Timed out when trying to enable indications.

-20

-

_BLE_ERR_INVAL_HANDLE


Invalid handle.

-21

-

_BLE_ERR_NO_CACHE


No cache found, use bleServiceCacheUpdate to update the cache.

-99

-

_BLE_ERR_GENERIC


Failed to enable indications

 

 

Declaration:

FUNCTION bleIndicationRegister : INT;
VAR_INPUT
  dev    : SYSHANDLE;
  char   : INT;
  func   : CALLBACK;
  arg    : DINT;
END_VAR;
 

Callback declaration:

FUNCTION CALLBACK bleIndicationCb : INT;
VAR_INPUT
  dev       : SYSHANDLE; // Handle to device
  service   : UINT;     // Service
  char      : UINT;     // Characteristic
  data      : PTR;       // The indication data. This pointer may not be used outside the callback.
  len       : INT;       // The size of the data.
  arg       : DINT;      // The user argument.
END_VAR;

 

 

 

 

Example:

FUNCTION CALLBACK bleIndicationCb;
VAR_INPUT
  dev       : SYSHANDLE;
  service   : UINT;
  char      : UINT;
  data      : PTR;
  len       : INT;
  arg       : DINT;
END_VAR;
VAR
  str     : STRING;
END_VAR;
  str:=strFromMemory(src:=data, len:=len);
  DebugFmt(message:="\1.\2: "+str, v1:=service, v2:=char);
END_FUNCTION;
 
...
// Register callback to show indications for characteristic 10
rc := bleIndicationRegister(dev := dev, char := 10, func:=@bleIndicationCb);
...