btSignalLevel (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


The btSignalLevel function is used to obtain the current signal level of a connection. Use the connection ID obtained from btConnect or btListen as the input parameter. The return value is a decimal value between 0 and 100 where 100 is maximum signal strength.

 

Input:

ID : SINT

The connection ID obtained with btConnect or btListen.

 

Return: SINT

Signal level 0..100 where 100 is maximum signal strength.

-1

- Bluetooth library is not open.

-3

- Bluetooth module is not present.

-8

- No device connected to ID.

 

Declaration:

FUNCTION btSignalLevel: SINT;
VAR_INPUT
  ID : SINT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc           : INT;
  SignalLevel  : SINT;
  ConID_out   : SINT;
  ConID_in     : SINT;  
  buffer       : ARRAY[1..127] OF SINT;
  RXbuffer_out : ARRAY[1..127] OF SINT;
  RXbuffer_in  : ARRAY[1..127] OF SINT;
  btRX_out     : btReceiveData;
  btRX_in      : btReceiveData;
  btCon_out   : btConnection;
  btCon_in   : btConnection;
END_VAR;
 
// Open the Bluetooth library
btOpen(name := "RTCU MX2");
 
// Set the Pin for incoming connections
btSetPin(pin := "1234");
 
// 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);
 
// Initiate the incoming connection
ConID_in:=btListen();
DebugFmt(message:="Incoming Connection ID =\1", v1:=ConID_in);
 
// 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;
 
// setup the receive and connection function blocks
btRX_in.Data:=ADDR(RXbuffer_in);
btRX_in.MaxSize:=SIZEOF(RXbuffer_in);
btRX_in.id:=ConID_in;
btCon_in.id:=ConID_in;
 
BEGIN
btCon_out();
btCon_in();
btRX_out();
btRX_in();
 
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 btCon_in.changed THEN
  DebugMsg(message:="Connection info changed:");
  DebugFmt(message:="    Connected=\1",v1:=INT(btCon_in.connected));
  DebugMsg(message:="    Address="+btCon_in.Address);
  DebugFmt(message:="    Error=\1", v1:=btCon_in.Errorcode);
END_IF;
 
IF btRX_out.ready THEN
  DebugMsg(message:="Data Received from outgoing connection");
END_IF;
 
IF btRX_in.ready THEN
  DebugMsg(message:="Data Received from incoming connection");
END_IF;
 
  ...
SignalLevel:=btSignalLevel(ID:=ConID_in);
DebugFmt(message:="Incoming connection Signal level =\1", v1:=SignalLevel);
 
SignalLevel:=btSignalLevel(ID:=ConID_out);
DebugFmt(message:="Outgoing connection Signal level =\1", v1:=SignalLevel);
 
  ...
 
END;
END_PROGRAM;