btleReadVal (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400, NX-900

Firmware version:

1.10.00

 


 

This function will read a value from a characteristic.

 

Input:

dev : STRING

The address of the device to read from.

 

service : INT

The service the characteristic belongs to.

 

char : INT

The characteristic to read from.

 

size : INT

The size of the buffer.

 

data : PTR

The buffer to read the data into.

 

Output:

size : INT

The number of bytes read. If the buffer is too small, this will contain the needed size.

 

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.

-7

-

_BT_ERR_NO_RES


The buffer is too small for the data. The size parameter contains the needed size.

-8

-

_BT_ERR_INVAL


This device does not have any characteristics.

-16

-

_BT_ERR_NOT_PERM


The characteristic does not support read.

-19

-

_BT_ERR_NOT_CONNECTED


The device is not connected.

 

 

Declaration:

FUNCTION btleReadVal : INT;
VAR_INPUT
  dev      : STRING;
  service  : INT;
  char     : INT;
  size     : ACCESS INT;
  data     : PTR;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc      : INT;
  address : STRING;
  data    : ARRAY [1..60] OF SINT;
  size    : INT;
END_VAR;
 
// Turn on the Bluetooth library
btPower();
 
BEGIN
  ...
  size := SIZEOF(data);
  // Read data from BLE device <address>.
  rc := btleReadVal(dev := address, service := 16#0c, char := 16#1a, data := ADDR(data), size := size);
  DebugFmt(message:="btleReadVal "+address+": \1, size: \2", v1:=rc, v2 := size);
  ...
END;
 
END_PROGRAM;