//// //// Created by zong on 5/18/22. //// // //#include "main_windows.h" //#include //#include //#include //#include // //static bool check_exist(QString str) { // for (auto &port: QSerialPortInfo::availablePorts()) { // if (str == port.portName()) // return true; // } // return false; //} // //main_windows::main_windows(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { // ui->setupUi(this); // QObject::connect(&port, SIGNAL(readyRead()), this, SLOT(read_data())); // QSerialPortInfo info; // auto tmp = QSerialPortInfo::availablePorts(); // ui->comboBox->clear(); // for (auto &port: tmp) { // qDebug() << port.portName(); // ui->comboBox->addItem(port.portName()); // } // //} // //main_windows::~main_windows() { // delete ui; //} // //void main_windows::update_ui_port() { // ui->comboBox->clear(); // for (auto &port: QSerialPortInfo::availablePorts()) { // ui->comboBox->addItem(port.portName()); // } //} // //void main_windows::open_port() { // if (is_open) { // port.close(); // is_open = false; // ui->pushButton_2->setText("open"); // return; // } // if (ui->comboBox->count() == 0) { return; } // auto cur_port = ui->comboBox->currentText(); // if (!check_exist(cur_port)) return; // port.setPortName(cur_port); // port.setStopBits(QSerialPort::OneStop); // port.setBaudRate(115200); // port.setDataBits(QSerialPort::Data8); // port.setParity(QSerialPort::NoParity); // port.setFlowControl(QSerialPort::NoFlowControl); // if (port.open(QIODevice::ReadWrite)) { // is_open = true; // ui->pushButton_2->setText("close"); // qDebug() << "open port success"; // } else // is_open = false; // //} // //void main_windows::read_data() { // auto data = port.readAll(); // qDebug() << data; // auto tmp = data.toHex(' ').toUpper(); // auto new_text = QString(tmp); // ui->textEdit->insertPlainText(new_text); //// auto text = ui->textEdit- //}