QSerialPort M_serialPort;
QSerialPortInfo M_SerialPortInfo;


void MainWindow::on_M_portNumComboBox_currentIndexChanged(const QString &arg1)
{
#ifdef MAIN_DEBUG
    qDebug()<<"M_serialPort : "  <<arg1;
#endif

    if(M_SerialPortInfo.portName() == arg1)
    {
        M_serialPort.setPortName(M_SerialPortInfo.portName());
    }
    else
    {
        qDebug()<<"M没有此串口";
    }
}

//获取并设置M串口信息
void MainWindow::on_M_stopBitComboBox_currentIndexChanged(int index)
{
#ifdef MAIN_DEBUG
    qDebug()<<"M_serialPort.stopBit : " <<index;
#endif

    switch (index)
    {
        case 0:
            M_serialPort.setStopBits(QSerialPort::OneStop);
            break;
        case 1:
            M_serialPort.setStopBits(QSerialPort::TwoStop);
            break;
        default:
            M_serialPort.setStopBits(QSerialPort::UnknownStopBits);
            break;
    }
}

void MainWindow::on_M_baudRateComboBox_currentIndexChanged(int index)
{
#ifdef MAIN_DEBUG
    qDebug()<<"M_serialPort.baudRate : " <<index;
#endif

    switch (index)
    {
        case 0:
            M_serialPort.setBaudRate(QSerialPort::Baud1200,QSerialPort::AllDirections);
            break;
        case 1:
            M_serialPort.setBaudRate(QSerialPort::Baud2400,QSerialPort::AllDirections);
            break;
        case 2:
            M_serialPort.setBaudRate(QSerialPort::Baud4800,QSerialPort::AllDirections);;
            break;
        case 3:
            M_serialPort.setBaudRate(QSerialPort::Baud9600,QSerialPort::AllDirections);;
            break;
        case 4:
            M_serialPort.setBaudRate(QSerialPort::Baud19200,QSerialPort::AllDirections);;
            break;
        case 5:
            M_serialPort.setBaudRate(QSerialPort::Baud38400,QSerialPort::AllDirections);;
            break;
        case 6:
            M_serialPort.setBaudRate(QSerialPort::Baud57600,QSerialPort::AllDirections);;
            break;
        case 7:
            M_serialPort.setBaudRate(QSerialPort::Baud115200,QSerialPort::AllDirections);;
            break;
        default:
            M_serialPort.setBaudRate(QSerialPort::UnknownBaud,QSerialPort::AllDirections);;
            break;
    }
}

void MainWindow::on_M_parityBitComboBox_currentIndexChanged(int index)
{
#ifdef MAIN_DEBUG
    qDebug()<<"M_serialPort.parityBit : " <<index;
#endif

    switch (index)
    {
        case 0:
            M_serialPort.setParity(QSerialPort::NoParity);
            break;
        case 1:
            M_serialPort.setParity(QSerialPort::OddParity);
            break;
        case 2:
            M_serialPort.setParity(QSerialPort::EvenParity);
        default:
            M_serialPort.setParity(QSerialPort::UnknownParity);
            break;
    }
}

void MainWindow::on_M_digitBitComboBox_currentIndexChanged(int index)
{
#ifdef MAIN_DEBUG
    qDebug()<<"M_serialPort.dataBit : " <<index;
#endif

    switch (index)
    {
        case 0:
            M_serialPort.setDataBits(QSerialPort::Data5);
            break;
        case 1:
            M_serialPort.setDataBits(QSerialPort::Data6);
            break;
        case 2:
            M_serialPort.setDataBits(QSerialPort::Data7);
            break;
        case 3:
            M_serialPort.setDataBits(QSerialPort::Data8);
            break;
        default:
            M_serialPort.setDataBits(QSerialPort::UnknownDataBits);
            break;
    }
}

void MainWindow::on_M_dataFlowComboBox_currentIndexChanged(int index)
{
#ifdef MAIN_DEBUG
    qDebug()<<"M_serialPort.dataFlow : " <<index;
#endif

    switch (index)
    {
        case 0:
            M_serialPort.setFlowControl(QSerialPort::NoFlowControl);
            break;
        case 1:
            M_serialPort.setFlowControl(QSerialPort::HardwareControl);
            break;
        case 2:
            M_serialPort.setFlowControl(QSerialPort::SoftwareControl);
        default:
            M_serialPort.setFlowControl(QSerialPort::UnknownFlowControl);
            break;
    }
}


void MainWindow::on_M_openSerialPortButton_clicked()
{
    bool comState = M_serialPort.open(QIODevice::ReadWrite);//打开串口并选择读写模式
    if(comState)
    {
        ui->statusBar->showMessage("M串口打开成功");
    }
    else
    {
        ui->statusBar->showMessage("M串口打开失败");
    }
}

void MainWindow::on_M_closeSerialPortButton_clicked()

最新文章

  1. 以self-contained方式在Linux上部署ASP.NET Core站点
  2. storm中DAU实时计算方案
  3. [原创]纯JS实现网页中多选复选框checkbox和单选radio的美化效果
  4. MVVM架构~Knockoutjs系列之js接收C#数据集合的方式
  5. Android保持屏幕常亮的方法
  6. JavaScript parseInt函数
  7. 关于DOM树的常见增删操作
  8. extjs4与ckeditor、ckfinder整合
  9. linux内核值shmmax问题
  10. 白帽子讲Web安全2.pdf
  11. 原 IOS之NSValue整理
  12. 前端--关于CSS文本
  13. bzoj 3261最大异或和
  14. Python django解决跨域请求的问题
  15. java实现文章敏感词过滤检测
  16. Linux C 编程
  17. JSAP101
  18. Jenkins自动化构建(一)执行selenium+python脚本
  19. Angular2 组件与模板 -- 输入和输出属性
  20. 如何判断SOCKET还是连接着的

热门文章

  1. SOJ1737 题解
  2. 20230103~05code
  3. Java面向对象之类与对象的创建
  4. Javascript高级程序设计(000)
  5. SqlServer基礎
  6. 关于certutil的探究-文件下载+编码分块上传上传文件再合并
  7. bpmn的依赖注入
  8. js 俄罗斯方块 canvas
  9. JS-变量存储
  10. 第五章:用Python分析商品退单数据并找出异常商品