gpt4 book ai didi

javascript - DeviceInformation.findAllAsync DeviceInformation 返回不正确的名称属性

转载 作者:行者123 更新时间:2023-11-28 04:53:17 27 4
gpt4 key购买 nike

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 或串行端口,有人遇到过这种情况吗?

最佳答案

Following code returns in DeviceInfromation.name values like SPP-dev, HM-12, SPP1 or Serial Port

这是设计使然,并在 RS1 中进行了更改。您的代码正在查询 RfcommDeviceServices,并且这些名称与远程设备上的 Rfcomm 服务的名称相匹配。

如果您对外围设备名称感兴趣,则必须使用针对 BluetoothDevice 的选择器字符串。 ,或获取parent device来自 RfcommDeviceService 对象。

关于javascript - DeviceInformation.findAllAsync DeviceInformation 返回不正确的名称属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42734859/

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