NodeJS Serialport Data Read

Viewed 15

I have a serial data read question.

I have a serial device that responds to commands with an ack (0x06) or error (0x21)

To start data flow, I need to send a certain command, wait for the ACK, then send the data request command... And collect the 18 byte, non-terminated data. Then resend the data request after a couple of seconds.

Currently, I am using the 'on read' signal from the port. This works...however, the read event mostly fires for each byte read and sometimes if fires and reads two bytes of data.

So... Question is... How can I ensure the after I send the data request that I collect JUST the 18 bytes of the response message?

Will this require checking the size of each data read from the port and splitting it up into aingle-byte chunks?

From what I could tell, a parser might work, but I could not tell how to kick off the parser read after the ACK, and then stop after reading 18 bytes, the start again after then next ACK.

Any help or thoughts would be appreciated.

0 Answers
Related