Remove Bluetooth Device given a String mac address

Topics: Bluetooth - Microsoft
May 30, 2012 at 12:55 PM
Edited May 30, 2012 at 1:53 PM

I have a pairing application that stores a service in a registry key. When I pair a new device, I need to remove the old device. I get the mac address from registry as a string.

How do I convert this to a value I can use for BluetoothAddress / BluetoothSecurity?

Here is what I have now:


BluetoothAddress tempaddress = new BluetoothAddress(encoding.GetBytes(tempMac));


When the application hits the "BluetoothAddress" it just hangs forever.

May 30, 2012 at 1:46 PM
Edited May 30, 2012 at 1:57 PM

What platform?  Desktop Windows or Mobile?  Which Bluetooth stack? (e.g. and linked pages).

BluetoothAddress (unfortunately) takes the address bytes in little-endian order.  Check that tempaddress is the same value as you expect.  PS you may want to use BluetoothAddress.CreateFromBigEndian.

May 30, 2012 at 1:52 PM

This is for a windows mobile application. It's actually freezing on the "BluetoothAddress" assignment, so I can't check that it is what I expect.

May 30, 2012 at 2:08 PM
Edited May 30, 2012 at 3:20 PM

Wierd.  Wait! What type is "encoding"??

I suspect that there's something wrong on the encoding,GetBytes call.  Split the first line into two and check which hangs e.g.

byte[] bytes = encoding.GetBytes(tempMac)
BluetoothAddress tempaddress = new BluetoothAddress(bytes);

However I suspect you really want something like:

string tempMac = ...
BluetoothAddress tempaddress = BluetoothAddress.Parse(tempMac);