node-serialport icon indicating copy to clipboard operation
node-serialport copied to clipboard

Cannot read SerialPort data within a Worker Thread

Open FergusCoulter opened this issue 11 months ago • 1 comments

SerialPort Version

12.0.0

Node Version

22.12.0

Electron Version

No response

Platform

Linux pulse 6.6.63-v8+ #1824 SMP PREEMPT Tue Dec 3 12:59:39 GMT 2024 aarch64 GNU/Linux

Architecture

ARM

Hardware or chipset of serialport

No response

What steps will reproduce the bug?

This file calls the worker...

console.log("starting worker")
const gpsWorker = new Worker('./WorkerTest.js');

gpsWorker.on('message', (dt) =>{
    console.log("received message from worker to main thread")
    console.log(dt)
});
gpsWorker.on("error", (msg) => {
    console.log(msg);
});

Worker.js:

console.log("starting GPS worker service")
const gps = new GPSSetup();
// gps.SetupGPS();
// gps.ChangeUpdateRateAndLog();

const port = new SerialPort({
    path:'/dev/serial0',
    baudRate:115200
});
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }));

parser.on('data', (data) => {
    parentPort.postMessage(data)
});

What happens?

Trying to run SerialPort in a worker thread results in an error

2025-01-02T21:20:21.003Z serialport/bindings-cpp/unixRead read error [Error: EAGAIN: resource temporarily unavailable, read] {
  errno: -11,
  code: 'EAGAIN',
  syscall: 'read'
}
2025-01-02T21:20:21.004Z serialport/bindings-cpp/unixRead waiting for readable because of code: EAGAIN
2025-01-02T21:20:21.005Z serialport/bindings-cpp/poller Polling for "readable"
Segmentation fault

What should have happened?

I would expect the console to output the serial data

Additional information

No response

FergusCoulter avatar Jan 02 '25 21:01 FergusCoulter

Seems like a duplicate of #2748

andrei-tatar avatar Apr 14 '25 08:04 andrei-tatar