problem with writting on the screen after changing terminal

Hello.

We have written a getch() function (which I list at the end of this
email) that works perfectly in text mode but gives me a problem inside
of photon. The problem is that the printf() functions that I call
before calling getch() are not always printed out on the sceen. It
seems we do something inside of the getch() function that makes the
text previously sent to the screen with printf() dissapear (does not
appear on the screen).

Anyone can help?

Thank you,
Jose.


//this is my getch() function
#include <unistd.h>
#include <sys/uio.h>
#include <termios.h>

int getch()
{
struct termios old_termios;
struct termios new_termios;
char ch[3]="";
int c;

/* save current terminal settings */
tcgetattr(STDOUT_FILENO, &old_termios);

/* set to non canonical mode, echo off, ignore signals */
new_termios = old_termios;
new_termios.c_lflag &= ~(ECHO | ICANON | ISIG | IEXTEN);
new_termios.c_cc[VMIN] = 1;
new_termios.c_cc[VTIME] = 0;

tcsetattr(STDOUT_FILENO, TCSADRAIN, &new_termios);
read(STDIN_FILENO, ch, 3);

/* restore old terminal settings */
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &old_termios);
c=ch[0]+ch[1]+ch[2];
return c;
}

Hi Jose,

I am trying to reproduce the problem here but I need more info. Could you send me a reproducable test case. Step by step instructions on how to reproduce the problem your having.

Thanks
Brenda

Previously, Jose A. Galvez wrote in qdn.public.qnxrtp.photon:

Hello.

We have written a getch() function (which I list at the end of this
email) that works perfectly in text mode but gives me a problem inside
of photon. The problem is that the printf() functions that I call
before calling getch() are not always printed out on the sceen. It
seems we do something inside of the getch() function that makes the
text previously sent to the screen with printf() dissapear (does not
appear on the screen).

Anyone can help?

Thank you,
Jose.


//this is my getch() function
#include <unistd.h
#include <sys/uio.h
#include <termios.h

int getch()
{
struct termios old_termios;
struct termios new_termios;
char ch[3]="";
int c;

/* save current terminal settings */
tcgetattr(STDOUT_FILENO, &old_termios);

/* set to non canonical mode, echo off, ignore signals */
new_termios = old_termios;
new_termios.c_lflag &= ~(ECHO | ICANON | ISIG | IEXTEN);
new_termios.c_cc[VMIN] = 1;
new_termios.c_cc[VTIME] = 0;

tcsetattr(STDOUT_FILENO, TCSADRAIN, &new_termios);
read(STDIN_FILENO, ch, 3);

/* restore old terminal settings */
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &old_termios);
c=ch[0]+ch[1]+ch[2];
return c;
}

Hello.

Our software is really big. It was ported from QNX4 and is used to
control a robot. So it has to communicate with our electronics, have
signals and a function which is launched every ~40 milliseconds with a
timer. I’m not sure you want me to send you everything and I’m not
sure you would succeed in compiling it there. I have just separated
the input/output functions from the realtime control functions
(asociated with the timer), and then I don’t reproduce the problem
either.

In the meantime I solved the problem by writting
tcdrain(STDOUT_FILENO) after every printf. It is strange because, when
the printf is inside of the function asociated with the timer, the
tcdrain has to be put EXACTLY just after the printf. If I put it
before the getch (in the main-loop), then the printfs I put inside of
the function asociated with the timer are not always printed on the
screen. Another strange thing is that in text mode everything works
perfectly (with no need of the tcdrain function). Sorry for the
confusing explanations, anyway, as I said, I solved my problem by
writting tcdrain right after every printf, so you don’t need to care
about my problem any more; if you want my code anyhow, tell me.

Thank you very much for your time,
Jose


Brenda Merpaw wrote:

Hi Jose,

I am trying to reproduce the problem here but I need more info. Could you send me a reproducable test case. Step by step instructions on how to reproduce the problem your having.

Thanks
Brenda

Previously, Jose A. Galvez wrote in qdn.public.qnxrtp.photon:
Hello.

We have written a getch() function (which I list at the end of this
email) that works perfectly in text mode but gives me a problem inside
of photon. The problem is that the printf() functions that I call
before calling getch() are not always printed out on the sceen. It
seems we do something inside of the getch() function that makes the
text previously sent to the screen with printf() dissapear (does not
appear on the screen).

Anyone can help?

Thank you,
Jose.


//this is my getch() function
#include <unistd.h
#include <sys/uio.h
#include <termios.h

int getch()
{
struct termios old_termios;
struct termios new_termios;
char ch[3]="";
int c;

/* save current terminal settings */
tcgetattr(STDOUT_FILENO, &old_termios);

/* set to non canonical mode, echo off, ignore signals */
new_termios = old_termios;
new_termios.c_lflag &= ~(ECHO | ICANON | ISIG | IEXTEN);
new_termios.c_cc[VMIN] = 1;
new_termios.c_cc[VTIME] = 0;

tcsetattr(STDOUT_FILENO, TCSADRAIN, &new_termios);
read(STDIN_FILENO, ch, 3);

/* restore old terminal settings */
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &old_termios);
c=ch[0]+ch[1]+ch[2];
return c;
}

Jose A. Galvez wrote:

Hello.

Our software is really big. It was ported from QNX4 and is used to
control a robot. So it has to communicate with our electronics, have
signals and a function which is launched every ~40 milliseconds with a
timer. I’m not sure you want me to send you everything and I’m not
sure you would succeed in compiling it there. I have just separated
the input/output functions from the realtime control functions
(asociated with the timer), and then I don’t reproduce the problem
either.

In the meantime I solved the problem by writting
tcdrain(STDOUT_FILENO) after every printf. It is strange because, when
the printf is inside of the function asociated with the timer, the
tcdrain has to be put EXACTLY just after the printf. If I put it
before the getch (in the main-loop), then the printfs I put inside of
the function asociated with the timer are not always printed on the
screen. Another strange thing is that in text mode everything works
perfectly (with no need of the tcdrain function). Sorry for the
confusing explanations, anyway, as I said, I solved my problem by
writting tcdrain right after every printf, so you don’t need to care
about my problem any more; if you want my code anyhow, tell me.

Thank you very much for your time,
Jose


Brenda Merpaw wrote:

Hi Jose,

I am trying to reproduce the problem here but I need more info. Could you send me a reproducable test case. Step by step instructions on how to reproduce the problem your having.

Thanks
Brenda

Previously, Jose A. Galvez wrote in qdn.public.qnxrtp.photon:

Hello.

We have written a getch() function (which I list at the end of this
email) that works perfectly in text mode but gives me a problem inside
of photon. The problem is that the printf() functions that I call
before calling getch() are not always printed out on the sceen. It
seems we do something inside of the getch() function that makes the
text previously sent to the screen with printf() dissapear (does not
appear on the screen).

Anyone can help?

Thank you,
Jose.


//this is my getch() function
#include <unistd.h
#include <sys/uio.h
#include <termios.h

int getch()
{
struct termios old_termios;
struct termios new_termios;
char ch[3]="";
int c;

/* save current terminal settings */
tcgetattr(STDOUT_FILENO, &old_termios);

/* set to non canonical mode, echo off, ignore signals */
new_termios = old_termios;
new_termios.c_lflag &= ~(ECHO | ICANON | ISIG | IEXTEN);
new_termios.c_cc[VMIN] = 1;
new_termios.c_cc[VTIME] = 0;

tcsetattr(STDOUT_FILENO, TCSADRAIN, &new_termios);
read(STDIN_FILENO, ch, 3);

/* restore old terminal settings */
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &old_termios);
c=ch[0]+ch[1]+ch[2];
return c;
}


Hi

Have you though if it might be the buffering in the terminal? I suspect that is the case, i’ve noted printf’s dissapear alot, i now use fprintf(stder,“dsgfsf…”);
instead, then it’ll work!
there is some way to disable buffering, and i’m pretty sure the prinft will work then.
Goodluck

/Johan