Have a terminal program always output/input to/from ttyS0 - Unix
This is a discussion on Have a terminal program always output/input to/from ttyS0 - Unix ; Hi,
I am writting a text mode UI program which use ncurses library.
Because this program will running on an embedded deveice, hence at
times I need to:
1, start it from a remote teminal runing on a telnet connection, ...
-
Have a terminal program always output/input to/from ttyS0
Hi,
I am writting a text mode UI program which use ncurses library.
Because this program will running on an embedded deveice, hence at
times I need to:
1, start it from a remote teminal runing on a telnet connection, but
has the UI program acts exactly like it were started from local
terminal ttyS0, that is, the UI program started from remote has to
output/input to/from the local ttyS0.
2, start the UI program from a script in backgroud, such as
#!/bin/bash
....
theUI &
othertask
....
How do I do? Thank you.
-
woody
-
Re: Have a terminal program always output/input to/from ttyS0
Steven Woody wrote:
> Hi,
>
> I am writting a text mode UI program which use ncurses library.
> Because this program will running on an embedded deveice, hence at
> times I need to:
>
> 1, start it from a remote teminal runing on a telnet connection, but
> has the UI program acts exactly like it were started from local
> terminal ttyS0, that is, the UI program started from remote has to
> output/input to/from the local ttyS0.
man newterm
(open /dev/ttyS0, passing the file pointers to newterm)
--
dickey@jtan.com
-
Re: Have a terminal program always output/input to/from ttyS0
On Apr 8, 7:25 am, dic...@invisible-island.net wrote:
> Steven Woody wrote:
> > Hi,
>
> > I am writting a text mode UI program which use ncurses library.
> > Because this program will running on an embedded deveice, hence at
> > times I need to:
>
> > 1, start it from a remote teminal runing on a telnet connection, but
> > has the UI program acts exactly like it were started from local
> > terminal ttyS0, that is, the UI program started from remote has to
> > output/input to/from the local ttyS0.
>
> man newterm
>
> (open /dev/ttyS0, passing the file pointers to newterm)
>
> --
> dic...@jtan.com
It did not work for me. Blow is a simple example, and I sit on /dev/
pts/0 hoping the program output/input on another terminal /dev/pts/1,
but the result is that everything just output/input on my current
virtual terminal /dev/pts/0. Would you please check where I made
wrong:
#include
#include
int main()
{
char mesg[]="Enter a string: ";
char str[80];
int row,col;
FILE *term = fopen( "/dev/pts/1", "r+" );
if ( term == NULL )
return 1;
SCREEN *s = newterm( "linux", term, term );
if ( s == NULL )
return 2;
if ( set_term( s ) == NULL )
return 3;
initscr();
getmaxyx(stdscr,row,col);
mvprintw(row/2,(col-strlen(mesg))/2,"%s",mesg);
getstr(str);
mvprintw(LINES - 2, 0, "You Entered: %s", str);
getch();
endwin();
delscreen( s );
return 0;
}
-
Re: Have a terminal program always output/input to/from ttyS0
On Apr 8, 11:18 am, Steven Woody wrote:
> On Apr 8, 7:25 am, dic...@invisible-island.net wrote:
>
>
>
> > Steven Woody wrote:
> > > Hi,
>
> > > I am writting a text mode UI program which use ncurses library.
> > > Because this program will running on an embedded deveice, hence at
> > > times I need to:
>
> > > 1, start it from a remote teminal runing on a telnet connection, but
> > > has the UI program acts exactly like it were started from local
> > > terminal ttyS0, that is, the UI program started from remote has to
> > > output/input to/from the local ttyS0.
>
> > man newterm
>
> > (open /dev/ttyS0, passing the file pointers to newterm)
>
> > --
> > dic...@jtan.com
>
> It did not work for me. Blow is a simple example, and I sit on /dev/
> pts/0 hoping the program output/input on another terminal /dev/pts/1,
> but the result is that everything just output/input on my current
> virtual terminal /dev/pts/0. Would you please check where I made
> wrong:
>
> #include
> #include
>
> int main()
> {
> char mesg[]="Enter a string: ";
> char str[80];
> int row,col;
> FILE *term = fopen( "/dev/pts/1", "r+" );
> if ( term == NULL )
> return 1;
> SCREEN *s = newterm( "linux", term, term );
> if ( s == NULL )
> return 2;
> if ( set_term( s ) == NULL )
> return 3;
> initscr();
> getmaxyx(stdscr,row,col);
> mvprintw(row/2,(col-strlen(mesg))/2,"%s",mesg);
> getstr(str);
> mvprintw(LINES - 2, 0, "You Entered: %s", str);
> getch();
> endwin();
> delscreen( s );
>
> return 0;
>
> }
Sorry, I just found the cause. I should not call initscr() when use
newterm(). When removed it, the program almost behavior right.
But still have problems: while the program output on /dev/pts/1, it
did not get the inputs from there correctly. It's likely the inputs
was got firstly by the 'bash' running on the /dev/pts/1. As, you
know, the logic of the program is to ask me input a string, then print
the string, then wait for anykey before exit. Now, the behaviour is:
1) I started the program on /dev/pts/0, I saw nothing on /dev/pts/0.
( this is right )
2) I went to the /dev/pts/1 and saw "Enter a string: " on the screen.
( this is also right )
3) I input 'good' and then a 'enter' key on /dev/pts/1 and saw the
'good' echoed on /dev/pts/1. ( this seems right )
4) I pressed 'enter' key on the /dev/pts1
5) on the /dev/pts1, I saw an error string printed: "-bash: good:
command not found", and the bash command prompt apears. ( this is not
what I wanted, you see, the 'good' string was got by `bash' running on
the /dev/pts/1 )
6) I pressed 'enter' key again on /dev/pts/1, this key was got by my
program, then the program printed "You Entered: ", I guees, what he
really said is "You Entered: ", just the is not
visible. So I believe, the second `enter' key was captured by my
program.
7) I pressed any key on the /dev/pts/1, my program on the /dev/pts/0
existed and the command prompt on the /dev/pts/0 appeared again. This
seemed normal.
Did you see my problem?
Thanks.
-
woody
-
Re: Have a terminal program always output/input to/from ttyS0
Steven Woody wrote:
> On Apr 8, 7:25 am, dic...@invisible-island.net wrote:
>> Steven Woody wrote:
....
>> > 1, start it from a remote teminal runing on a telnet connection, but
>> > has the UI program acts exactly like it were started from local
>> > terminal ttyS0, that is, the UI program started from remote has to
>> > output/input to/from the local ttyS0.
....
> It did not work for me. Blow is a simple example, and I sit on /dev/
> pts/0 hoping the program output/input on another terminal /dev/pts/1,
> but the result is that everything just output/input on my current
> virtual terminal /dev/pts/0. Would you please check where I made
> wrong:
I'm puzzled why you're opening a pty, when the issue was to open a
specific ttyS0.
--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net