From: Demetris Z. <fgc...@cy...> - 2007-06-25 19:44:13
|
My MCU is sending 1 (as in a byte 1) so i want to make the program stop at a point and wait for the Atmega to send "1" if 1 is send then continue with the program. if not then wait until it gets 1. with the code : > if ( read( gPortFd, &ch, 1 ) == 1 ) > { > //... got one character now... > } you are saying if if ( read( gPortFd, &ch, 1 ) equals to 1 then (do whatever) else continue. but i don't want to continue. I want to wait untill i get that 1 byte. Demetris Z. ----- Original Message ----- From: "Dave Hylands" <dhy...@gm...> To: "General mailing list for gumstix users." <gum...@li...> Sent: Monday, June 25, 2007 10:35 PM Subject: Re: [Gumstix-users] Serial Code Question > Hi Demetris, > > On 6/25/07, Demetris Zavorotnichenko <fgc...@cy...> wrote: >> By doing : >> >> if ( read( gPortFd, &ch, 1 ) == 1 ) >> { >> //... got one character now... >> } >> >> then if "read( gPortFd, &ch, 1 )" is equal to 0 then won't the program >> continue from there? > > It shouldn't ever return 0 if you've set things up right. It should > only return 1 to indicate that it read one character or -1 to indicate > that an error occurred. > > If you use fcntl and FNDELAY, then you can get a return of 0, but > otherwise it shouldn't happen. > > -- > Dave Hylands > Vancouver, BC, Canada > http://www.DaveHylands.com/ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > gumstix-users mailing list > gum...@li... > https://lists.sourceforge.net/lists/listinfo/gumstix-users |