You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Ahh - the interpreter isn't multi-threaded so it relies on having short functions that finish relatively quickly. When you get data from serial it goes into a Queue, and that queue is handled in the 'idle' loop - so it's expected that what you're doing there won't work.

    The best bet is to use on('data' as you say. If you post up details of what you've got then I can try and see why it's not working?

    As a start, you could try:

    var dataLine = "";
    Serial6.on('data',function(d) {
      dataLine += d;
      var idx = dataLine.indexOf("\n");
      while (idx>=0) {
        var command = dataLine.substr(0,idx);
        soStuffWith(command);
        dataLine = dataLine.substr(idx+1);
        idx = dataLine.indexOf("\n");
      }
    });
    
About

Avatar for Gordon @Gordon started