Initiating a backround JS code from SNAP!

sorry my little sister managed to get on my computer somehow
didn't mean to post here

added the following change behind the greeting message:

  Serial.print( "Hello from Arduino@WEB Serial");
  for (int i = 0; i<1000; i++){Serial.print(i % 100);}

On the SNAP receive side, when the image block is executed, the USBdata list is always single items of 255 entries, regardless of the timeout value specified.
image .
That ends up being the Greeting message plus the few numbers that fit into the remainder of the 255 entries.

Why only 255 entries when there is plenty more data?

Also, if I change the SNAP side to:
image
then the incoming is recorded as:
image

I must be doing something wrong, not to get the interim data.

Another Test:
with the original echo code on arduino:

  if( Serial.available() > 0){
    Serial.write( Serial.read());
  }

And SNAP executing:
image
what comes back is always:
image

WEB Serial API, Web Serial API

unsigned long bufferSize= 255;
FlowControlType flowControl = "none";

bufferSize member
A positive, non-zero value indicating the size of the read and write buffers that should be created.

Updated project to bufferSize = 15000 so it can accomodate 1s of data at 115200.
New method, repeat read till timeout.
SimpleSerial script pic (3)

Test sketch for writing small 10k chunks of data :wink: I'll prefer to not cluter "setup()" until neccesary.

void setup() {
  Serial.setTimeout (100);
  Serial.begin( 115200);
  while (!Serial) {delay(1);}
}
void loop() {
  if ( Serial.available()) {
    Serial.read();
    for (int i = 0; i<9999; i++){Serial.write((i % 100)+1);}
    Serial.write( 255);
  }
}

I consider it being OS/hardware dependant and not specified.
New block was added to to read all data until timeout occured after last successfull read.
Every meanigfull chunk of data must be separated by some substantial delay (>>(1000/60 ) ~ 30ms) or by "end-of-packet" marker and parsed.
Snap! yielding is required to allow JS event loop to "breathe" and process incoming data.
Sorry, if I trying to explain too obvious things ...

Had a chance to test the latest version.
When there are more than 1 USB port connected, selecting the first listed one always connects to the last one. Even with port close and open.

Are you selecting the actual picked port or always selecting the last one in the browser list ?

The last version works wonderfully !
I was able to transfer 10000 data points from micro device to SNAP !
Way beyond what will really be happening.
Even with 1ms timeout setting, it is possible to read very long streams, because at 115200 baud bit timing is 8usec.

You have created a masterpiece !

As soon as USB port selection is fixed, I will prepare some demo script for Jens.
I think he is going to like this one.

I made changes to allow port selection with an available ports reporter, index to ports list, GUI.
Only dry-run so far, as my other boards are not available during the Easter celebration.

Happy Easter, dardoro .

OK, All is well and working good with Arduino and my devices.
USB selection fixed.

Questions:

  • Documentation purposes, do we need all the blocks ?
  • Can we trim them down ?
  • Are there true differences in the way they operate ?

I will start working on the demo program for my needs with MicroBlocks.
We can certainly use the ones you did for the Arduino, for general public.

Thanks for all your help.

Open(-1)
Read (port) with ...
Write...
Close
are core components other are for convenience or better user experience.

Happy Easter, tguneysu

Hi dardoro,
Are you OK with me sharing our project with the MicroBlocks Developers community and the SNAP developer Jens ?
I am hoping that once he reviews your work and its application through my demo program, he will accept the library into the SNAP.
I will share all exchanged communication with you.

Please advise of your email to my email address: tguneysu@msn.com.

Feel free to use, share and modify these blocks in whatever way You and the community found useful.
I already send an email to Your @msn account.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.