Solved

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

Posted on 2006-07-11
5
454 Views
Last Modified: 2010-08-05
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)
0
Comment
Question by:De_Wagter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:manish_regmi
ID: 17088792
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
0
 

Author Comment

by:De_Wagter
ID: 17093249
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?
0
 
LVL 8

Expert Comment

by:manish_regmi
ID: 17096175
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

0
 
LVL 40

Accepted Solution

by:
noci earned 500 total points
ID: 17097303
You probably need to disable a getty (or agetty etc.) command in your inittab and a "kill -HUP 1"
to reread the inittab.

Or better setup runlevels.

runlevel 0 = shutdown
runlevel 1 = single user
runlevel 2 = multiuser, no network
runlevel 3 = normal use
runlevel 4= application use
runlevel 6 = reboot.

Run level 4 is your special own mode.
then a line like

s0:12345:respawn:/sbin/getty ......

should be changed to

s0:1235:respawn:/sbin/getty

Not the missing 4...,
an on another place you could say:

ap:4:respawn:/usr/loca/myapp

and run myapp when in runlevel 4

The line
id:3:initdefault:
specifies the initial mode it starts in,
telinit 4
could be used to move on to level 4 manualy,
or replace the 3 by 4 and it will do it by default.
During boot you probably also can tell at what level to start after loading the kernel,
I have to refer you to the Micro Linux documentation for this.

0
 

Author Comment

by:De_Wagter
ID: 17155313
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
GUI development for Ubuntu 8 220
Replication of Nagios surveilance data 2 103
Ubuntu 16.04 Emergency Boot 2 231
Linux : when to add the entries in /etc/hosts file 22 104
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question