C# 连接32英尺蓝牙设备时出现错误10049
我正在尝试在不使用COM端口的情况下与自定义蓝牙设备建立连接。但是,我收到一个错误:[10049]“请求的地址在其上下文中无效”。我做错了什么C# 连接32英尺蓝牙设备时出现错误10049,c#,bluetooth,rfcomm,32feet,C#,Bluetooth,Rfcomm,32feet,我正在尝试在不使用COM端口的情况下与自定义蓝牙设备建立连接。但是,我收到一个错误:[10049]“请求的地址在其上下文中无效”。我做错了什么 static Guid serviceClass= new Guid("4d36e978-e325-11ce-bfc1-08002be10318"); //GUID of device class static BluetoothAddress addr = BluetoothAddress.Parse("001210160177"); //from
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());
下面是它最终的运行方式
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中查看它们。项目文档中已涵盖了所有内容。:-) 简而言之,删除
SetServiceState
行,它是不必要的/不好的。每次配对都是不必要的,速度有点慢,但如果工作正常,可能不值得改变
文件:
(一)
- “请参阅下面的“常规蓝牙数据连接”一节。Bluetooth客户端提供读取和写入的流——无需使用虚拟COM端口”
- 10049“请求的地址在其上下文中无效。”
- 远程设备上没有运行具有给定服务类Id的服务
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 ...