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 //returns "SPP-dev" instead of name
})
}
successCallback(parsedDevices);
} else {
errorCallback("No devices found.");
}
}, function(error) {
errorCallback({
error: "list",
message: error.message
});
});
} catch (ex) {
errorCallback(ex);
}
}, 0);
}
}
以下代码返回DeviceInfromation.name值,如SPP-dev,HM-12,SPP1或Serial Port,有没有人遇到过这种情况?
答案 0 :(得分:0)
以下代码返回DeviceInfromation.name值,如SPP-dev,HM-12,SPP1或串行端口
这是设计并在RS1中更改。您的代码正在查询RfcommDeviceServices,这些名称与远程设备上的Rfcomm服务名称相匹配。
如果您对外围设备名称感兴趣,则必须使用以BluetoothDevice为目标的选择器字符串,或从RfcommDeviceService对象获取parent device。