Yes, @DrAzzy's right. fs.read will block, but when you send data it's stuck in an output buffer. That buffer is 128 characters, so as long as you send less than that, Espruino won't block.
I don't think there are any functions to tell how full that output buffer is though, so you'll need to use setTimeout between calls to Serial.write to make sure you don't send data faster than the UART can take it.
eg.
function sendData() {
var moreData = getMoreData();
Serial1.write(moreData);
setTimeout(sendData, moreData.length*10000/baudRate);
}
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Yes, @DrAzzy's right.
fs.read
will block, but when you send data it's stuck in an output buffer. That buffer is 128 characters, so as long as you send less than that, Espruino won't block.I don't think there are any functions to tell how full that output buffer is though, so you'll need to use
setTimeout
between calls toSerial.write
to make sure you don't send data faster than the UART can take it.eg.