btleWriteVal (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400, NX-900

Firmware version:

1.10.00

 


 

This function will write a value to a characteristic.

 

Input:

dev : STRING

The address of the device to write to.

 

service : INT

The service the characteristic belongs to.

 

char : INT

The characteristic to write to.

 

size : INT

The number of bytes to write.

 

data : PTR

The data to write.

 

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.

-16

-

_BT_ERR_NOT_PERM


The characteristic does not support write.

-19

-

_BT_ERR_NOT_CONNECTED


The device is not connected.

 

 

Declaration:

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

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc      : INT;
  address : STRING;
  data    : ARRAY [1..60] OF SINT;
END_VAR;
 
// Turn on the Bluetooth library
btPower();
 
BEGIN
  ...
  data[1] := 45;
  data[2] := 21;
  data[3] := 10;
  data[4] := 71;
  // Send data to BLE device.
  rc := btleWriteVal(dev := address, service := 16#0c, char := 16#1a, data := ADDR(data), size := 4);
  DebugFmt(message:="btleWriteVal "+address+": \1", v1:=rc);
  ...
END;
 
END_PROGRAM;