bleCharFind (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

LX2

Firmware version:

2.30.00


This function will find a characteristic on the device that matches a specific UUID.

If the device has multiple characteristics with the same UUID, this function can be called with incrementing index until it returns -9 (_BLE_ERR_NODATA).

 

Input:

dev: SYSHANDLE

Handle to the device.

 

UUID : STRING

The UUID of the characteristic to find.

Three types of UUID are supported:

16-bit: "2a06"

32-bit: "00002a06"

128-bit: "00002a06-0000-1000-8000-00805f9b34fb"

 

idx: INT(default 0)

Zero-based index of the characteristic to read.

 

service: UINT(default 0)

ID of the service to get the characteristic from. Leave at 0 to search all services.

 

Output:

char : UINT

The ID of the characteristic.

 

flags : DINT

A bit field with the flags for this characteristic.


Bit

Hex

Name

Description


2

02

Read

The characteristic can be read, see bleReadVal.


3

04

Write no response

The characteristic can be written without waiting for response, which allows for higher throughput. See bleWriteVal.


4

08

Write

The characteristic can be written and waits for the response. See bleWriteVal.


5

10

Notify

The characteristic supports notifications, which can be used to receive data whenever it is ready, e.g. when triggered by events. See bleNotifyRegister.


6

20

Indicate

The characteristic supports indications, which can be used to receive data whenever it is ready. Unlike Notify, Indicate lets the sender know that the data has been received. See bleIndicationRegister.

 

 

 

 

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

-4

-

_BLE_ERR_NOT_FOUND


Failed to find device.

-8

 

_BLE_ERR_INVAL


Invalid UUID

-9

 

_BLE_ERR_NODATA


Characteristic not found.

-20

 

_BLE_ERR_INVAL_HANDLE


Invalid handle.

-21

 

_BLE_ERR_NO_CACHE


No cache found, use bleServiceCacheUpdate to update the cache.

 

 

Declaration:

FUNCTION bleCharFind : INT;
VAR_INPUT
  dev       : SYSHANDLE;
  uuid      : STRING;
  idx       : INT  := 0;
  service   : UINT := 0;
  char      : ACCESS UINT;
  flags     : ACCESS DINT;
END_VAR;

 

Example:

...
        // Ready, try reading cache
        rc := bleServiceCacheUpdate(dev:=dev);
        DebugFmt(message:="bleServiceCacheUpdate: \1", v1:=rc);
 
        // Find wanted characteristic
 
        // Battery level characteristic
        rc := bleCharFind(dev:=dev, uuid:="00002a19-0000-1000-8000-00805f9b34fb", char:=c, flags := flags);
        DebugFmt(message:="bleCharFind: \1, Char: \2, flags: \4", v1:=rc, v2:=c, v4:=flags);
        IF rc = _BLE_OK THEN
          bat_level_id := c;
        END_IF;
        // Read from characteristic
        size:=1;
        rc := bleReadVal(dev:=dev, char:=bat_level_id, size := size, data := ADDR(bat_level));
        DebugFmt(message:="bleReadVal(\2): \1", v1:=rc, v2:=bat_level_id);
...