[ECOS] Trouble doing serial console I/O in C++

Paul D. DeRocco pderocco@ix.netcom.com
Fri Jul 27 21:22:00 GMT 2007

System: EB40A (ARM7), RAM app debugged over 1st serial port. eCos includes
both tty and termios drivers for the second serial port. I'm trying to do
ordinary console-like line-at-a-time I/O using C++ fstreams. The obvious

	fstream* f = new fstream("/dev/tty1");
	string l;
	getline(f, l, '\n');

doesn't work, because it waits for me to enter 256 characters, rather than
terminating the read on the Enter key. That problem is occurring in fread(),
since it repeatedly reads until it gets the total requested number of bytes.
That seems wrong. It also echoes everything as I type, and then a second
time when it has read the 256 characters. (No, my terminal program is NOT
configured for local echo.)

I tried

	char b;
	f->rdbuf()->pubsetbuf(&b, 1);

That makes it respond correctly to the Enter key, since the fstream is doing
single-character fread() calls, but it echoes each individual character
twice, and also for some reason the backspace doesn't work.

I've tried termios, and it does the same thing, although backspace is even
buggier. I've tried opening a separate ifstream and ofstream. I've tried
tying the ifstream and the ofstream. Nothing works right.

Has anyone figured out how to get fstreams on serial ports to work
correctly? Or is there a way to get cin and cout to map to this device?
(What the heck to cin/cout, or for that matter stdin/stdout, connect to,


Ciao,               Paul D. DeRocco
Paul                mailto:pderocco@ix.netcom.com 

Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

More information about the Ecos-discuss mailing list