1. Setup and Requirements
Bluetooth capabilities in LabVIEW are available for the following operating systems:
- Windows XP SP 2 and later – LabVIEW works with Bluetooth devices that use the Microsoft Bluetooth driver included with Windows XP Service Pack 2 and later. Refer to the Microsoft Web site for Bluetooth devices that are supported by the Microsoft Bluetooth driver. Most Bluetooth devices come packaged with a proprietary Bluetooth driver. To use the device with LabVIEW, the Bluetooth adapter must be using the Microsoft Bluetooth driver. A Microsoft Bluetooth driver for Windows XP SP1 was also available. Refer to Microsoft Knowledge Base Article 323183: Availability of Windows XP Service Pack 1 Support for Bluetooth Wireless Devices for more information about Bluetooth-compatible operating systems.
- Windows 2000 – Bluetooth applications for a PDA target can be developed in Windows 2000. However, Bluetooth communication cannot be utilized since Windows 2000 does not have a compatible Bluetooth driver. Applications developed in Windows 2000 can be built for a target that supports Bluetooth and run on that system.
- Pocket PC 2003 – To run Bluetooth applications on Pocket PC 2003 devices they must be using the WIDCOMM BTW-CE driver version 1.4 or later. Additional installation of Bluetooth DLLs is also required. Refer to the Installing the WIDCOMM Bluetooth DLLs on Pocket PC 2003 Devices section of the Getting Started with LabVIEW PDA Module for more information.
- Palm OS 5.0 and later – To run Bluetooth applications on Palm devices, you must have Palm OS 5.0 and later with installed Bluetooth hardware.
- Mac OS X - The LabVIEW Bluetooth VIs are not supported on the Mac platform.
2. Creating a Bluetooth Server Application
Complete the following steps to develop a Bluetooth server application.
1. Create a Bluetooth service – Use the Bluetooth Create Listener function to create a Bluetooth service identified by a Bluetooth uuid. This function returns a listener ID which refers to this server through your LabVIEW application. The Bluetooth Create Listener function also returns a reserved Bluetooth channel that the server can use to listen for inbound connections. A Bluetooth channel is a global resource with only 30 channels available on any Bluetooth device. If no server channel is available the function returns an error.
2. Wait for incoming connection request – Use the Bluetooth Wait on Listener function to wait for and accept an incoming connection request from a client. This function returns a connection ID that is used to exchange data with the client.
3. Read and Write data – Use Bluetooth Read and Bluetooth Write functions to exchange data with the client.
4.Close connection – Use Bluetooth Close Connection function to close connection to the client and to stop listening for incoming connections.
The block diagram of a typical Bluetooth server application looks similar to Figure 1.
Figure 1. Bluetooth Server Application
3. Creating a Bluetooth Client Application
Complete the following steps to develop a Bluetooth client application.
1. Request a connection to Bluetooth server – Use the Bluetooth Open Connection function to connect to a service on a Bluetooth server. Set the channel number to zero and specify a Bluetooth uuid to identify which service to connect to. The Bluetooth Open Connection function performs an SDP query to make a connection to the first service found with matching uuid. Internally, the result of an SDP query is an RFCOMM channel number to connect to. The SDP query is a tool to "translate" uuid to a channel number.
If you know the channel number associated with the service in advance, use the channel number instead of zero. Specifying a nonzero channel number bypasses the internal SDP query operation thus reducing the amount of time it takes to connect to the service. If the channel number is nonzero, LabVIEW ignores the uuid input parameter.
Note: You can use the Bluetooth RFCOMM Service Discovery VI to search for a valid channel number associated with a service on a remote Bluetooth device. This VI performs an SDP RFCOMM service discovery resulting in a channel number you can use to connect to the corresponding service on the remote Bluetooth device.
2. Read and Write data – Use Bluetooth Read and Bluetooth Write functions to exchange data with the server.
3. Close connection – Use Bluetooth Close Connection function to close connection to the server.
The block diagram of a typical Bluetooth client application looks similar to Figure 2.
Figure 2. Bluetooth Client Application
Refer to the following VIs for examples of creating a simple Bluetooth server and client applications:
- Simple Bluetooth Server VI: labview\examples\comm\Bluetooth.llb
- Simple Bluetooth Client VI: labview\examples\comm\Bluetooth.llb
- Simple Bluetooth Server (Palm OS) VI: labview\examples\PDA\pdacomm\PDABluetooth.llb
- Simple Bluetooth Client (Palm OS) VI: labview\examples\PDA\pdacomm\PDABluetooth.llb
- Simple Bluetooth Server (Pocket PC) VI: labview\examples\PDA\pdacomm\PDABluetooth.llb
- Simple Bluetooth Client (Pocket PC) VI: labview\examples\PDA\pdacomm\PDABluetooth.llb
4. Finding Nearby Bluetooth Devices
Use the Bluetooth Discover function to search for Bluetooth devices that are within the permissible range. The function returns a list of device addresses and names. These device addresses can then be used by a client to connect to a specific Bluetooth server. The optional input parameter, time limit (ms), specifies the length of Bluetooth inquiry. The default value is 10 ms and the maximum value is 30 s. If time limit is less than or equal to zero, the function returns a list of installed local Bluetooth devices.
Note: Bluetooth discovery is a slow operation because of the communication involved. A Bluetooth device address is a fixed address that is usually printed on the actual device and you can query the address from the device control setting. This address is unique to each device. If you know the Bluetooth address of the specific device you want to connect to, you can skip the discovery process and use the Bluetooth Open Connection function to connect to the device directly.
5. Querying Services Available on a Bluetooth Device
Use the Bluetooth RFCOMM Service Discovery VI to search for available RFCOMM services on a local/remote Bluetooth device. This function returns a list of available services along with the associated channel numbers. A channel number in the list can be used as an input parameter of the Bluetooth Open Connection function to make a connection to the corresponding service on the remote Bluetooth device.
Figure 3. Bluetooth Discovery Function
Refer to the following VIs for examples of Bluetooth device and service discovery:
- Advanced Bluetooth Server.vi: labview\examples\comm\Bluetooth.llb
- Advanced Bluetooth Client.vi: labview\examples\comm\Bluetooth.llb
- Advanced Bluetooth Client – PDA.vi: labview\examples\PDA\pdacomm\PDABluetoothllb
6. Bluetooth Virtual Serial Port
A Bluetooth system in PalmOS and PocketPC provides serial port profile with a virtual serial driver. Bluetooth Serial Port profile defines procedures that devices use to emulate an RS-232/serial cable connection. The profile maps virtual Serial COM ports to actual Bluetooth channels. Bluetooth Serial Port profile enables you to use LabVIEW Serial VIs to open a connection to and exchange data with other Bluetooth devices. Bluetooth Serial Port profile cannot be used on Windows XP SP1. Other Windows Bluetooth drivers may work with the Serial Port profile.
The driver recognizes only one active serial channel at a time. You can open the serial channel as an outbound (client) port or as an inbound (server) port. When you open the port as an outbound (client) port, the driver prompts you to select a Bluetooth device (server) to connect to. When you open the port as an inbound (server) port, the driver waits to receive a connection request from the client. Bluetooth serial port is based on RFCOMM, which is different from a physical serial port. RFCOMM requires roles of a server and a client when establishing Bluetooth serial connection.
Refer to KnowledgeBase 32GEGGTP: Does LabVIEW for PDA Support Bluetooth? (linked below) for more information on Bluetooth Virtual Serial Port and the LabVIEW PDA Module.
KnowledgeBase 32GEGGTP: Does LabVIEW for PDA Support Bluetooth?
LabVIEW Development System
LabVIEW PDA Module
LabVIEW PDA User Manual