Remove Bluetooth Device given a String mac address

Topics: Bluetooth - Microsoft
May 30, 2012 at 1:55 PM
Edited May 30, 2012 at 2: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));
BluetoothSecurity.RemoveDevice(tempaddress);

 

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

Developer
May 30, 2012 at 2:46 PM
Edited May 30, 2012 at 2:57 PM

What platform?  Desktop Windows or Mobile?  Which Bluetooth stack? (e.g. http://32feet.codeplex.com/wikipage?title=Stack%20Identification&referringTitle=Documentation 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 2: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.

Developer
May 30, 2012 at 3:08 PM
Edited May 30, 2012 at 4: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);