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


This opens the Bluetooth module and enables the library functions. This function must be called and returned successfully before any other Bluetooth function is called. If the Bluetooth module is disconnected or power is removed, it is necessary to re-initialize the module by closing the module with btClose and reopen with btOpen.

 

Power will be applied directly from the serial port connector through the DC-Out output. Because of this, boardDCOUT should not be used in the program as the firmware will control this output when the Bluetooth module is opened and closed. There should also not be connected anything else to the DC-Out output when the Bluetooth module is connected.

 
For non-USB programming port devices:

When the Bluetooth module is open, the normal programming port is disabled, and btClose must be called to re-enable it.

 

After the Bluetooth library has been opened, connections to other devices can be made. Use btConnect to initiate an outgoing connection where the program decides which device to connect to either by using a specific address or by doing a network search with btSearch. Alternatively use btListen to open for incoming connections where other Bluetooth devices may search for the module and connect to it.

 

The Bluetooth module is invisible for other Bluetooth devices until a btListen command is issued to allow incoming connections. Until then, however, the Bluetooth module will not be found during network searches.

 

Input:

port : SINT

The serial port where the Bluetooth module is located (only port 0, the default port, is supported).

 

name : STRING

The name of the Bluetooth module. Other devices in the area will see this name. Maximum length is 40 characters.

 

Returns: INT

0

- Success.

-2

- Bluetooth library is already open.

-3

- Bluetooth module is not present or not supported.

-6

- Bluetooth does not support selected CPU speed.

-10

- Invalid port.

-12

- Invalid name.

 

Declaration:

FUNCTION btOpen : INT;
VAR_INPUT
  port : SINT := 0;
  name : STRING := "";
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
 
// Open the Bluetooth library
btOpen(name := "RTCU MX2");
 
BEGIN
 ...
END;
 
END_PROGRAM;