Serial device. Assumes data is sent with new line characters (\r\n) between messages.
import { Serial } from'https://unpkg.com/ixfx/dist/io.js' consts = newSerial.Device(); s.addEventListener(`change`, evt=> { console.log(`State change ${evt.priorState} -> ${evt.newState}`); if (evt.newState === `connected`) { // Do something when connected... } });
// In a UI event handler... s.connect();
Reading incoming data:
// Parse incoming data as JSON s.addEventListener(`data`, evt=> { try { consto = JSON.parse(evt.data); // If we get this far, JSON is legit } catch (ex) { } });
Serial device. Assumes data is sent with new line characters (\r\n) between messages.
Reading incoming data:
Writing to the microcontroller