khanning / scratch-arduino-extension

Javascript extension to connect Scratch 2.0 with Arduino using Firmata
83 stars 91 forks source link

Race condition #31

Open cactrot opened 9 years ago

cactrot commented 9 years ago

Chrome 45 windows 8.1 probably affects others using a HC-06 bluetoooth to serial adapter

With my setup line: 507 "set_receive_handler" callback would be processed before line: 506

"device.open" would finish, so the device was not set when it was called and it would return without

setting the receive handler.

So I tried moving the "set_receive_handler" call to the ready callback for "device.open".

I was able to connect and set the LED pins. Although the readback was a little spotty.

I think the polling function might need some fine turning for the high latency.

console.log('Attempting connection with ' + device.id);
    device.open({ stopBits: 0, bitRate: 57600, ctsFlowControl: 0 }, function() {
      device.set_receive_handler(function(data) {
        var inputData = new Uint8Array(data);
        processInput(inputData);
      });
    });
davecraig commented 6 years ago

Ah yes, I see this too. I started writing a bit of a Firmata port for Microbit and hit the same issue.