2

我正在尝试在不使用 COM 端口的情况下与自定义蓝牙设备建立连接。但是,我收到一个错误:[10049]“请求的地址在其上下文中无效”。我究竟做错了什么?

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

2 回答 2

2

它的所有内容都包含在项目的文档中。:-)

简而言之,删除那条SetServiceState线是不必要的/不好的。每次都进行配对也是不必要的,而且有点慢,但如果它运行良好,可能不值得改变。

文件:

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

  • “请参阅下面的通用蓝牙数据连接部分。BluetoothClient 提供要读取和写入的 Stream——无需使用虚拟 COM 端口”

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 “请求的地址在其上下文中无效。”
  • 远程设备上没有运行具有给定服务类 ID 的服务

即错误的服务类 ID。

于 2014-03-15T10:55:25.080 回答
0

这就是它最终如何滚动的方式。

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

另外,我的错误在这里:

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

应该:

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

要查看正确的 GUID,请参阅您的设备(不是加密狗)的设置/属性。您可以从 Windows 中看到它们。

于 2014-03-14T09:23:07.400 回答