home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / linux / 20223 < prev    next >
Encoding:
Text File  |  1992-12-13  |  2.0 KB  |  58 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!mcsun!fuug!prime!mits!kennu
  3. From: kennu@mits.mdata.fi (Kenneth Falck)
  4. Subject: Re: How read characters from /dev/modem/ using C?
  5. Organization: Microdata International Telecomm Service, Helsinki, Finland
  6. Date: Sun, 13 Dec 1992 23:28:47 GMT
  7. Message-ID: <1992Dec13.232847.13223@prime.mdata.fi>
  8. References: <1ggc66INNafl@usenet.INS.CWRU.Edu>
  9. Sender: usenet@prime.mdata.fi (Usenet poster)
  10. Nntp-Posting-Host: mits.mdata.fi
  11. Lines: 45
  12.  
  13. cc935@cleveland.Freenet.Edu (Gerrold T. Sithe) writes:
  14. >         I'm trying to write a C program that executes a chat script with a
  15. > dialup system.  I run my program with input and output redirected to the modem:
  16. > a.out </dev/modem >/dev/modem
  17. >         Using scanf to read from the modem doesn't work well because the remote
  18. > system doesn't end it's query lines with a newline.  So the prompt, "Enter
  19. > Command?" doesn't get received until later.  No good for a chat script.
  20. >         So I went to a character based input using getchar.  Still the modem
  21. > driver won't return a line of data until it receives a newline from the remote
  22. > system.  I then tried using the system IO calls open and read with no success.
  23. >         How can I access the modem on a character-by-character basis or have it
  24. > return lines without receiving a newline?
  25.  
  26. You should use non-canonical input (whatever that means), i.e. 
  27. either use stty from the shell:
  28.  
  29.  stty -icanon -isig -echo
  30.  
  31. or termios:
  32.  
  33.  #include <termios.h>
  34.  
  35.  struct termios tty;
  36.  
  37.  tcgetattr (STDIN_FILENO, &tty);
  38.  tty.c_lflag &= ~(ISIG|ICANON|ECHO);
  39.  tcsetattr (STDIN_FILENO, TCSANOW, &tty);
  40.  
  41. to set up the terminal. See `man stty' and `man termios' for
  42. more info about those flags... (I think some systems also require
  43. that you set tty.c_cc [VTIME] = 0 and [VMIN] = 1 or something. I 
  44. think /usr/include/linux/termios.h will also be a good file to read.)
  45.  
  46. Of course, you can open /dev/modem from within the program and use
  47. it's fileno instead of STDIN_FILENO...
  48.  
  49. -- 
  50. kennu@mits.mdata.fi
  51.