Bluetooth Development
Background
The Windows Embedded Source Tools for Bluetooth was developed to help Windows Mobile/CE developers quickly and easily build Bluetooth-enabled applications.
The library consists of a single .Net assembly and offers the following capabilities:
- Enumerate previously paired devices
- Connect to another Bluetooth device using a NetworkStream object
- Expose a Bluetooth service for other devices connect with
As you can see, the library exposes the basics for a client-server programming model using the .Net Compact Framework.
Tutorial #1: Getting started with the Windows Embedded Source Tools for Bluetooth
Download the library from
here .
Bluetooth Information
05/10/2007Since this page seems to be abandoned I (Adam_) have been adding information and features to a site about programming for Bluetooth in .NET. Just today I have launched a section of the site dedicated to bluetooth. I hope this serves as a valuable information resource for those developing bluetooth applications.
Click Here
Tutorial #1: Listing paired Bluetooth devices
Coming Soon
While its still coming, here is my version
Tutorial 1
Tutorial #2: Connecting to another Bluetooth device
Coming Soon
Tutorial 2
Tutorial #3: Exposing a service for other Bluetooth devices to connect with
Coming Soon
Tutorial 3
Bluetooth stack support
The Windows Mobile Shared Source Bluetooth Library requires a Microsoft stack to cooperate with and does not support without modification the Widcomm stack. There are various libraries available when working with the Widcomm stack but they all come at a price.
High Point Software offer
BTAccess and other various products which provide access to the Widcomm stack. Similarly
Franson offer their own
BlueTools that provides support for both Microsoft and Widcomm stacks.
Comments / Questions
CommentHi everyone,
This is a brief overview of the Windows Mobile Shared Source Bluetooth as I had a painful day figuring this out. Firstly I'm sure everyone has downloaded the
setup file and installed.
This installation file copies the source code and a compiled DLL to C:\Program Files\Microsoft\Windows Embedded Source Tools\
So now all you need to do is add a reference to "Microsoft.WindowsMobile.SharedSource.Bluetooth.dll" in your project and then you get access to all the bluetooth classes
-BluetoothDevice-BluetoothService-BluetoothRadio-BluetoothDeviceCollection-BluetoothEndpoint Just a quick code sample on getting paired devices
Firstly import "Microsoft.WindowsMobile.SharedSource.Bluetooth"
Dim btRadio As New [BluetoothRadio]
For Each Device As [BluetoothDevice] In [btRadio.PairedDevices]
lbDevices.Items.Add(Device.Name)
Next
(yes, I prefer VB.NET)
Now one of the problems I found was I couldn't get a list of paired devices. So after I loaded all the source code into my project I determined it was erroring on
Registry.CloseKey(). More investigation found that the location in the registry that the DLL was looking for paired devices was HKEY
LOCALMACHINE\Software\\Microsoft\\Bluetooth\\Device. So using
Mobile Registry Editor I found out the location didn't exist.
I'm using an HP iPaq rx4700 and the location I found it under was HKEY
LOCALMACHINE\Software\\WIDCOMM\\BTConfig\\Devices\
or
HKEY
LOCALMACHINE\Software\\WIDCOMM\\Connections\\0001\
Just a side note, I imagine this registry issue is also the reason why "Microsoft.WindowsMobile.Status.SystemState.ConnectionsBluetoothCount" always returns zero.
Now to explain why this is happening as I'm new to bluetooth so this wasn't obvious to me. Their are different bluetooth stacks. The most common one is WIDCOMM. Microsoft have since made their own. Note that this code only applies to the Microsoft Stack, it will not work with WIDCOMM.
Now that this is all said you might want to watch
Creating a Managed Bluetooth Application Using Microsoft Visual Studio 2005 It's a great tutorial by Anil Dhawan that is easy to implement yourself once you know the above information.
Also a good stop off point is
http://msdn2.microsoft.com/en-us/library/ms847082.aspx
Added 29-04-2007Hi again
I just wanted to add some more info that might be of help
1. I still don't know about the Core class, if anyone does please post or email
2.
Open Source .NET Bluetooth project for Microsoft Stack3. I use
Franson Bluetools it supports the Microsoft and WIDCOMM stack but does cost a little money (well worth it considering how long you might spend figuring out bluetooth)
Added 01-07-2007Hi All
I have been receiving emails on this subject so I thought it would be great to post some articles on the subject to help everyone out. I am still creating them but there is some basic information there. I will also tell you that the btsCore class is not needed. I am still unsure what Anil is using but the functionality is all in the library just called differently.
So go to
http://www.dotnetcore.com/information.aspx
I should have some more information posted over the next few weeks to explain the entire library and even expand on it.
Thanks
Adam_
adam@dotnetcore.com
Q. I have Pharos BT adapter for MS GPS-360 device paired with Moto Q but when I start Pocket Streets on the Q, then "Start GPS" on the Q, I get the following from Pocket Streets: "The phone does not contain the Microsoft Bluetooth Manager, which is required to connect to a Bluetooth GPS device." Is it possible to install MS BT Manager on the Q like I installed Pocket Streets on the Q?
Q. Looking for a list of
PDAs and/or phones that use the Microsoft stack. Thanks! cdg - cdgreb@yahoo.com
Q. I am trying to develop a little software on a iPAQ (non-Microsoft stack), so... will your library be useful to me? Thanks to all :) Silius - silius@gmail.com
Q. How Do I connect to a GPS-Bluetooth-Devices that needs a pinnumber to connect?
Q. Anyone knows who or what team owns this library? I have some questions about it. Thanks
A. If there were any team in charge of this library then it may well be the
Windows Embedded team as the download is directly linked from their
Windows CE Source Code page.
Q. Do you know if this code could be modified to work with Pocket PC Build 4.2?
Q. The press release for the shared source code continually mentions the Win32 API, and using it on Windows Mobile and Embedded systems, but it only seems designed to run on Windows CE.
If you change the reference from "Ws2.dll" to "Ws2_32.dll" you get past the first stage, but it then falls over when referencing bthutil.dll, which only exists on Windows CE, not XP SP2 or Embedded. For example
BthSetMode() from bthutil.dll lets you set the radio to discoverable on Windows CE, but on XP you need to use ""BluetoothEnableDiscovery()"" from Irprops.cpl.
Perhaps this
managed wrapper would be more helpful for working with Bluetooth on XP
Q. Hey... I have just started an application and so far it hasnt put up any errors. Visual Studio .NET, C#, same ""SharedSource"" dll. Trouble is that I am not sure where to go from here. Is there any help whatsoever with the ""SharedSource""?
Q. I have been trying to develop some test purpose BT application, using MS Embedded Source Toolkit library. Just wanted to know where will i get the following files?
* bthutil.dll
* btdrt.dll
* Ws2.dll
* coredll.dll
Are they part of OS for Pocket PC or comes with CE SDK? Which version? - BT DEV
A. Hi as far as I know, they come with the SDK. I am using CE 4.2 (PocketPC 2003,
SmartPhone 2003). I've read in MSDN that these are supported only from CE 4.2.
Q. What do I do to get across this exception?
Unable to load DLL 'Ws2.dll': The specified module could not be found.
(Exception from HRESULT: 0x8007007E)
I am just doing:
[BluetoothRadio] br = new [BluetoothRadio();]
I have added the reference to ""Microsoft.WindowsMobile.SharedSource.Bluetooth.dll"" Any help available?
A. Hi. On what device are you running the code? As far as I know, you have to deploy the App on a Windows Mobile 5.0 PPC. I tried to do the same on my Laptop (Windows XP) which does not work!
Q. Hi all... I have a setup, with VS2005. I've downloaded the Windows Embedded Shared Bluetooth (or what was the name?). I watched the e-Howto by Anil Dhawan (hope i spelled his name right...). I'm trying to do the excact same thing as he does, only with the new and simplified Bluetooth Class Library.
Code for the Desktop-server is like this: (C#)
private void btnStartBtService_Click(object sender, [EventArgs] e)
{
Guid serviceGuid = new Guid("{2B430631-B12D-4487-BFF2-5EFAAB90DDB8}");
[BluetoothService] bs = new [BluetoothService(serviceGuid);]
if (!bs.Started)
bs.Start();
[NetworkStream] ns = [bs.AcceptConnection();]
// some sort of device is connected
string [dataToSend] = "Hello device. My name is Martin!";
byte[] dataBuffer = [System.Text.ASCIIEncoding.ASCII.GetBytes(dataToSend);]
ns.Write(dataBuffer, 0, dataBuffer.Length);
ns.Flush();
ns.Close();
}
The bs.Start() method throws a
SocketException. I'm using the Microsoft Bluetooth Stack, which is included in Windows XP SP2.
Any ideas what could be wrong?
A. I had a similar problem. So to try and debug the problem I consolidated the Shared Source code into a test app to find out where it falls over, so as to give me an idea as to what is going on inside the dll. The error may be because the
PublishService() method has a line:
serverSocket = new
Socket((AddressFamily)32, SocketType.Stream, (ProtocolType)3);But checking the
AddressFamily enumeration, the values only range from -1 to 29, so I'm not sure where 32 comes in, though I'm told it is correct because it is otherwise known as AF_BTH, the Bluetooth Address Family. An exception is thrown (and caught) when it gets to the line: serverSocket.Bind(btep);
It then carries on to try and extract a port no. at which point it crashes because
serverSocket.LocalEndPoint is null.
I think that is what is wrong. I'm still figuring out how to put it right. By the way, Anil, a new explanatory video would go a long way. The current one appears to be out of date using deprecated methods?
A. It looks like Start calls
PublishService. That function creates a new
BluetoothEndPoint and uses it to bind to the server socket. The end point is created with no parameters, so maybe the error is that it has an invalid address?
Q. I attempted to perfrom Anil's example as well, but I'm having trouble getting Visual Studio to recognize the new libraries that are posted on
Microsoft Windows Embedded Developer Center.
I can't tell if I've just been unable to locate the libraries or if I've downloaded the wrong library.