home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / programm / 4674 < prev    next >
Encoding:
Text File  |  1992-09-15  |  1.5 KB  |  60 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!hellgate.utah.edu!dog.ee.lbl.gov!news!nosc!usenet
  3. From: geurin@texasex.nosc.mil
  4. Subject: Please Help with buffered serial I/O in SunOS
  5. Message-ID: <1992Sep16.013718.1525@nosc.mil>
  6. Sender: usenet@nosc.mil (Network News)
  7. Organization: Naval Ocean Systems Center, San Diego, CA
  8. Date: Wed, 16 Sep 1992 01:37:18 GMT
  9. Lines: 49
  10.  
  11.  
  12. Howdy-
  13.  
  14. I have a problem getting a read() to /dev/ttya (or ttyb) to return
  15. when there aren't any characters to be read.  I did set the O_NDELAY
  16. flag when opening the device:
  17.  
  18.  
  19.   if ((sp_id = open(com,O_RDWR|O_NDELAY)) == -1)
  20.     return(0);
  21.  
  22.   ioctl(sp_id,TIOCFLUSH,0);
  23.   ioctl(sp_id,TIOCEXCL,0);
  24.   ioctl(sp_id,TIOCGETP,&tty);
  25.   tty.sg_ospeed=B9600;
  26.   tty.sg_ispeed=B9600;
  27.   tty.sg_flags=ANYP|RAW|TANDEM;
  28.   ioctl(sp_id,TIOCSETP,&tty);
  29.  
  30.  
  31. Whenever a read() is executed, and there no chars to be read, read should
  32. return 0 for the number read, no?  Well, whenever I issue a read(),
  33. the program just hangs there, waiting on something from the serial port.
  34.  
  35. So, I tried using select():
  36.  
  37.  
  38.   FD_ZERO(&fdset);
  39.   FD_SET(sp_id, &fdset);
  40.   if (select(ulimit(4,0), &fdset, 0, 0, 0) <0) {
  41.     perror("select");
  42.     exit(1);
  43.   }
  44.   if (FD_ISSET(sp_id, &fdset)) {
  45.     numrd = read(sp_id,&ch,1);
  46.  
  47.   etc...
  48.  
  49.  
  50. Now, select() never returns!  ulimit() returns OK (64).
  51.  
  52. I must be missing something really basic, if both are waiting on
  53. the serial port.
  54.  
  55. Please forgive if this is a stupid question.
  56.  
  57. Any/All help will be greatly appreciated!
  58. Chance Geurin
  59. geurin@nosc.mil
  60.