• Well, there's:

    SerialX.on('data', function(s) {
      s.split("").forEach(obj.onData);
    });
    

    But what I tend to do is handle a line at a time, which I think is easier?

    var line = "";
    SerialX.on('data', function(s) {
      line += s;
      var i = line.indexOf("\n");
      while (i>=0) {
        handleLine(line.substr(0,i));
        line = line.substr(i+1);
        i = line.indexOf("\n");
      }
    });
    
About

Avatar for Gordon @Gordon started