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 文档
     
     
  • 相关阅读:
    oracle查看锁表及解锁
    二、web综合开发
    一、springboot入门
    oracle行转列及分组排序
    awk命令--转
    oracle 游标
    HttpServletRequestWrapper类的使用
    rabbitMQ
    java(其他)面试要点7
    java(框架)面试要点6
  • 原文地址:https://www.cnblogs.com/countryboy666/p/11523648.html
Copyright © 2011-2022 走看看