How to interact Bluetooth from.NET Compact Framework

Bluetooth is wireless technology used mostly in small devices and electronic gadgets like PDA for data transfer between devices. As a common user it is very easy to use Bluetooth and you can fully enjoy all provided features, but from developer’s point of view, it can be quite frustrating to develop applications using Bluetooth in C# or VB.NET, because it isn’t as easy as you would expect.

The first reason is that .NET Compact Framework does NOT support Bluetooth, so some third-party library must be used. There are few libraries available, but before I start describing those, first let’s look on short overview, because situation with Bluetooth can be quite confusing.

Today, there is pretty much devices with Bluetooth, each using different type of Bluetooth hardware. All functionality of Bluetooth hardware is exposed thru so called Bluetooth stacks, let’s say low level interface or maybe drivers. Unfortunately there are several types of Bluetooth stacks, so application written for one Bluetooth stack will not work on different one. We have to choose which Bluetooth stack we will support in our application or implement different versions, each for particular Bluetooth stack, but of course, this will make development more difficult.

Here is short list of stacks:

  1. Widcomm stack
  2. Microsoft stack
  3. Others like Toshiba stack, …

Fortunately, in most of devices you will find Widcomm Bluetooth stack or Microsoft Bluetooth stack, so I will focus only on these two (if you want to know more about Bluetooth stacks, look at http://en.wikipedia.org/wiki/Bluetooth_stack ^).

Widcomm stack

Broadcom implementation

Before April 2004, it was very difficult to develop for Widcomm Bluetooth stacks. But then in 2004 Broadcom company acquired Widcomm and released free official development kit for both Windows PC and Windows Mobile platforms for interacting Widcomm stack from custom applications. Unfortunately it‘s only unmanaged C++ version. You can download it here http://www.broadcom.com/products/Bluetooth/Bluetooth-RF-Silicon-and-Software-Solutions ^.

  • - unmanaged C++ version
  • + free

BTAccess from High-Point Software

This is managed library providing access to Widcomm stack. It is NOT free, you can find prices on http://www.high-point.com/purchase.htm ^. There is also available evaluation version on http://www.high-point.com/downloads.htm ^, there is no time limit but each time you initialize Bluetooth, dialog window is opened with information that it is only evaluation version.

I had several difficulties using this library. Some crucial events were fired more than once (e.g. each device was found always twice, etc) and finally it worked only on one of three tested PDA’s I had, all with Widcomm stack:

  • HP iPAQ hx2790 - working
  • HP iPAQ 214 - not working
  • Asus MyPal A639 - not working
  • - only Widcomm stack
  • - NOT free
  • + managed

Microsoft stack

Microsoft implementation

Here is situation much easier. Microsoft provides free library for Microsoft Bluetooth stack called Windows Embedded Source Tools for Bluetooth Technology. It is managed Win32 wrapper that includes classes for creating and enumerating Bluetooth services and classes to connect to existing Bluetooth devices.

Links:
http://msdn2.microsoft.com/en-us/embedded/aa714533.aspx & - official page
http://channel9.msdn.com/wiki/default.aspx/Channel9.BluetoothDevelopment ^ - web page with tutorials and samples
http://go.microsoft.com/?linkid=2913250 ^ - download library

  • - only for Microsoft stack
  • + managed
  • + free

32feet.NET

32feet.NET is another implementation providing access to Microsoft stack. It is free, shared-source project that you can find on http://inthehand.com/content/32feet.aspx ^.

  • - only for Microsoft stack
  • +manage
  • + free

Microsoft and Widcomm

Franson BlueTools

Franson BlueTools is the only library supporting both Microsoft and Widcomm stack at once, it recognizes stack in the device and uses appropriate implementation, all is automatic and hidden from programmer. Franson BlueTools supports both PC and Windows Mobile platforms.
Franson BlueTools is NOT free, standard version costs 99 €. There is also free 14 day trial version available - you have to register on http://franson.com ^ and get serial key that must be used in the code. Link to Franson BlueTools is http://franson.com/bluetools ^.

My experience
This library worked fine on all three tested PDA’s without problems, except some events were not fired as expected.

  • - NOT free
  • + supports both Widcomm and Microsoft stack
  • + managed

What stack is installed in my device?

Of course if you are going to develop some Bluetooth applications, you will need to know, what Bluetooth stack is in your device. There is no easy way to find that out, either you can watch registers on the device, whether there is Widcomm key or you can search Google. Unfortunately you can’t just look at manufacturer’s web pages to find out what Bluetooth stack is installed in the device, because they usually don’t provide this low-level information.

Summary

Purpose of this short article was to introduce you into problematic of developing Bluetooth enabled applications. Sample source codes are provided to all mentioned libraries on their web pages, you can download it there. If you are not sure, which one to take, I recommend Franson BlueTools that works fine and can be used for both Widcomm and Microsoft stacks.
I also recommend deeply testing library you will use on real PDA, because it usually doesn’t behave as expected. Most interaction is done thru events and my experience is that some events were fired in wrong order or several times at once.

Leave a Reply