Search code examples
node.jsnode-serialport

node.js serialport - TypeError: "offset" is not an integer


I'm trying to open up a serial port and read incomming data:

const SerialPort = require('serialport');

var port = new SerialPort(
  "/dev/ttyUSB0",
  { baudRate: 115200 }
);

port.on('data', data => {
  console.log(data);
});

port.on('error', err => {
  console.log('Error', err);
});

port.on('close', err => {
  console.log('Closed', err);
});

The above example fails with TypeError: "offset" is not an integer whenever new data arrives:

Closed { TypeError: "offset" is not an integer
    at LinuxBinding.read (/home/kristupas/projects/node-factory-worker/node_modules/@serialport/binding-abstract/binding-abstract.js:89:13)
    at LinuxBinding.read (/home/kristupas/projects/node-factory-worker/node_modules/@serialport/bindings/lib/linux.js:63:17)
    at SerialPort._read (/home/kristupas/projects/node-factory-worker/node_modules/@serialport/stream/stream.js:374:16)
    at SerialPort.Readable.read (_stream_readable.js:462:10)
    at maybeReadMore_ (_stream_readable.js:610:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:17) disconnected: true }

I've tried @serialport/terminal (source here) and it works like intended, so clearly something is wrong with my code, however as far as I can tell I'm following the documentation correctly.


Solution

  • Which version of serialport are you using? Make sure you're not using the 8.0.0 branch.