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