读数据
删除特定 key 所对应的键值对
[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.bluetooth.read(device_id, service_uuid, characteristic_uuid,success,error)
支持平台:
- Android
- iOS
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
device_id | String | 是 | 设备号 |
service_uuid | String | 是 | 服务id |
characteristic_uuid | String | 是 | 特征值 |
success | Function | 是 | 成功回调函数 |
error | Function | 是 | 失败回调函数 |
device_id
(android)设备mac
地址,(ios)设备id
。
service_uuid
服务id
,连接蓝牙时返回。
characteristic_uuid
特征值,连接蓝牙时返回。
success
函数会返回ArrayBuffer
类型,结果信息。
error
函数会返回一个字符串,错误的相关信息。
示例代码
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
var uuid = 'BA6607B4-9EA3-E8FE-6D42-1464FB57FE44';
var service_uuid='FFF0';
var characteristic_uuid='FFF3';
navigator.bluetooth.read(uuid,service_uuid,characteristic_uuid,function (success) {
var buffer = ab2str(success);
console.log(JSON.stringify(buffer));
},function (error){
alert(JSON.stringify(error));
});
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
}
</script>
响应示例代码:
"1E.05.05.05"