From: Joel VanderWerf Date: 2005-12-19T06:04:53+09:00 Subject: Re: Better way to read data from IO into packets? Levin Alexander wrote: > Hi, > > I have a small program, that reads data from a serial port and chops > it into packets. A Packet has the following format: > > [0x65, 0xEB, , , , data:length>, ] Why not read enough bytes to make sure you get the length byte: s = io.sysread(5) len = s[4] s << io.sysread(len+2) ary = s.unpack "C5a#{len}n" Or is the problem that there may be a variable number of "start bytes"? In that case, maybe you could tell from the first 5 bytes how many start bytes there are, and then read enough to capture the length byte. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407