This disconnects a connection ID. After this function call, the ID is invalid, and a btConnect or a btListen must be issued to establish a new connection. If a connection was lost and needs to be reestablished, it is not necessary to disconnect the ID. Just re-initiate the connection like when it was created before it was lost.
Input:
ID : SINT
The connection ID obtained with btConnect or btListen.
Returns: INT
0
|
- Success.
|
-1
|
- Bluetooth library is not open.
|
-8
|
- No device connected to ID.
|
-17
|
- Timeout, but the ID is released.
|
Declaration:
FUNCTION btDisconnect : INT;
VAR_INPUT
ID : SINT;
END_VAR;
Example:
INCLUDE rtcu.inc
PROGRAM test;
VAR
rc : INT;
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;
btOpen(name := "RTCU MX2");
ConID_out:=btConnect(address:="00:e0:98:ae:17:23",pin:="0000");
DebugFmt(message:="Outgoing Connection ID =\1", v1:=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:=btDisconnect(ID:=ConID_out);
DebugFmt(message:="ConID_out disconnected=\1", v1:=rc);
...
END;
END_PROGRAM;
|