鸿蒙HarmonyOS SDK
设备通信
读取数据点

读取数据点

读取 API 由各通信 capability 提供。传入 undefined 读取全部数据点,传入名称数组只读取指定数据点。

通过 BLE 读取

const allBleData = await device.bleCapability.readDataPoints(device, undefined);
const selectedBleData = await device.bleCapability.readDataPoints(device, ['power']);

调用前应完成 BLE 连接与鉴权。

通过 LAN 读取

const allLanData = await device.lanCapability.readDataPoints(device, undefined);
const selectedLanData = await device.lanCapability.readDataPoints(
  device,
  ['power', 'temperature']
);

通过 MQTT 读取

const allCloudData = await device.mqttCapability.readDataPoints(device, undefined);
const selectedCloudData = await GizMqttManager.readDeviceDataPoints(device, ['power']);

同一设备同时只能有一个等待响应的 MQTT 读取命令。

返回结果

三个通道都返回 GizDataPointEvent。其中 dataalertsfaults 分别保存普通数据、告警和故障,binary 是原始二进制数据,source 表示来源通道。持续接收设备上报时,请使用 事件监听