[comp.unix.aix] TTY without echos

shawn@jdyx.UUCP (Shawn Hayes) (03/26/90)

     I'm trying to set up a program to read and write characters to a tty
port.  What I would like to have happen is I read a character from the port
and if it's a numeric character I echo it back, and if it is anything else
I ignore it.  Currently I can type in alphabetic characters and they are ignored
, but as soon as I echo a numeric character back to the terminal the port
echoes every character. 

   I've set up the port with a  stty -echo -echoe -echok raw
but something must still be wrong in the setup.  Is there a way to configure
a tty port to never echo characters, so that only the output from my program
shows up on the port?

                                                         Shawn Hayes

penneyj@servio.UUCP (D. Jason Penney) (03/27/90)

[100 lashes with a wet noodle for anyone who doesn't post enough 
return address that one can follow up with e-mail!]

In article <1990Mar25.170947.2415@jdyx.UUCP> shawn@jdyx.UUCP (Shawn Hayes) writes:
>
>     I'm trying to set up a program to read and write characters to a tty
>port.  What I would like to have happen is I read a character from the port
>and if it's a numeric character I echo it back, and if it is anything else
>I ignore it.  Currently I can type in alphabetic characters and they are ignored
>, but as soon as I echo a numeric character back to the terminal the port
>echoes every character. 
>
>   I've set up the port with a  stty -echo -echoe -echok raw
>but something must still be wrong in the setup.  Is there a way to configure
>a tty port to never echo characters, so that only the output from my program
>shows up on the port?
>
>                                                         Shawn Hayes

You don't say what brand of pUnyx you're running, but I suppose from the
Newsgroups line that it's some form of AIX.  I strongly recommend setting
the terminal into RAW mode directly from within your program (i.e., 

c_lflag &= ~(HUPCL | ICANON | ISIG | ECHO),
c_cc[VMIN] = 1, c_cc[VTIME] = 0).

Note: the BSD incantation is somewhat different from this...

I suspect from your description that you're using stdio to do the 
echoing.  It could possibly be the case that stdio clears these flags.

Workaround:  use sprintf() to build the strings and then use write(2) 
to output the characters to the screen.  This works like a champ for me 
in all pUnyx variants.
-- 
D. Jason Penney           Ph: (503) 629-8383
Beaverton, OR 97006       uucp: ...uunet!servio!penneyj (penneyj@slc.com)
"Talking about music is like dancing about architecture." -- Steve Martin

guy@auspex.auspex.com (Guy Harris) (03/28/90)

>I strongly recommend setting the terminal into RAW mode directly
>from within your program (i.e., 
>
>c_lflag &= ~(HUPCL | ICANON | ISIG | ECHO),
>c_cc[VMIN] = 1, c_cc[VTIME] = 0).

Well:

	1) HUPCL has nothing to do with "raw mode";

	2) you may or may not want to turn ISIG off.  Turning it off
	   means your interrupt character (^C, <DEL>, whatever) has no
	   effect; leaving it on means that it still generates the
	   appropriate signal.  If you *do* want to be able to interrupt
	   things with ^C or <DEL> or whatever, leave it on, but
	   remember to *catch* the SIGINT signal and restore the tty
	   modes back to their original values before exiting.

>Note: the BSD incantation is somewhat different from this...

BSD RAW mode turns off the signal characters; BSD CBREAK mode doesn't,
just as turning ICANON off doesn't.

>I suspect from your description that you're using stdio to do the 
>echoing.  It could possibly be the case that stdio clears these flags.

The only terminal "ioctl" function every standard I/O implementation I
know of does is the one to read the current settings, and it only does
that to see if a file descriptor refers to a terminal.  None of them
change the settings; it's conceivable that some broken implementation
out there does, but it's unlikely.