Closed sixbladeknife closed 10 years ago
Looking into the issue. Let's check.
'data.value' is BC.DataValue and the 'data' contains more information. use 'data' like this:
device.rfcommSubscribe(onDataAvaliable);
function onDataAvaliable(data){
$("#notifyValue_hex").html(data.value.getHexString());
$("#notifyValue_unicode").html(data.value.getUnicodeString());
$("#notifyValue_ascii").html(data.value.getASCIIString());
$("#notifyDate").html(data.date);
}
BTW: data.value.value is an ArrayBuffer in Uint8Array type. you can new the rawData like this:
var rawData = new Uint8Array(data.value.value);
thanks lizhijumacc, that did the trick, though documentation is pretty much unclear about a "custom" use of BC.DataValue. I humbly suggest to expand it a bit.
However, to make me understand fully:
Sorry for that. the rfcommSubscribe callback parameter 'data' is not type of the BC.DataValue , 'data' is just a common JSON object which contains the BC.DataValue field, the 'data.value' is BC.DataValue, so you can call the BC.DataValue function 'getHexString' for data.value. the data.value.value is an ArrayBuffer of Uint8Array~
you can dump the internal data structure about the 'data' object.
device.rfcommSubscribe(onDataAvaliable);
function onDataAvaliable(data){
alert(JSON.stringify(data));
}
Thanks for your advice, I will check the document later.
ok! once again thank you
hi, I'm trying to send binary data over bluetooth through RFCOMM. I subscribe a incoming data callback using:
and I define my callback similarly as:
logcat report as follow:
which tells me rawData is a correctly instantiated empty Uint8Array object, which is not what I expected to have, while variable data contains expected binary data. It seems that data, which should be of BC.DataValue type, does not return a ArrayBuffer object with the method value. What am I doing wrong?
thanks in advance
bye
sixbladeknife