bleCharGet (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

LX2

Firmware version:

2.25.00


This function will retrieve a characteristic from the device.

To list all the known characteristics, keep calling this function with incrementing index until it returns -9 (_BLE_ERR_NODATA).

 

 

Input:

dev: SYSHANDLE

Handle to the device.

 

idx: INT

Zero-based index of the characteristic to read.

 

service: INT

ID of the service to get the characteristic from.

 

Output:

char : INT

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.

 

 

UUID : STRING

The UUID of this characteristic.

 

 

 

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.

-9

 

_BLE_ERR_NODATA


Service 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 bleCharGet : INT;
VAR_INPUT
  dev       : SYSHANDLE;
  idx       : INT;
  service   : UINT;
  char      : ACCESS UINT;
  flags     : ACCESS DINT;
  uuid      : ACCESS STRING;
END_VAR;

 

Example:

FUNCTION ShowServices;
VAR_INPUT
  dev     : SYSHANDLE;
END_VAR;
VAR
  i, j    : INT;
  s, c    : UINT;
  rc, rc2 : INT;
  uuid    : STRING;
  primary : BOOL;
  flags   : DINT;
END_VAR;  
  DebugMsg(message := "-- Services: --");
  i := 0;
  REPEAT
    rc := bleServiceGet(dev := dev, idx := i, service := s, uuid := uuid, primary := primary);
    IF rc = 1 THEN
        DebugFmt(message := "  Service: \1, primary: \2, UUID: " + UUID, v1 := s, v2 := INT(primary));
        j := 0;
        REPEAT
          rc2 := bleCharGet(dev := dev, service := s, idx := j, char := c, uuid := uuid, flags := flags);
          IF rc2 = 1 THEN
              DebugFmt(message := "    Char: \1, flags: " + dintToHex(v := flags) + ", UUID: " + UUID, v1 := c);
          ELSE
              DebugFmt(message := "    End(\2): \1", v1 := rc2, v2 := j);
          END_IF;
          j := j + 1;
        UNTIL rc2 <> _BLE_OK
        END_REPEAT;
    ELSE
        DebugFmt(message := "  End(\2): \1", v1 := rc, v2 := i);
    END_IF;
    i := i + 1;
  UNTIL rc <> _BLE_OK
  END_REPEAT;
END_FUNCTION;