From: Ryan R. <rjr...@uc...> - 2008-01-10 21:01:21
|
This code reliably syncs the read to the beginning of the packet and ensures that you get all of your characters. Just make sure that the first two characters you send for each packet are 0x55 and the port is set up as in the last email. while(!packetAcquired) { read(pax_port,buf1,1); if(buf1[0] == 0x55) { read(pax_port, buf2, 1); if(buf2[0] == 0x55 ) { buf[0] = buf1[0]; buf[1] = buf2[0]; n = read(pax_port,buf+2,58); packetAcquired = 1; } } } you'll get your data packet, including the 0x5555 header, in buf[]. Ryan On Thu, 2008-01-10 at 22:53 +0200, Demetris Zavorotnichenko wrote: > Tnx Guys, I'll try this and see what happends. > > I appreciate the help allot. > > -----Original Message----- > From: gum...@li... > [mailto:gum...@li...] On Behalf Of Dave > Hylands > Sent: Thursday, January 10, 2008 10:44 PM > To: General mailing list for gumstix users. > Subject: Re: [Gumstix-users] Serial C question > > Hi Demetris, > > On Jan 10, 2008 12:42 PM, Demetris Zavorotnichenko > <fgc...@cy...> wrote: > > So how would I di this so I could receive 18 characters ? > > This page explains the VMIN and VTIME parameters. > <http://unixwiz.net/techtips/termios-vmin-vtime.html> > > Basically, you'd need to set VMIN = 18, and VTIME = 0 > > Of course, if you do some other read of a different length, then you'd > need to keep changing VMIN. > > Personally, I'd create a routine that just reads single characters and > returns after it got 18. Then you don't need to keep resetting the > termios parameters. > |