Search code examples
c#bluetoothrfcomm32feet

Error 10049 while connecting bluetooth device with 32feet


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());

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.