2014-03-12 59 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中看到它們。