用Qt和C#写了两版串口数据读取程序,发现串口在拔插之后,开头的几个数据读取不到,但是用串口助手可以读取到
后来经过尝试,需要进行设置
Qt中:
m_reader = new QSerialPort(this); m_reader->setPort(com_info); if(m_reader->open(QIODevice::ReadOnly)) { m_reader->setBaudRate(QSerialPort::Baud9600); m_reader->setParity(QSerialPort::NoParity); m_reader->setDataBits(QSerialPort::Data8); m_reader->setStopBits(QSerialPort::OneStop); m_reader->setFlowControl(QSerialPort::NoFlowControl); m_reader->setDataTerminalReady(true);//这个很重要,否则的话拔插串口之后,刚开始的几个数据会读取不到!!!!!!!!!!!!!!!!!!! m_reader->clearError(); m_reader->clear(); connect(m_reader, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); ui->textEdit->append("Arduino端口"+com_info.systemLocation()+"++++++打开成功!+++++"); }
C#中: