Domanda

I need to write terminal for UART on raspberry pi. The idea is to press keys on keyboard connected to my raspberry and send it by UART and then print what raspberry receives by UART.

Problem is in echo on raspberry pi. I don't need this, but I don't know how to disable it. I use this function:

int kbhit(void)
{
    struct termios oldt, newt;
    int ch;
    int oldf;

    tcgetattr(STDIN_FILENO, &oldt);
    newt = oldt;
    newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
    fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
    ch = getchar();
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    fcntl(STDIN_FILENO, F_SETFL, oldf);
    if(ch != EOF)
    {
        return ch;
    }
    return 0;
}

Sometimes there is no echo.

For example my input is: abcdefgh
But program returns me this: abbccddeefghh

È stato utile?

Soluzione

I just commented line

tcsetattr(STDIN_FILENO, TCSANOW, &oldt);

and it's working without echo. It looks like something which is responsible for clearing echo has little time to do it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top