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 文档
     
     
  • 相关阅读:
    62. Unique Paths
    24. Swap Nodes in Pairs
    83. Remove Duplicates from Sorted List
    21. Merge Two Sorted Lists
    141. Linked List Cycle
    268. Missing Number
    191. Number of 1 Bits
    231. Power of Two
    9. Palindrome Number
    88. Merge Sorted Array
  • 原文地址:https://www.cnblogs.com/countryboy666/p/11523648.html
Copyright © 2011-2022 走看看