方法Windows.Devices.Enumeration.DeviceInformation.findAllAsync返回DeviceInformation的集合。此对象将属性name指定为设备蓝牙名称。但相反,该属性包含HM-12,SPP Dev或SerialPort等值,我假设它们是蓝牙协议的名称。
以下是示例。请注意,此代码在Windows升级之前正常工作(该版本导致此未知)
使用Windows 10 mobile 10.0.14393.67
Windows 10桌面输出正确的结果。
var rfcomm = Windows.Devices.Bluetooth.Rfcomm;
var sockets = Windows.Networking.Sockets;
var streams = Windows.Storage.Streams;
var deviceInfo = Windows.Devices.Enumeration.DeviceInformation;
var cordova = require('cordova');
module.exports = {
connService: null,
connSocket: null,
connWriter: null,
connReader: null,
connDevice: null,
list: function(successCallback, errorCallback) {
setTimeout(function() {
try {
var selector =
rfcomm.RfcommDeviceService.getDeviceSelector(
rfcomm.RfcommServiceId.serialPort);
var parsedDevices = [];
deviceInfo.findAllAsync(selector, null).then(function(devices) {
if (devices.length > 0) {
for (var i = 0; i < devices.length; i++) {
parsedDevices.push({
id: devices[i].id,
name: devices[i].name
})
successCallback(parsedDevices);
}
} else {
errorCallback("No devices found.");
}
}, function(error) {
errorCallback({
error: "list",
message: error.message
});
});
} catch (ex) {
errorCallback(ex);
}
}, 0);
}
}
选择器的值(Windows 10移动设备):
System.Devices.DevObjectType:=10 AND System.Devices.AepService.ProtocolId:="{E0CBF06C-CD8B-4647-BB8A-263B43F0F974}" AND System.Devices.AepService.ServiceClassId:="{B142FC3E-FA4E-460B-8ABC-072B628B3C70}" AND System.Devices.AepService.Bluetooth.ServiceGuid:="{00001101-0000-1000-8000-00805F9B34FB}" AND System.Devices.AepService.ParentAepIsPaired:=System.StructuredQueryType.Boolean#True
选择器的值(Windows 10 PC) - 工作正常
System.Devices.InterfaceClassGuid:=\"{B142FC3E-FA4E-460B-8ABC-072B628B3C70}\" AND System.DeviceInterface.Bluetooth.ServiceGuid:=\"{00001101-0000-1000-8000-00805F9B34FB}\" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True
答案 0 :(得分:0)
<强>问题强>
您的选择器仅查找与serialPort描述匹配的设备/服务,这就是您获得SPP Dev或Serial Port等名称的原因。
<强>解决方案强>
取自Windows 10 sample for BluetoothRFcommChat,找到蓝牙设备使用以下AQS查询:
"sample","sample"