在c++中读取串行端口的设置

setting for the reading serial port in c++

本文关键字:设置 串行端口 读取 c++      更新时间:2023-10-16

我对串行的参数设置有点问题。在程序c++I中配置:-波特率->38400-数据位->8-奇偶校验->无-停止位->1-握手->没有。但是从串行读取的缓冲区是脏的,它包含更多的消息。我想要1条消息作为1个缓冲区。你能帮我吗?我等着回答。这是代码:

speed=B38400;
    cfsetospeed (&tty, speed);
    cfsetispeed (&tty, speed);
    tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;     // 8-bit chars
    // disable IGNBRK for mismatched speed tests; otherwise receive break
    // as 00 chars
    tty.c_iflag &= ~IGNBRK;         // disable break processing
    tty.c_lflag = 0;                // no signaling chars, no echo,
                                    // no canonical processing
    tty.c_oflag = 0;                // no remapping, no delays
    tty.c_cc[VMIN]  = 0;            // read doesn't block
    tty.c_cc[VTIME] = 5;            // 0.5 seconds read timeout
    tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
    tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
                                    // enable reading
    tty.c_cflag &= ~(PARENB | PARODD);      // shut off parity
    tty.c_cflag |= parity;
    tty.c_cflag &= ~CSTOPB;
    tty.c_cflag &= ~CRTSCTS;

我使用树莓,一个debian平台