Skip to content

Cannot read SerialPort data within a Worker Thread #2974

Open
@FergusCoulter

Description

@FergusCoulter

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions