You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
I am having issues opening/closing character devices in Node. How does one properly open and close a character device (i.e. a serial port or TTY device) for reading and writing?
Here's my little program that doesn't quite work as expected:
var fs = require("fs");
fs.open("/dev/ttyUSB0", "r+", function(err, fd) {
if(err) throw err;
var input = fs.createReadStream("/dev/ttyUSB0", {"fd": fd});
input.on("data", function(chunk) {
console.log("in:", chunk);
});
var out = fs.createWriteStream("/dev/ttyUSB0", {"fd": fd});
console.log("out:", "ATZ\r\n");
out.write("ATZ\r\n");
setTimeout(function() {
console.log("Closing file...");
fs.close(fd, function(err) {
console.log("File has been closed", err);
// At this point, Node will just hang
});
}, 5000).unref();
});