On 07 August 2007 16:35, Neil Jansen wrote: > I'm trying to write a serial port app with GCC. I need to insert a > 100ms delay between commands, and I'm trying to do with with the > usleep() function. When I do this it returns -1.
http://cygwin.com/acronyms#PPAST. It http://cygwin.com/acronyms#WJFFM. > Is there a way to get this to work, or possibly could someone > recommend another millisecond delay routine? The way to get it to work will probably turn out to be "using it correctly". My testcase: /artimi/chips $ cat us.c #include <stdio.h> #include <unistd.h> #include <errno.h> int main (int argc, const char **argv) { int rv, dtime; if (argc >= 2) { dtime = atoi (argv[1]); } else { dtime = 100 * 1000; } printf ("delay %dus. Start now:\n", dtime); fflush (NULL); rv = usleep (dtime); printf ("Finished... "); fflush (NULL); printf ("ret val %d errno %d\n", rv, errno); return 0; } /artimi/chips $ gcc -g -O2 -o us ./us.c /artimi/chips $ time ./us.exe delay 100000us. Start now: Finished... ret val 0 errno 0 real 0m0.266s user 0m0.171s sys 0m0.000s /artimi/chips $ time ./us.exe 1000000 delay 1000000us. Start now: Finished... ret val 0 errno 0 real 0m1.156s user 0m0.171s sys 0m0.000s /artimi/chips $ shows usleep working with no problems, so I think the bug is most likely in your program. cheers, DaveK -- Can't think of a witty .sigline today.... -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/