c - Reading data on serial port - byte by byte -


how read data on serial port in byte byte fashion.

i have source sends out packets of varying packet size. reading data in raw mode(non-canonical). when set vmin, able packet of size or larger. ex: if received packet size 46 bytes, , if set vmin '1'. receive data in 2 chunks(meaning 2 read calls needed complete data 1 fetching first 32 , next fetching rest 14 bytes). if set vmin 46, complete packet fetched.

but problem here varying packet size. if data packet size more(say 70 bytes), mess buffer , following reads reads 60+ bytes in first read , rest in next read.

so thinking read data byte byte , determine end of packet.

does know if do-able. or suggestion on how read complete data packet in 1 read operation.

uart setting: baud: 115200 no parity. 1 stop bit. 8n1. no flow control.

thanks in advance.

a approach for processing serial data read chunks of data port buffer , pull byte byte buffer.

serial port reading affected timeout settings , incoming data flow, number of bytes per read not guaranteed consistent. example, if knew packets going 46 bytes, might think set vmin 46 , expect 46 bytes per read. however, if sending source sends multiple packets without delays between, might of 1 , part of packet. if sending source delay during transmission of packet longer receiving port's timeout, fewer vmin bytes.

be sure code possibility of lost data. example, let's packets start , ends . start pulling data buffer , first byte , 49 bytes later encounter meaning new packet, without having seen previous packet. there should of course crc packet, or @ least checksum.


Comments