【问题标题】:DeviceInformation.findAllAsync DeviceInformation returns incorrect name propertyDeviceInformation.findAllAsync DeviceInformation 返回不正确的名称属性
【发布时间】:2017-08-01 18:29:49
【问题描述】:
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 或串行端口,有人遇到过这种情况吗?

【问题讨论】:

    标签: javascript cordova bluetooth uwp


    【解决方案1】:

    以下代码返回 DeviceInfromation.name 值,例如 SPP-dev、HM-12、SPP1 或串行端口

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

    如果您对外围设备名称感兴趣,则必须使用以BluetoothDevice 为目标的选择器字符串,或从 RfcommDeviceService 对象中获取parent device

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多