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()

Qt 串口相关配置的更多相关文章

  1. Qt串口通信

    1. Qt串口通信类QSerialPort 在Qt5的的更新中,新增了串口通信的相关接口类QSerialPort,这使得在开发者在使用Qt进行UI开发时,可以更加简单有效地实现串口通信的相关功能. 开 ...

  2. Qt 串口通信

    在Qt5之前,串口通信基本依赖于第三方库,下面是我曾接触过的串口通信类库: 名称 语言 平台   QextSerialPort QT C++ Win/Linux http://sourceforge. ...

  3. QT+VS2013 1配置和安装

    相关参考:http://www.cnblogs.com/ranjiewen/p/5318768.html 1下载 VS2013 微软官网查找  https://www.visualstudio.com ...

  4. 【转】QT 串口QSerialPort + 解决接收数据不完整问题

    类:QSerialPort 例程:Examples\Qt-5.9.1\serialport\terminal,该例子完美展示了qt串口收发过程,直接在这上面修改就可以得到自己的串口软件.核心方法 // ...

  5. 通过minicom传送文件的相关配置及使用方法

    写一下我使用串口向开发板传送文件中遇到的问题及解决办法: 使用的软硬件环境: 虚拟机:VMware® Workstation 8.0.1 Linux操作系统:Fedora 9 开发板:mini6410 ...

  6. 迅为iTOP-4418开发板串口虚拟控制台配置为普通串口

    如何将 iTOP-4418 的串口控制台配置为普通串口.在最终的产品中,如果需要额外的串口,可以将调试用的控制台串口作为普通串口使用,因为交付给最终用户手中的产品,一般不需要调试串口.屏蔽串口控制台需 ...

  7. QT串口助手(三):数据接收

    作者:zzssdd2 E-mail:zzssdd2@foxmail.com 一.前言 开发环境:Qt5.12.10 + MinGW 实现的功能 串口数据的接收 ascii字符形式显示与hex字符形式显 ...

  8. zookeeper集群的搭建以及hadoop ha的相关配置

    1.环境 centos7 hadoop2.6.5 zookeeper3.4.9 jdk1.8 master作为active主机,data1作为standby备用机,三台机器均作为数据节点,yarn资源 ...

  9. Linux网络相关配置

    一.修改网卡相关配置 Linux网络参数是在/etc/sysconfig/network-scripts/ifcfg-eth0中设置,其中ifcfg-eth0表示是第一个网卡,如果还有另外一块网卡,则 ...

  10. ios开发之Info.plist文件相关配置

    前言:在iOS开发中有些情况下需要对Info.plist文件进行配置,以下介绍几种相关配置.以后遇到需要配置的再更新... 开发环境:swift3.0.1,Xcode8.1 一,项目中需要使用第三方字 ...

随机推荐

  1. thinkphp5框架使用总结

    因为采用了mvc模式,所以理解上为了简便,把控制中心作为一个浏览对象去处理,其他不要去考虑只把它们当做附属物 一.路径访问方式 http://网址/index.php/模块/控制器/操作.html 其 ...

  2. Appium元素选择 滑动 通知栏

    一.根据ID  包名可省略 1.元素的resource id属性 2.唯一标志该元素的值 3.一般最优先根据它来定位 driver.find_element_by_id('io.manong.deve ...

  3. linux中用户和用户组的概念

    大家好,我们继续来上linux课程,这节课我们从以下几点来进行讲解: Linux权限的概念: UID相关概念 用户和用户组的关系 用户和账户的区别 Linux是一个多用户多任务的的操作系统,很多时候, ...

  4. KU060板卡设计资料原理图第636篇:基于FMC的KU060高性能 PCIe 载板

    基于FMC的KU060高性能 PCIe 载板 一.板卡概述 板卡主控芯片采用Xilinx 公司的 Kintex UltraScale系列FPGA XCKU060-2FFVA1156.板载 2 组 64 ...

  5. 部署spingboot项目到云服务器踩坑记录

    按教程部署mall电商系统 https://www.macrozheng.com/mall/deploy/mall_deploy_docker.html#docker环境安装 只记录SpringBoo ...

  6. docker配置文件模板

    { "registry-mirrors": [ "https://bxsfpjcb.mirror.aliyuncs.com" ], "max-conc ...

  7. 狂神--ElasticSearch

    一.ElasticSearch概述 官网:https://www.elastic.co/cn/downloads/elasticsearch Elaticsearch,简称为es,es是一个开源的高扩 ...

  8. SpringBoot代理图片、文件等路径

    在config文件夹下新增一个配置类即可 /** * @author cyl * @time 2022/10/25 */ @Configuration public class UrlConfig e ...

  9. Jest - Testing Asynchronous

    When we test asynchronous, we use Axios to get the response. install the Axios npm i axios Cause we ...

  10. js动态删除添加一行

    <div class="input-dyna-add"> <form class="form-inline form-group" role= ...