You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Looks good - the only thing I can see is in some functions you access the object directly with DMX but you should really be using this (or it'll fail if you call the object anything else).

    As you might have found out, it's slightly more painful than that though - you need to use bind:

    this.serial.on( 'data', this.newData.bind(this) ); // <----
    
    // Handle new bytes of data as they come in
    DMX.prototype.newData = function( d ) {
      // Store the bytes received at the buffer index
      this.data.set( d, this.id );
      
      // Move the buffer index along.
      this.id += d.length;
    };
    

    and the same for the end of frame marker too...

    Other thing I'd say is maybe calling all the handlers could end up being quite slow - I'm not sure. You'd have to be careful that the new frame handler didn't take so long that you missed data.

  • I was using this but it doesn't work for some reason... it says:

    Uncaught Error: Field or method "set" does not already exist, and can't create it on undefined at line 3 col 12...

    Specifically this doesn't exist inside that DMX.prototype.newData function, or indeed inside any other than the first one DMX()...

    I also don't know what you mean about bind, but I tried adding this and it also didn't work.

About

Avatar for Gordon @Gordon started