Link to home
Start Free TrialLog in
Avatar of De_Wagter
De_Wagter

asked on

Urgent: ttyS0 is my stdin. Now I want to use ttyS0 for something else... HOW?

I have a micro Linux board (SSV DIL-PC) http://www.dilnetpc.com/.

Since it has no keyboard nor screen, it is set up to use /dev/ttyS0 as keyboard and console. But I need all the serial ports for my own application!

What happens now is that I can open the port and write to it without a problem in my own C++ program, but when receive a single byte, the port is "taken" from me, and first of all I did not receive the data, but also from then on I can not send anything anymore. It's like the Kernel claimed the port again (set ttyS0 back to 115200 instead of my 19200) etc...

How do I set /dev/null as system stdin and stdout so I can have my ttyS0 back for myself. (Linux 2.4 micro kernel with busybox compiled as an image)
Avatar of manish_regmi
manish_regmi

I thnik you can solve your problem using freopen

FILE *fp;
...
fp = freopen ("/dev/null", "w", stdout);


similarly do it for stdin

see man freopen

regards
Manish Regmi
Avatar of De_Wagter

ASKER

The command you suggest does exactly what it is supposed to do. I start the program from a telnet window. All stdin/stdout (=stdin/stdout from that telnet window) is redirected to /dev/null.

Unfortunately my problem is not solved with this, while I do like the trick though! Might be usefull later on...

I can still login via the serial port... this means the kernel still runs something that uses ttyS0... How do I get rid of this?
Kernel does not use it until it is told to do so.
Some demons might be using it.
If you dont need those daemons terminate all daemons/programs that uses it.

like telnetd, pppd might be using your serial port.

also replace /dev/ttys0 to something else in your inittab.

regards
Manish Regmi

ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the inittab had a getty on ttyS0 which runs a login server that screws up my application.

but:

the inittab is loaded from ROM that I am not allowed to change, so I still had the problem. But the comment from noci with the "kill -HUP 1" finally solved the trouble:

I made a good inittab in the flash that I am allowed to change. Then the board boots the bad inittab but runs the bootscript, which I am allowed to change. So in this script I copy the good inittabs with the runlevels as above to the /etc directory which is mounted in RAM. And thanks to the kill -HUP 1 command I was able to re-execute (this time the good) initab without having the bootloader overwriting my RAM again.

I would also lik to thank manish_regmi for his ideas and fast responses. You idea to replace the ttyS0 in inittabs would have worked if I were able to change it. Thanks for helping to identify the problem