如何避免在串行输入中输入键作为输入?

时间:2017-02-13 03:21:05

标签: c linux linux-device-driver

void *serial_function(void *threadNo_R)
{
int ImThreadNo = (int) threadNo_R;
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);//
 if (fd == -1)
    {
    /* Could not open the port. */
        perror("open_port: Unable to open /dev/ttyUSB0 - ");
    }
  fcntl(fd, F_SETFL,0);
  while(1)
   {
    read(fd,&dataReceived.Serial_input,1);
    printf("\n From serial fn: Serial_input is:%c\n",dataReceived.Serial_input);

    if(V_buf.power_window_data.front_right_up>=1)
    {
       writenornot= write(fd,"Window is raising:",19);
        if (writenornot < 0)
        {
        printf("Write Failed \n");
        }
        else
        printf("Write successfull \n"); 
    }   
}

}

在上面的程序中,串行输入通过终端发送,将由驱动程序读取并进行进一步的操作。如果我按下一个键'a',我应该按输入笔划来传递密钥,而我正在读取两个'a'和'输入笔画'。是否有任何方法,如打开(“/ dev / ttyUSB0”,O_RDWR | O_NOCTTY | O_NDELAY); ,它正在读取我按下的两个键并“输入“也。我想要输入密钥应该避免。

0 个答案:

没有答案