C++ (Qt)SerialReader::SerialReader(QObject *parent) : QThread(parent){ m_serialPort = new QSerialPort; m_serialPort->moveToThread(this); connect(m_serialPort, &QSerialPort::readyRead, this, &SerialReader::readSerialData);} void SerialReader::run(){ m_serialPort->setPortName("COM1"); if (!m_serialPort->open(QIODevice::ReadWrite) || !m_serialPort->setBaudRate(9600) || !m_serialPort->setDataBits(QSerialPort::Data7) || !m_serialPort->setParity(QSerialPort::NoParity) || !m_serialPort->setStopBits(QSerialPort::TwoStop) || !m_serialPort->setFlowControl(QSerialPort::NoFlowControl) || !m_serialPort->setDataTerminalReady(true) || !m_serialPort->setRequestToSend(false)) { emit critical(m_serialPort->errorString()); return; } exec(); m_serialPort->close();} void SerialReader::readSerialData(){ QByteArray data = m_serialPort->readAll(); qDebug() << data; if (data.startsWith("#")) m_serialPort->write("...");}