Question

I'm trying to establish a connection with a custom bluetooth device without using COM ports. However, I'm getting an error: [10049] "The requested address is not valid in its context". What am I doing wrong?

static Guid serviceClass= new Guid("4d36e978-e325-11ce-bfc1-08002be10318"); //GUID of device class

static BluetoothAddress addr = BluetoothAddress.Parse("001210160177"); //from device            
BluetoothDeviceInfo device = new BluetoothDeviceInfo(addr); 

device.SetServiceState(serviceClass, true);

Console.WriteLine(BluetoothSecurity.PairRequest(device.DeviceAddress, "0000")); //pairing my device - writes True
BluetoothEndPoint ep = new BluetoothEndPoint(addr, serviceClass);

BluetoothClient conn = new BluetoothClient(ep); //10049 error
conn.Connect(ep);
Console.WriteLine(conn.GetStream());
Was it helpful?

Solution

Its all covered in the project's documentation. :-)

In short, remove that SetServiceState line it is unnecessary/bad. Doing the pairing each time is also unnecessary and a bit slow but probably not worth changing if its working well.

Docs:

1) http://32feet.codeplex.com/documentation

  • "See section General Bluetooth Data Connections below. The BluetoothClient provides the Stream to read and write on -- there is no need to use virtual COM ports"

2) http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections

BluetoothAddress addr
  = BluetoothAddress.Parse("001122334455");
Guid serviceClass;
serviceClass = BluetoothService.SerialPort;
// - or - etc
// serviceClass = MyConsts.MyServiceUuid
//
var ep = new BluetoothEndPoint(addr, serviceClass);
var cli = new BluetoothClient();
cli.Connect(ep);
Stream peerStream = cli.GetStream();
peerStream.Write/Read ...

3) http://32feet.codeplex.com/wikipage?title=Errors

  • 10049 "The requested address is not valid in its context."
  • No Service with given Service Class Id is running on the remote device

i.e. Wrong Service Class Id.

OTHER TIPS

Here's how it finally rolls.

device.SetServiceState(serviceClass, true); //do it before pairing
...
BluetoothClient conn = new BluetoothClient(); 
conn.Connect(ep);

Also, my mistake here:

static Guid serviceClass = new Guid("4d36e978-e325-11ce-bfc1-08002be10318"); 
//GUID of device class

Should be:

static Guid serviceClass = new Guid("00001101-0000-1000-8000-00805f9b34fb"); 
//GUID of bluetooth service

For seeing the proper GUID, refer to your device's (not dongle's) settings/properties. You can see them from Windows.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top