btleCharGet (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400, NX-900

Firmware version:

1.10.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 -4 (_BT_ERR_NOT_FOUND).

 

Input:

dev : STRING

The address of the device to get the data from.

 

idx : INT

The index of the characteristic to read.

 

service : INT

The service to read the characteristics of.

 

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


3

04

Write no response

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


4

08

Write

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


5

10

Notify

The characteristic supports notifications, which can trigger events when the value changes. See btleNotifyStart.

 

 

UUID : STRING

The UUID of this characteristic.

 

 

Returns: INT

1

-

_BT_OK


Success.

0

-

_BT_ERR_NOT_SUPPORTED


The API is not supported.

-1

-

_BT_ERR_NOT_OPEN


The adapter is not powered(see btPower).

-4

-

_BT_ERR_NOT_FOUND


The device or characteristic could not be found.

-8

-

_BT_ERR_INVAL


This device does not have any characteristics.

 

 

 

Declaration:

FUNCTION btleCharGet : INT;
VAR_INPUT
  dev      : STRING;
  idx      : INT;
  service  : INT;
  char     : ACCESS INT;
  flags    : ACCESS DINT;
  UUID     : ACCESS STRING;
END_VAR;

 

Example:

...
FUNCTION getServices
VAR_INPUT
  dev     : STRING;
END_VAR;
VAR
  rc      : INT;
  rc2     : INT;
  service : INT;
  ch      : INT;
  primary : BOOL;
  UUID    : STRING;
  i       : INT;
  c       : INT;
  flags   : DINT;
END_VAR;
DebugMsg(message:="Get services for "+dev);
 
i := 1;
REPEAT
  rc := btleServiceGet(dev:=dev, idx:=i, service:=service, primary:=primary, UUID:=UUID);
  DebugFmt(message:="  btleServiceGet "+dev+": \1", v1:=rc);
  IF rc = _BT_OK THEN
    DebugFmt(message:="  Service: \1, primary: \2, UUID: "+UUID, v1:=service, v2:=INT(primary));
    c := 1;
    REPEAT
       
        rc2 := btleCharGet(dev:=dev, idx:=c, service:=service, char:=ch, UUID:=UUID, flags := flags);
        DebugFmt(message:="    btleCharGet "+dev+": \1", v1:=rc2);
        IF rc2 = _BT_OK THEN
          DebugFmt(message:="    Service: \1, Char: \2, flags: \4, UUID: "+UUID, v1:=service, v2:=ch, v4:=flags);
           
        END_IF;
      c := c + 1;
    UNTIL rc2 <> _BT_OK END_REPEAT;
  END_IF;
i := i + 1;
UNTIL rc <> _BT_OK END_REPEAT;
 
END_FUNCTION;
...