Bluetooth

The RFO-BASIC! Bluetooth unit lets a BASIC program exchange bytes over a Bluetooth connection with another device that is paired with the Android device running the BASIC program. The other device does not have to be an Android device.

Before communication can occur, Bluetooth must be enabled on two devices and the devices have to be paired — that is, made aware of one another, typically with one of the devices providing a passcode that the user of the other devices enters through the keyboard. The way to do this is usually in the Android settings.

The BASIC Bluetooth connection is always in one of three states: Listening, Connecting, and Connected. Only when the state is Connected can exchange of bytes occur. Either device can drop the connection.

One of the two devices uses BT.OPEN to begin listening for a connection. The other device uses BT.CONNECT to connect with a device that is listening. Each connection is "secure" or "insecure" and both parties are required to specify one or the other type of connection.

The BASIC program can monitor the status of the connection and can be interrupted when bytes from the other device are ready to be read.


 * The program, included with the RFO-BASIC! installation, implements a simple text chat.  You can use it to verify that two devices are paired and can exchange bytes, to study use of these BASIC statements, and to be the starting point for your own Bluetooth application.

BT.OPEN
Open a Bluetooth connection

BT.OPEN {}
 * Synopsis

The BT.OPEN statement opens Bluetooth and either listens for a secure connection or listens for an insecure connection. If  is omitted or if its value is 1, BT.OPEN listens for a secure connection. If  is provided and its value is 0, BT.OPEN listens for an insecure connection.
 * Description

If the device's Bluetooth receiver is switched off, BT.OPEN puts a dialogue on the screen asking if the user wants to switch Bluetooth on. If the user denies permission to switch Bluetooth on, the BASIC program exits.

When BT.OPEN returns successfully, the connection is in Listening state.

BT.CLOSE
Close any Bluetooth connection

BT.CLOSE
 * Synopsis

The BT.CLOSE statement closes any Bluetooth connection that is open. If no connection is open, then BT.CLOSE has no effect. BASIC automatically closes the Bluetooth connection when the program exits.
 * Description