How do you control echoing of chars with getchar() etc?

Discussion to talk about software related topics only.
Post Reply
barttech
Posts: 135
Joined: Fri Feb 20, 2009 12:59 pm

How do you control echoing of chars with getchar() etc?

Post by barttech »

My app is echoing every char that getchar() receives. I don't want them to be echoed, how can I avoid this? I've tried ioctl() but can't get it to make any difference. Any sample code would be appreciated. I'm using:
SerialClose( 0 ); // close UART 0
fdSerial = OpenSerial( 0, 115200, 1, 8, eParityNone );
ReplaceStdio( 0, fdSerial ); // stdin
ReplaceStdio( 1, fdSerial ); // stdout
ReplaceStdio( 2, fdSerial ); // stderr
I've tried:
ioctl(fdSerial,8); //IOCTL_RX_ECHO (8) When set echo chars received to tx
Of ioctl() the manual says: "The ioctl command consists of IOCTL_SET or IOCTL_CLR and the bit of the associated options. "
but I don't know how to use IOCTL_SET or IOCTL_CLR.
Thanks,
Sam
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: How do you control echoing of chars with getchar() etc?

Post by rnixon »

How about using read() instead?
barttech
Posts: 135
Joined: Fri Feb 20, 2009 12:59 pm

Re: How do you control echoing of chars with getchar() etc?

Post by barttech »

read() echoes too. I don't think getchar() echoed until I tried using ioctl() to control LF and CR being appended to output. Could ioctl() have changed something?
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: How do you control echoing of chars with getchar() etc?

Post by rnixon »

I think something is going on with your app or the serial terminal you are using. read() should not echo, it just fills the buffer you pass as a parameter.
ahbushnell
Posts: 25
Joined: Thu Apr 24, 2008 7:45 pm

Re: How do you control echoing of chars with getchar() etc?

Post by ahbushnell »

Are you sure your terminal software doesn't have echo turned on?
barttech
Posts: 135
Joined: Fri Feb 20, 2009 12:59 pm

Re: How do you control echoing of chars with getchar() etc?

Post by barttech »

Neither my terminal program (uCon) nor my application were explicitly echoing. As I expected, the call to gets() was echoing.
This is what I needed to do:
ioctl(2,IOCTL_CLR|IOCTL_RX_ECHO);
Of the second parameter for ioctl, the NetBurnerRuntimeLibraries.pdf says
"The ioctl command consists of IOCTL_SET or IOCTL_CLR and the bit of the associated options. "
so I was trying IOCTL_CLR&IOCTL_RX_ECHO, based on the "and". When I looked into ioctl.h I saw my mistake.
Sam
Post Reply