[英]How to get value from Arraybuffer of BLE device read characteristic value
I have gone through doc of IONIC 2 whcih is https://ionicframework.com/docs/v2/native/ble/ . 我浏览了IONIC 2的文档, 网址为https://ionicframework.com/docs/v2/native/ble/ 。 From there conversion of arraybuffer to string is given which is not working for me .
从那里给出了arraybuffer到string的转换,这对我不起作用。 As shown in image
如图所示
How to get firmware version from this data from read characteristics as Arraybuffer conversion code of IONIC 2 which is: function bytesToString(buffer) { return String.fromCharCode.apply(null, new Uint8Array(buffer)); }
如何从读取的数据中获取这些数据的固件版本,作为IONIC 2的Arraybuffer转换代码,即:
function bytesToString(buffer) { return String.fromCharCode.apply(null, new Uint8Array(buffer)); }
function bytesToString(buffer) { return String.fromCharCode.apply(null, new Uint8Array(buffer)); }
is not working for me. function bytesToString(buffer) { return String.fromCharCode.apply(null, new Uint8Array(buffer)); }
对我不起作用。 Using that code I am getting output: îÍy}ùt
. 使用该代码,我得到输出:
îÍy}ùt
。 I am new to ionic . 我是离子的新手。 I have Byte Transmission Order least significant octet first (ie, little endian).
我先将字节传输顺序的最低有效字节确定为最低字节(即小字节序)。 please provide me conversion solution.
请提供我转换解决方案。 Thank you.
谢谢。
I am using bytesToString
also and also got the value in ascii afterwards i did this: 我也使用
bytesToString
并且事后也得到了ascii中的值:
var convertData = bytesToString(result);
var hexResult = [];
for (var i=0; i < convertData.length; i++){
var resultNumber = convertData.charCodeAt(i); //Dec
var resultString = ("00" + (+resultNumber).toString(16)).substr(-2); //String
hexResult[i] = "0x" + resultString;
}
I want hex so I did toString(16)
. 我想要十六进制,所以我做了
toString(16)
。 You can change accordingly and play around with this. 您可以进行相应的更改并尝试使用。
Let me know if this works! 让我知道这个是否奏效!
我let data=new Uint8Array(buffer)
同样的问题,但是我发现的简单解决方案是let data=new Uint8Array(buffer)
现在在data
您将获得数组中的所有值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.