Last active
November 21, 2022 12:47
-
-
Save Mte90/54f901ae350eb097e052 to your computer and use it in GitHub Desktop.
Firefox WebSerial API Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
if (Serial.available() > 0) { | |
Serial.println("I received the message: " + Serial.readString()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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