bleServiceGet (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

LX2

Firmware version:

2.25.00


This function will retrieve a service from the device.

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

 

 

Input:

dev: SYSHANDLE

Handle to the device to get the service from.

 

idx: INT

Zero-based index of the service to read.

 

Output:

service : INT

The ID of the service.

 

primary : BOOL

TRUE if this is a primary service.

 

UUID : STRING

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

-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 bleServiceGet : INT;
VAR_INPUT
  dev       : SYSHANDLE;
  idx       : INT;
  service   : ACCESS UINT;
  primary   : ACCESS BOOL;
  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;