serialport / node-serialport

Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
https://serialport.io
MIT License
5.81k stars 1.01k forks source link

READ DATA SPLITTED #2677

Open ReisoAphi opened 1 year ago

ReisoAphi commented 1 year ago

SerialPort Version

11.0.1

Node Version

18.13.0

Electron Version

No response

Platform

Linux SYMMETRIC 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.38-1 (2023-07-14) x86_64 GNU/Linux

Architecture

x64

Hardware or chipset of serialport

No response

What steps will reproduce the bug?

I have this code and the issue is that im getting the read splitter in 9 different buffers, shouldn't it be in the same buffer ?

const { SerialPort } = require("serialport") const devices = new Array let indexerCollector = 0

const port = new SerialPort({ path: '/dev/ttyUSB0', baudRate: 4800, dataBits: 8, stopBits: 1,

})

port.on("data",(data)=>{ console.log(data)

}) port.open(()=>{ console.log("PORT OPEN") port.write(Buffer.from('020300000002C438','hex'),'hex') // port.write(Buffer.from('010300000002C40B','hex'),'hex') })
port.on("error",(err)=>{ console.log(err) })

What happens?

PORT OPEN <Buffer 02> <Buffer 03> <Buffer 04> <Buffer 00>

### What should have happened? I should be getting the buffer like this. ### Additional information _No response_
artapon commented 1 year ago

I found the problem too. Are you find anyway or solution to fixed this problem. Thank.

reconbot commented 1 year ago

The data comes in slower than the computer can process it. So you will need a parser to help buffer the data or interpret it.

https://serialport.io/docs/api-parsers-overview

https://serialport.io/docs/api-parser-inter-byte-timeout

https://serialport.io/docs/api-parser-byte-length