Hello makeblock friends,
I need some help for reading data from the device in Extension Builder in LIVE mode.
I’m doing my own device (arduino based) and implemented on it a protocol (similar to FF55 protocol) for communicating with the device. The protocol is tested using a simple Terminal, so it is working Ok.
The block is a Boolean and in this example I try to get data from a Digital Pin.
The code implemented in bock’s Live Mode Handler (onRun) is:
(args, app, device, block) => {
app.log(Get block ${block.opcode} is checked to trigger
);
var bytes = [0xaa, 0x55, 4, 0, 1, 30, args.pin]; // Make the bytes for get the boolean data
device.writeRaw(bytes); // Send the bytes
let data = device.readRaw(); // Try to read the response
for (let i = 0; i < data.length; ++i) {
app.log(`data[${i}]`, datas1[i]); // Never execute this part
}
}
The problem is I never get the response data, even if the Device is sending the data.
Also I put logs in the Extension Handler onRead:
onRead(app, device) {
let data = device.readRaw(false);
app.log(“Reading Byte from device”);
for (let i = 0; i < data.length; ++i) {
app.log(Byte[${i}]
, datas1[i]);
}
}
And I get some response but aldo the “length” of data variable seems to be Zero, because the for loop never execute. This is what I get in the log:
mBlock log: Get block control_if_else is checked to trigger
mblock-mscratch.js?v5.1.5-3:1 mBlock log: Reading Byte from device
Also, I put the blocks I’m using for testing. I noted the flow does not execute correctly when I add my boolean block (get digital pin) in the if-else block. May be this is related to the problem above