nativescript - Nativescript蓝牙读取连续数据
问题描述
我们正在使用一种 EEG 设备,它每秒提供原始数据。使用时nativescript-bluetooth
我们可以扫描和连接设备,但读取只返回一个值。我们想要的是连续的数据读取和存储。
我试图读取bluetooth.read
一次打印结果的位置,但我希望它每秒被调用一次。
```
bluetooth.connect({
UUID: uuid,
onConnected: (peripheral) => {
peripheral.services.forEach((service) => {
console.log("service found: " + JSON.stringify(service));
this.deviceServiceData = service;
});
setTimeout(() => {
this.readDataFromDevice(this.deviceServiceData, uuid);
this.notify(this.deviceServiceData, uuid);
}, 1000);
},
onDisconnected: function (peripheral) {
console.log("Periperhal disconnected with UUID: " + peripheral.UUID);
}
});
}
notify(service, uuid) {
bluetooth.startNotifying({
peripheralUUID: uuid,
serviceUUID: service.UUID,
characteristicUUID: service.characteristics[0].UUID,
onNotify: function (result) {
console.log("read: " + JSON.stringify(result));
}
}).then(function () {
console.log("subscribed for notifications");
}, function (err) {
console.log("notify error error: " + err);
});
}
readDataFromDevice(service, uuid) {
bluetooth.read({
peripheralUUID: uuid,
serviceUUID: service.UUID,
characteristicUUID: service.characteristics[0].UUID,
}).then((result) => {
var data = new Uint8Array(result.value);
console.log(data);
}, function (err) {
console.log("read error: " + err);
});
}
How should I get the values generated by the device every second? Do I call `readDataFromDevice` at every time interval?
解决方案
推荐阅读
- swift - 具有相同名称的 Swift 枚举案例
- filter - 如何封装ansible过滤器?
- javascript - 多约束复杂数据的最佳组合算法
- prometheus - 普罗米修斯每次发出请求时都会使用令牌读取文件吗?
- vue.js - 我将 axios 响应存储到两个不同的“数据”变量中,如果我更改一个变量,它将自动更改另一个变量
- java - 当他/她在新行中按 Enter 时,用户必须退出 while 循环。但它不起作用,它一直在换行
- java - 千分尺@Timed 注释
- tensorflow - GCloud MLEngine:创建版本失败。检测到错误模型错误:加载模型失败:需要类似字节的对象,而不是“str”(错误代码:0)
- scala - 使用临时凭证通过来自 AWS 外部的 spark 从 s3 读取
- python - 我如何获得为单个图像预测的神经网络的值?