zoukankan      html  css  js  c++  java
  • qt串口

    qt串口通信:
    #ifdef _TTY_POSIX
    #include "posix_qextserialport.h"
    #define QextBaseType Posix_QextSerialPort
    #else
    #include "win_qextserialport.h"
    #define "QextBaseTypeport.h"
    #define QextBaseType Win_QexSerialPort
    #endif
    QextSerialBase类中 QueryMode读取串口的方式:
    Polling :建立定时器 读取串口信息
    EventDrrivent: 一旦有数据发出readyRead()信号
    设置串口为事件驱动模式
    mycom = new Win_QextSerialPort("COM1",QextSerialBase::EventDriven);
    mycom->open(QIODevice::ReadWrite);
    mycom->setBaudRate(BAUD9600);
    mycom->setDataBits(DATA_8);
    mycom->serParity(PAR_NONE);
    mycom->setStopBits(STOP_1);
    mycom->setFlowControl(FLOW_OFF);数据流控制
    mycom->setTimeout(500);
    connect(mycom,SIGNAL(readyRead()),this,SLOT(readMycom()));

    void Widget::readMycom()
    {
     if(mycom->buteAvailable()>= 8)
     {
      QByteArray temp = mycom->readAll();
      ui->textBrowser->insertPlainText(Temp);
     }
    }
    使用Polling模式:
    mycom = new Win_QextSerialPort("Com1",QextSerialBase::Polling);
    readTimer = new QTimer(this);
    readTimer->start(100);
    mycom->setTimeout(10);  将数据放入串口缓冲区
    connect(readTimer,SIGNAL(timeout()),this,SLOT(readMyCom()));

    Linux :
    mycom = new Posix_QextSerialPort("/dev/ttyS0",QextSerialBase::Polling)

    www.yafeilinux.com 文档
     
     
  • 相关阅读:
    TCP的三次握手与四次挥手理解及面试题(很全面)
    python解释器锁的理解
    Flask的基本使用、四剑客和配置文件
    Django cache缓存
    xadmin后台管理
    cookies与session
    Java stream流
    Java IO流
    springboot配置文件加载顺序与一些常用配置
    OAuth2.0开放授权
  • 原文地址:https://www.cnblogs.com/countryboy666/p/11523648.html
Copyright © 2011-2022 走看看