Skip to content

Instantly share code, notes, and snippets.

@Mte90
Last active November 21, 2022 12:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mte90/54f901ae350eb097e052 to your computer and use it in GitHub Desktop.
Save Mte90/54f901ae350eb097e052 to your computer and use it in GitHub Desktop.
Firefox WebSerial API Test
/* Try it in Scatchpad */
var serial = new SerialPort();
/* Change the port with yours */
serial.port = '/dev/ttyACM0';
console.log('Serial open? ' + serial.open());
console.log('Send text to the port serial');
serial.write('WebSerial API form Firefox!');
/* Little delay of 2 second for read the output form Arduino */
setTimeout(function () {
temp = serial.readline();
temp = temp.replace(/(\r\n|\n|\r)/gm,"");
console.log('Output form Serial port: ' + temp);
console.log('Close connection');
serial.close();
}, 2000);
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
Serial.println("I received the message: " + Serial.readString());
}
}
Download from https://bugzilla.mozilla.org/show_bug.cgi?id=926940 the development build with the WebSerial API
Screenshot: https://plus.google.com/u/0/+DanieleScasciafratteMte90Net/posts/EED6sbEt2zv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment