bleServiceGet (Function)

Top  Previous  Next

Architecture:

NX32L

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

 

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
   ij    : INT;
   sc    : UINT;
   rcrc2 : INT;
   uuid    : STRING;
   primary : BOOL;
   flags   : DINT;
END_VAR;   
   DebugMsg(message := "-- Services: --");
   i := 0;
   REPEAT 
      rc := bleServiceGet(dev := devidx := iservice := suuid := uuidprimary := primary);
      IF rc = 1 THEN
         DebugFmt(message := "  Service: \1, primary: \2, UUID: " + UUIDv1 := sv2 := INT(primary));
         j := 0;
         REPEAT 
            rc2 := bleCharGet(dev := devservice := sidx := jchar := cuuid := uuidflags := flags);
            IF rc2 = 1 THEN
               DebugFmt(message := "    Char: \1, flags: " + dintToHex(v := flags) + ", UUID: " + UUIDv1 := c);
            ELSE
               DebugFmt(message := "    End(\2): \1", v1 := rc2v2 := j);
            END_IF;
            j := j + 1;
         UNTIL rc2 <> _BLE_OK
         END_REPEAT;
      ELSE
         DebugFmt(message := "  End(\2): \1", v1 := rcv2 := i);
      END_IF;
      i := i + 1;
   UNTIL rc <> _BLE_OK
   END_REPEAT;
END_FUNCTION;