gpt4 book ai didi

c# - 32feet连接蓝牙设备报错10049

转载 作者:行者123 更新时间:2023-12-05 05:27:01 25 4
gpt4 key购买 nike

我正在尝试在不使用 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());

最佳答案

它全部包含在项目的文档中。 :-)

简而言之,删除不必要/错误的 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。

关于c# - 32feet连接蓝牙设备报错10049,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22346166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com