Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!spool.mu.edu!usenet.eel.ufl.edu!news.mathworks.com!nntp.primenet.com!mr.net!news.ios.com!news2.ios.com!news.gsini.net!gsi.gsini.net!jvarsoke From: jvarsoke@gsi.gsini.net () Newsgroups: comp.unix.bsd.bsdi.misc,comp.unix.programmer Subject: open ("/dev/tty01", . . . Date: 19 Aug 1996 17:40:45 GMT Organization: GSI Internet Services, Inc. Lines: 67 Message-ID: <4va8ut$lcg@isis.gsini.net> NNTP-Posting-Host: gsi.gsini.net X-Newsreader: TIN [version 1.2 PL2] Xref: euryale.cc.adfa.oz.au comp.unix.bsd.bsdi.misc:4649 comp.unix.programmer:41740 I'm writing a serial comm program and one particular thing is plaguing me. When I issue the open() function the program will hang until I kill it, unless I specify O_NONBLOCK. I'm using a timer in the sample code below to avoid this enormous wait. If I specify O_NONBLOCK in the open() then the file descriptor is returned and everything is hunky-dory, except the device obviously doesn't block. I've tried various functions to turn off the non-blocking status, but to no avail. fcntl(), and ioctl() didn't seem to make the i/o block. here's the open command which works: fd = open (modem, O_RDWR|O_NOCTTY|O_NONBLOCK, 0); the following hangs: fd = open (modem, O_RDWR|O_NOCTTY|O_NONBLOCK, 0); OK, now it gets a little stranger. . . If I use the /usr/bin/tip program before I execute the second open statement (above), everything is fine. The device it opened and it blocks. Actually, ever after that first instance of the tip program on the same device, my second open command will work. Reboot, and same situation as the first time. Also of note: before tip is run the TR (terminal ready) light on the modem is on, after tip is run, the TR light is off. OK so my question is this... Why does this all happen. OR How can I turn the TR light off before opening the device? Please E-Mail me any answers at: jvarsoke@gsi.gsini.net Thanks. -j A portion of the modem init code follows: int init_modem (char *modem) { struct termios term; struct itimerval it; int fd = 0; printf ("Opening Modem %s . . . ",modem); fflush (stdout); fd = open (modem, O_RDWR|O_NOCTTY|O_NONBLOCK, 0); if (fd) printf ("success\n"); close(fd); fd = 0; printf ("Opening Modem %s . . . ",modem); fflush (stdout); timerclear (&it.it_interval); it.it_value.tv_sec = 5; it.it_value.tv_usec = 0; signal (SIGALRM, timeout); setitimer (ITIMER_REAL, &it, (struct itimerval *) NULL); if (setjmp(env) == 0) { fd = open (modem, O_RDWR|O_NOCTTY, 0); } if (fd) printf ("success\n"); else return 0; (other stuff deleted) } -jvarsoke@gsi.gsini.net