2014-03-12 49 views
1

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

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

回答

2

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

总之,删除那SetServiceState线是不必要的/坏的。每次做配对也是不必要的,有点慢,但如果运作良好,可能不值得改变。

文档:

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

  • “见下面部分一般蓝牙数据连接BluetoothClient提供流中读取和写入 - 没有必要使用虚拟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上运行。

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中看到它们。