* Re: Re: [ECOS] Select() issues
@ 2007-01-10 16:28 Andre-John Mas
2007-01-11 18:20 ` Andrew Lunn
0 siblings, 1 reply; 3+ messages in thread
From: Andre-John Mas @ 2007-01-10 16:28 UTC (permalink / raw)
To: Andrew Lunn; +Cc: ecos-discuss
Andrew Lunn wrote:
>
> > struct termios ts, ots; /* termios setting, old termios setting */
> > int fd = STDIN_FILENO;
>
> Im not an eCos termios expert, but shouldn't this be a file handle
> returned by opening /dev/termios0 and not standard in?
>
> Andrew
>
On 10-Jan-07, at 10:32 , Andrew Lunn wrote:
struct termios ts, ots; /* termios setting, old termios setting */
int fd = STDIN_FILENO;
Im not an eCos termios expert, but shouldn't this be a file handle
returned by opening /dev/termios0 and not standard in?
Andrew
Up until this particular issue I have had no problems using "standard in".
I will look to see what effect opening /dev/termios0, but most examples
I have seen use STDIN_FILENO directly.
Changing my code slightly, I now find that I now block at cin.get().
I wondering whether I am doing something wrong when changing to canocial
mode?
char InputHandler::DoPressAnyKey()
{
struct termios ts, ots;
int c = 0;
int fd = STDIN_FILENO;
cout << "--0\n";
tcflush(fd,TCIOFLUSH);
cout << "--1\n";
WaitForData();
tcgetattr(fd, &ts); /* save tty state */
ots = ts; /* structure copy */
ts.c_lflag &= ~( ICANON );
ts.c_cc[VMIN] = 1;
ts.c_cc[VTIME] = 0;
tcsetattr(fd, TCSAFLUSH, &ts);
cout << "--2\n";
// INFO: make sure to reset terminal attributes before
// leaving method
if ( !IsTimedOut() )
{
cout << "--2.1\n";
c = cin.get();
cout << "--2.2\n";
}
cout << "--3\n";
tcsetattr(fd, TCSAFLUSH, &ots); /* restore TTY state */
cout << "--4\n";
if ( IsTimedOut() )
{
c = 0;
}
return c;
}
void InputHandler::WaitForData()
{
int fd = STDIN_FILENO;
fd_set fds;
struct timeval tv;
struct timeval *tvPtr = NULL;
cout.flush();
do
{
// INFO: if the time out is not zero then define the timeval and have tvPtr
// refer to it. if it is zero then tvPtr uses a NULL value. I things this
// way to avoid having to duplicate the select call and also not need to
// worry about memory allocation/deallocation
cout << "--a\n";
if ( this->timeout != 0 )
{
tv.tv_sec = this->timeout;
tv.tv_usec = 0;
tvPtr = &tv;
}
else
{
tvPtr = NULL;
}
FD_ZERO( &fds );
FD_SET( STDIN_FILENO, &fds );
cout << "--b\n";
int result = select(fd + 1, &fds, NULL, NULL, tvPtr);
cout << "--c\n";
if ( result == 0 )
{
this->timedout = true;
break;
}
else if ( result > 0 && FD_ISSET(fd,&fds) )
{
break;
}
cout << "--d\n";
}
while ( true );
cout << "--e\n";
}
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Re: [ECOS] Select() issues
2007-01-10 16:28 Re: [ECOS] Select() issues Andre-John Mas
@ 2007-01-11 18:20 ` Andrew Lunn
2007-01-12 3:45 ` Andre-John Mas
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2007-01-11 18:20 UTC (permalink / raw)
To: Andre-John Mas; +Cc: Andrew Lunn, ecos-discuss
> Up until this particular issue I have had no problems using "standard in".
> I will look to see what effect opening /dev/termios0, but most examples
> I have seen use STDIN_FILENO directly.
Please could you point me at the eCos examples that do this?
> Changing my code slightly, I now find that I now block at cin.get().
> I wondering whether I am doing something wrong when changing to canocial
> mode?
>
> char InputHandler::DoPressAnyKey()
> {
> struct termios ts, ots;
> int c = 0;
> int fd = STDIN_FILENO;
>
> cout << "--0\n";
>
> tcflush(fd,TCIOFLUSH);
>
> cout << "--1\n";
You are using stdout, not the file descriptor for a /dev/termios0. I
would first determine is you are using the correct file
descriptor. When this really is wrong, nothing will work......
Andrew
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [ECOS] Select() issues
2007-01-11 18:20 ` Andrew Lunn
@ 2007-01-12 3:45 ` Andre-John Mas
0 siblings, 0 replies; 3+ messages in thread
From: Andre-John Mas @ 2007-01-12 3:45 UTC (permalink / raw)
To: Andrew Lunn; +Cc: ecos-discuss
On 11-Jan-07, at 13:20 , Andrew Lunn wrote:
>> Up until this particular issue I have had no problems using
>> "standard in".
>> I will look to see what effect opening /dev/termios0, but most
>> examples
>> I have seen use STDIN_FILENO directly.
>
> Please could you point me at the eCos examples that do this?
>
>> Changing my code slightly, I now find that I now block at cin.get().
>> I wondering whether I am doing something wrong when changing to
>> canocial
>> mode?
>>
>> char InputHandler::DoPressAnyKey()
>> {
>> struct termios ts, ots;
>> int c = 0;
>> int fd = STDIN_FILENO;
>>
>> cout << "--0\n";
>>
>> tcflush(fd,TCIOFLUSH);
>>
>> cout << "--1\n";
>
> You are using stdout, not the file descriptor for a /dev/termios0. I
> would first determine is you are using the correct file
> descriptor. When this really is wrong, nothing will work......
>
> Andrew
>
I changed the code to read:
int fd = open ( "/dev/termios0", O_RDONLY) ;
in all instances, but that seems to make no difference at all. I can get
input and modify termio settings, as in the previous case, but when I
hit multiple enters (or any key for that matter) before I get to the
code,
the select() or cin.get() don't come back.
BTW It should be noted that Termios TTY channel #0, in my ecos config
file,
points to /dev/ser0
Andre
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-01-12 3:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-10 16:28 Re: [ECOS] Select() issues Andre-John Mas
2007-01-11 18:20 ` Andrew Lunn
2007-01-12 3:45 ` Andre-John Mas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).