Help reading from device in Live mode


#1

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


#2

Hi, happy new year~
Please receive the data from Extension Event Handler>>>>> onRead, see the picture below:

image

image


#3

Hello and happy new year.
I’m currently receiving data in onRead Extension Event Handler. But the data received must go to the onRun block handler, I think…
There isn’t documentation about how the data arriving from the device must be processed to ensure the correct behavior of the block.
For the example I wrote above:

  • I send a command to the device “read digital pin x” in the block’s onRun
  • The device send the response back with the digital pin value
    How to read and pass the value to the block and/or to the app to process the data and the workflow continues ok?
    Can you put an real example of this?

Thank you very much!
Rodrigo


#4

Hi ralcoberro,

Thanks for reaching out to us. We’re indeed currently working on providing an example showing how the data receiving and sending in live-mode work. Please be patient, and we will get back to you soon.

Best,

Allen


#5

Hello Allen!
Thanks for the response. Do you now when you could provide the example, aprox?

Thanks again
Rodrigo


Create a simple mblock5 block for mbot
#6

Hi ralcoberro,

Thanks for asking about the progress. In fact, when we’re writing the demo. We realized due to some restriction of our extension builder, we had to resolve some issues first.

To differentiate official developers (our inner developers) and the third-party developers, we adopted some mechanisms to do so and restricted third-party user’s access to some APIs. When we wrote demos recently for you, some issues were revealed. We had to first solve them, otherwise the demo won’t work if you try to follow it.

In fact, at this time the issues have been resolved, but as a company providing stable services, every update has to formally go through testing and then be released in the version bugfix version. However, we don’t have sufficient resources to do it now, the next publish plan for this bug is postponed to February (mBlock Web) and March (mBlock PC). I think we’re possibly able to provide working demo for you around February if you wish to test it only on Web first.

We’re so sorry for this delay, and we have been working on it all the time. Please do understand that we’re focusing on the new incoming release for mBlock PC around January recently, but we will not ignore this important concern and will keep working this then.

Best,

Allen


#7

Hello friends,
Have you any news about this topic?
Thank you very much
Rodrigo


#8

enviame un mail a guillermonestordx@gmail.com


Returning a value with a number block and accessing arguments values
#9

Is this problem solved?

I still can’t.


#10

Hi ralcoberro & gustn9687,
Our engineer write a demo for you.
I will send you the file by email.
Please check your inbox.
Thanks.


#11

Thank you very much guys!
I’ll check my email

Best regards
Rodrigo


#12

Mail received.

  1. Should we add code?
    Should I put the opensensorium code?

  2. Does it work on Arduino Uno boards?


#13

Hi @tech_support and @gustn9687,
I didin’t receive de mail. Can you send it to me again, please?
My email is ralcoberro@gmail.com
Thanks!
Rodrigo


#14

Hi ralcoberro,
Send you again, please download from here.


Thanks.


Live mode for custom extension
#15

Hello @tech_support,
I received and load it Ok.
I will study it.

Thank you very much!!
Rodrigo


#16

@tech_support and @ralcoberro : could you share the code with me, I’m currently facing the same issues to program a live handler for a arduino robot. I do not know how to write a live mode handler to send and receive data. I do not have pb in writing a firmware, that’s classical arduino programming but the live mode handler is a mistery to me.
The doc is nice, but unfortunately it is about a http protocol, not a serial one, so it did not help me so much

NB : my email : seb_user@orange.fr


#17

Hi sebdelprat,
Hope it will work to you.
Uploaded here.online_mode_demo.zip (36.4 KB)


#18

Thanks a lot


#19

I am having a problem with the online_mode_demo.mext file. when I drag and drop it into the makeblock editor it tells me that the file is in the wrong format.