btConnect (Function) |
Top Previous Next |
This function makes a connection to another Bluetooth device. To connect to a device, use the device number obtained from btSearch or specify the address of the device directly. Up to four connections can be handled simultaneously, which allows connections to both printers, headsets, etc. at the same time. However, only one audio connection is supported, so only one headset or other audio device may be connected at any given time.
The function returns a connection ID, which is the connection handle that is used when the connections are accessed. The ID is used in many cases - for example when transmitting data or when the connection must be disconnected. The ID is always the first available connection slot, and when an ID is disconnected, the slot will be available for a new connection.
When btConnects returns with the connection ID, the connection is not established yet - this is done asynchronously by the firmware. This means that several connections may be set up without waiting for the first connection to be established. The connections will be processed according to the assigned connection ID number. Use the btConnection function block to retrieve information about the connection. It will indicate when any changes occur to a connection - that could be connection establishment, disconnections, etc.
To connect to a headset, the headset parameter must be set to TRUE. Consult the user manual of the headset to determine the PIN. A headset connection uses two connections slots; one for control and one for audio. Please see btHsOpen for further information about using a headset.
The PIN input parameter is the PIN defined by the device to connect to. The Bluetooth module can only handle one PIN at a time, though. The btSetPin is used for incoming connections through btListen, and outgoing connection PINs are defined when a connection is initiated with btConnect. When a connection (through btConnect) is done with being processed, the Bluetooth module PIN will return to the PIN defined by btSetPin (if btListen is not used, this is irrelevant), or if more than one outgoing connection is pending, the module will initiate the next connection with the PIN associated for that connection.
When a connection to a device is established, the Bluetooth smart antenna stores the pairing info (address, passkey, etc.) which allows for a lost connection to be reestablished without user interaction. The Bluetooth smart antenna supports up to 16 simultaneous pairings, and when 16 devices have been paired, no new pairings will be stored.
Input: device : INT The device number found with btSearch (either use device or address - not both).
address : STRING The device address.
Pin : STRING The PIN of the device to connect to. Maximum 16 characters.
Headset : BOOL Set TRUE if connection is a headset.
Returns: SINT The connection ID
Declaration: FUNCTION btConnect : SINT;
Example: INCLUDE rtcu.inc |