|
串口打印控制
(需要 QtSerialPort 组件) 头文件 #include ”QtSerialPort/QSerialPort“ #include “QtSerialPort/QSerialPortInfo” 源文件 void MainWindow::SerialPrint(QString PortName,QString comm) { if (PortName.indexOf("com") ==-1 ) { qDebug()<<"Invalid Serial Port."; return; } QSerialPort *serial = new QSerialPort; serial->setPortName(PortName); if(serial->open(QIODevice::ReadWrite)) { serial->setBaudRate(QSerialPort::Baud9600); serial->setDataBits(QSerialPort::Data8); serial->setParity(QSerialPort::NoParity); serial->setStopBits(QSerialPort::OneStop); serial->setFlowControl(QSerialPort::NoFlowControl); serial->write(comm.toLatin1()); } else { qDebug()<< PortName +" NOT connected!"; } delete serial; } |