Qt 串口通信(QSerialPort)16进制收发实例代码(QT实战5) | 您所在的位置:网站首页 › linux串口发送16进制命令 › Qt 串口通信(QSerialPort)16进制收发实例代码(QT实战5) |
Qt 串口通信(QSerialPort)16进制收发实例代码
项目全部代码打包https://download.csdn.net/download/ydyuse/12324695 首先在项目文件里面添加一句 QT += serialport 使用静态函数生成QSerialPortInfo对象列表。列表中的每个QSerialPortInfo对象表示一个串行端口,可以查询端口名称、系统位置、描述和制造商。QSerialPortInfo类还可以用作QSerialPort类的setPort()方法的输入参数。 m_ui->serialPortInfoListBox->clear(); QString description; QString manufacturer; QString serialNumber; const auto infos = QSerialPortInfo::availablePorts(); for (const QSerialPortInfo &info : infos) { QStringList list; description = info.description(); manufacturer = info.manufacturer(); serialNumber = info.serialNumber(); list setBaudRate(p.baudRate); m_serial->setDataBits(p.dataBits); m_serial->setParity(p.parity); m_serial->setStopBits(p.stopBits); m_serial->setFlowControl(p.flowControl); if (m_serial->open(QIODevice::ReadWrite)) { showStatusMessage(tr("Connected to %1 : %2, %3, %4, %5, %6") .arg(p.name).arg(p.stringBaudRate).arg(p.stringDataBits) .arg(p.stringParity).arg(p.stringStopBits).arg(p.stringFlowControl)); } else { QMessageBox::critical(this, tr("Error"), m_serial->errorString()); showStatusMessage(tr("Open error")); }
3、发送数据,转换输入,并16进制发送 QString info= ui->textEditsend->toPlainText(); if (info.contains(" ")) { info.replace(QString(" "),QString(""));//把空格去掉 } qDebug() |
CopyRight 2018-2019 实验室设备网 版权所有 |