btSendData (Function)

Top  Previous  Next

Architecture:

X32 / NX32

Device support:

MX2 pro, DX4 pro, AX9 pro, MX2 turbo/encore/warp, AX9 turbo

Firmware version:

1.05


Sends data to a connected Bluetooth device. The receiver is the connection ID obtained from btConnect or btListen. If large amounts of data are sent, make sure to empty the receive buffer by calling btReceiveData to avoid losing data due to buffer overflow.

 

Input:

ID : SINT

The connection ID obtained with btConnect or btListen.

 

Data : PTR

Pointer to the data to send.

 

Size : INT

Number of bytes to send.

 

Returns: INT

The connection ID.

-1

- Bluetooth library is not open.

-3

- Bluetooth module is not present.

-8

- No device connected to ID.

-16

- Invalid data pointer or size.

 

Declaration:

FUNCTION btSendData : INT;
VAR_INPUT
  ID   : SINT;
  Data : PTR;
  Size : INT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc           : INT;
  ConID_out   : SINT;
  buffer       : ARRAY[1..127] OF SINT;
  RXbuffer_out : ARRAY[1..127] OF SINT;
  btRX_out     : btReceiveData;
  btCon_out   : btConnection;
END_VAR;
 
// Open the Bluetooth library
btOpen(name := "RTCU MX2");
 
// Initiate the outgoing connection
ConID_out:=btConnect(address:="00:e0:98:ae:17:23",pin:="0000");
DebugFmt(message:="Outgoing Connection ID =\1", v1:=ConID_out);
 
// setup the receive and connection function blocks
btRX_out.Data:=ADDR(RXbuffer_out);
btRX_out.MaxSize:=SIZEOF(RXbuffer_out);
btRX_out.id:=ConID_out;
btCon_out.id:=ConID_out;
 
BEGIN
btCon_out();
btRX_out();
 
IF btCon_out.changed THEN
  DebugMsg(message:="Connection info changed:");
  DebugFmt(message:="    Connected=\1",v1:=INT(btCon_out.connected));
  DebugMsg(message:="    Address="+btCon_out.Address);
  DebugFmt(message:="    Error=\1", v1:=btCon_out.Errorcode);
END_IF;
 
IF btRX_out.ready THEN
  DebugMsg(message:="Data Received from outgoing connection");
END_IF;
 
  ...
 
rc:=btSendData(ID:=ConID_out, Data:=ADDR(buffer), size:=SIZEOF(buffer));
DebugFmt(message:="btSendData =\1", v1:=rc);
  ...
 
END;
 
END_PROGRAM;