【问题标题】:Write 20 Bytes command on BLE device using IONIC CAPACITOR application使用 IONIC CAPACITOR 应用程序在 BLE 设备上写入 20 字节命令
【发布时间】:2022-10-04 22:03:31
【问题描述】:

嗨,伙计,我正在开发一个连接到 BLE 设备的应用程序。现在我需要使用 BleClient.write 在设备上写入这些 20 字节

34h 01h 50h 4Fh 4Ch 49h 54h 45h 43h 00 00 00h 00h 00h 00h 00h 00h 00h 00h 00h

但写功能问我 DATAVIEW... 我如何将这些字节发送到设备?

BleClient.write(device.deviceId, \'02366e80-cf3a-11e1-9ab4-0002a5d5c51b\', \'340a1b80-cf4b-11e1-ac36-0002a5d5c51b\', \'34h 01h 50h 4Fh 4Ch 49h 54h 45h 43h 00 00 00h 00h 00h 00h 00h 00h 00h 00h 00h\');

    标签: arrays typescript ionic-framework bluetooth-lowenergy


    【解决方案1】:

    根据write 方法的documentation,您可以使用numbersToDataView 辅助方法创建数据视图。它接受一个数字数组。

    usage section 甚至包括一个使用助手的示例:

    await BleClient.write(device.deviceId, POLAR_PMD_SERVICE, POLAR_PMD_CONTROL_POINT, numbersToDataView([1, 0]));
    console.log('written [1, 0] to control point');
    

    在你的情况下,它可能是

    numbersToDataView([34h, 01h, 50h, 4Fh, 4Ch, 49h, 54h, 45h, 43h, 00, 00, 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h])
    

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 2018-11-18
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 2020-03-21
      • 2020-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多