连接和断开蓝牙设备已在Windows Phone/Desktop 8.1上提供了各种结果.我一直在使用Windows.Devices.Bluetooth.Rfcomm命名空间,我试图连接几个具有不同蓝牙版本/类的设备.
每当我尝试连接到2.0或2.1设备时,都会出现问题.我第一次尝试连接到每个设备时,一切都会正常,连接将打开.当我随后关闭连接并重新连接设备时,问题就开始了. 在重新连接期间,连接将永远不会打开,调试器将抛出System.Exception:
> Message: No further data is available.
Run Code Online (Sandbox Code Playgroud)
此外,当连接失败时,Windows 8.1设备将继续尝试(不成功)连接到蓝牙设备,即使我自己的应用程序终止.有时,Windows 8.1设备也会将蓝牙设备显示为已连接,而设备会直观地显示它已不再连接.重新连接蓝牙设备的唯一方法是取消配对并关闭/重启Windows设备上的蓝牙.
每当我尝试DeviceInformation在连接失败后进行新的呼叫时,它将拒绝返回我之前尝试连接的设备.
> Message: The service cannot be found in the specified name space.
Run Code Online (Sandbox Code Playgroud)
奇怪的结果,1.2设备完美运行.
清单文件:
<m2:DeviceCapability Name="bluetooth.rfcomm">
<m2:Device Id="any">
<m2:Function Type="serviceId:00001101-0000-1000-8000-00805F9B34FB"/>
</m2:Device>
</m2:DeviceCapability>
Run Code Online (Sandbox Code Playgroud)
选择设备:
Guid RfcommChatServiceUuid = Guid.Parse("00001101-0000-1000-8000-00805F9B34FB");
await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(RfcommChatServiceUuid)));
Run Code Online (Sandbox Code Playgroud)
连接:(id = chatserviceid)
StreamSocket _socket;
RfcommDeviceService service = await RfcommDeviceService.FromIdAsync(deviceInformation1._id);
await _socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName);
Run Code Online (Sandbox Code Playgroud)
断开:
this._socket.Dispose();
this._socket = null;
Run Code Online (Sandbox Code Playgroud)
我已经研究了MSDN,代码示例,演示版,channel-9视频和StackOverflow,没有资源可以告诉我是否存在问题Windows.Devices.Bluetooth.Rfcomm.
是否有人认识到这些奇怪的结果?难道我做错了什么? …