BTConnect


BTConnect channel, address$ {,UUID$}

This command opens a Bluetooth channel to a device who's address is known. The address was most likely determined from a BTGetPaired$() function.

The channel number is chosen by the programmer. It is a lot like a file number and may be 1 to 10. So theoretically you could have up to 10 Bluetooth connections open at the same time, but you may find your Android device is limited to 5 or 6 connections before one of the existing connections is dropped. Some online references say up to 60 Bluetooth devices can be connected at once. If anyone succeeds in connecting 10 devices and wants to try more, post a topic on the forum and I will increase the limit.

The UUID$ is an optional string which will override the default unique application identifier. This field should always be omitted unless you have a good reason for using a particular unique identifier. If used, the unique identifier will only be used for the specified channel.


Example:


'First get the address of the device you wish to connect to.

dim pairs$(0)
pairs$() = BTGetPaired$()

If pairs$(0) = "none" Then
Print "No paired devices found"
End
Endif

List pairs$(), device$
name$ = ItemExtract$(device$, 0)
address$ = ItemExtract$(device$, 1)

'Now try to connect.

BTConnect 1, address$

'Wait for connection
For i = 1 to 30
Print BTGetState(1);" - ";
Print BTGetError$(1)
If BTGetstate(1)=4 Then Exit For
Wait 1000
Next i

If BTGetState(1) = 4 Then
Print "Connected"
Else
Print "Connect Failed"
Endif



Screenshot from above code



Bluetooth On|Off


Pairing a Bluetooth Device


BTGetPaired$()


BTDiscoverable


BTListen


BTGetSize()


BTGetState()


BTGetError$()


BTRead$()


BTWrite


BTGetName$()


BTGetAddress$()


BTClose