bleServiceFind (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

LX2

Firmware version:

2.30.00


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

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

 

The service can then be used by either bleCharGet or bleCharFind to find the wanted characteristics.

 

Input:

dev: SYSHANDLE

Handle to the device to get the service from.

 

UUID : STRING

The UUID of this service 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 service to read.

 

Output:

service : UINT

The ID of the service.

 

primary : BOOL

TRUE if this is a primary service.

 

 

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


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 bleServiceFind : INT;
VAR_INPUT
  dev       : SYSHANDLE;
  uuid      : STRING;
  idx       : INT := 0;
  service   : ACCESS UINT;
  primary   : ACCESS BOOL;
END_VAR;

 

Example:

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