Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial port communication does not work inside a Worker #29698

Closed
hugo-a-garcia opened this issue Sep 25, 2019 · 1 comment
Closed

Serial port communication does not work inside a Worker #29698

hugo-a-garcia opened this issue Sep 25, 2019 · 1 comment
Labels
addons Issues and PRs related to native addons. question Issues that look for answers. worker Issues and PRs related to Worker support.

Comments

@hugo-a-garcia
Copy link

  • Version: v12.10.0
  • Platform: Linux
  • Subsystem: Using module node-serialport

We are trying to narrow down the issue of why a serial port cannot be opened in a worker. I has been suggested that maybe there is a bug in worker_thread (???) Maybe someone can verify if this is a bug OR give us some guidance to figure it out please?

This is the issue that can be referenced at node-serialport:

Serial port commnunication does not work inside a Worker Thread #1938

This is the repo with the example code:

hugo-a-garcia/serial-worker

and here is the main code:

const {
   Worker, isMainThread, parentPort, workerData
} = require('worker_threads');

const SerialPort = require("serialport");
   const Readline = SerialPort.parsers.Readline;

if (isMainThread) {
   console.log("In main thread");

   const worker = new Worker(__filename);
   worker.on('message', msg => {
      console.log(msg);
   });
   worker.on('error', err => {
      console.error("Oops " + err)
   });
   worker.on('exit', (code) => {
      if (code !== 0)
         console.log(`Worker stopped with exit code ${code}`);
   });

} else {
   console.log("In worker thread");
 
   const port = new SerialPort("/dev/ttyACM0", {
       baudRate: 9600
   });
   
   const parser = new Readline
   port.pipe(parser);
   parser.on("data", (data) => console.log(data));
   
   // port.on('readable', function () {
   //     console.log(port.read().toString());
   // });
   
   port.on('error', function (err) {
       console.log('Error: ', err.message);
   });

   parentPort.postMessage("Done.");
}
@addaleax addaleax added addons Issues and PRs related to native addons. question Issues that look for answers. worker Issues and PRs related to Worker support. labels Sep 25, 2019
@addaleax
Copy link
Member

Not a bug with Node.js, see serialport/node-serialport#1938 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addons Issues and PRs related to native addons. question Issues that look for answers. worker Issues and PRs related to Worker support.
Projects
None yet
Development

No branches or pull requests

2 participants