btleServiceDataGet (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400, NX-900

Firmware version:

1.54.00

 


 

This function retrieves the service data from a remote device.

The service data is custom data that is part of the 32 bytes in the advertising data.

 

A device may be sending multiple types of service data, so it may be necessary to call this function multiple times with increasing index until it returns BT_ERR_NODATA.

 

Note: To be able to receive advertising data, the adapter must be scanning, using btScanStart.

 

 

Input:

dev : STRING

The address of the device to get the data from.

 

index : INT (default 0)

The index of the service data to read.

 

size : INT

The size of the buffer.

 

data : PTR

The buffer to store the data in. Must be at least 31 bytes long to be able to store all normal data.

 

Output:

size : INT

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

 

UUID : STRING

The UUID of the service data.

 

 

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


Could not find device.

-7

-

_BT_ERR_NO_RES


The buffer is not large enough for the data.

-8

-

_BT_ERR_INVAL


Buffer is smaller than 31 bytes.

-9

-

_BT_ERR_NODATA


The device has no service data for this index

 

 

 

Declaration:

FUNCTION btleServiceDataGet : INT;
VAR_INPUT
  dev      : STRING;

  index    : INT := 0;

  size     : ACCESS INT;

  data     : MANDATORY PTR;

  UUID     : ACCESS STRING;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc      : INT;
  sz      : INT;
  address : STRING;
  uuid    : STRING;
  data    : ARRAY [1..32] OF SINT;
END_VAR;
 
// Turn on the Bluetooth library
btPower();
 
// Start scanning for BLE devices to receive advertising data.
btScanStart(transport:=2);
 
BEGIN
  ...
  // retrieve service data from the device
  sz := SIZEOF(data);
  rc := btleServiceDataGet(dev:=address, data:=ADDR(data), size := sz, UUID := uuid);
  DebugFmt(message:="btleServiceDataGet: \1, sz \2$N", v1:=rc, v2 := sz);
 ...
END;
 
END_PROGRAM;