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, <type:8>, <counter:8>, <length:8>, data:length>, <crc:16>]

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