bleNotifyRegister (Function)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

2.25.00


 

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

Notification data is used for events that do not need a response.

 

The callback can be released by calling bleNotifyRelease.

 

Input:

dev: SYSHANDLE

Handle to the device.

 

char : UINT

The ID of the characteristic.

 

func: CALLBACK

The function to call when a notification 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 notification callbacks have been registered.

-8

-

_BLE_ERR_INVAL


Characteristic does not support notification.

-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 notification.

-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 notification

 

 

Declaration:

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

Callback declaration:

FUNCTION CALLBACK bleNotifyCb : INT;
VAR_INPUT
   dev       : SYSHANDLE// Handle to device
   service   : UINT     // Service
   char      : UINT     // Characteristic
   data      : PTR;       // The notification 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 bleNotifyCb;
VAR_INPUT
   dev       : SYSHANDLE;
   service   : UINT;
   char      : UINT;
   data      : PTR;
   len       : INT;
   arg       : DINT;
END_VAR;
VAR
   str     : STRING;
END_VAR;
   str:=strFromMemory(src:=datalen:=len);
   DebugFmt(message:="\1.\2: "+strv1:=servicev2:=char);
END_FUNCTION;
 
...
// Register callback to show notifications for characteristic 10
rc := bleNotifyRegister(dev := devchar := 10func:=@bleNotifyCb);
...