#ifdef _TTY_POSIX
#include “posix_qextserialport.h”
#define QextBaseType Posix_QextSerialPort
#include “win_qextserialport. h”
#define “QextBaseTypeport.h”
#define QextBaseType Win_QexSerialPort
#endif
Polling: Set up timer reading Get the serial port information
EventDrrivent: Once there is data to send the readyRead() signal
Set the serial port to event-driven mode
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); Data Flow Control
mycom->setTimeout(500);
connect(mycom,SIGNAL(readyRead()),this,SLOT(readMycom()));
{
if(mycom->buteAvailable()>= 8)
{
QByteArray temp = mycom->readAll ();
ui->textBrowser->insertPlainText(Temp);
mycom = new Win_QextSerialPort(“Com1”,QextSerialBase::Polling);
readTimer = new QTimer(this);
readTimer-> start(100);
mycom->setTimeout(10); Put data into serial buffer
connect(readTimer,SIGNAL(timeout()),this,SLOT(readMyCom()));
qt serial communication:
#ifdef _TTY_POSIX
#include “posix_qextserialport.h”
#define QextBaseType Posix_QextSerialPort
#else
#include “win_qextserialport .h”
#define “QextBaseTypeport.h”
#define QextBaseType Win_QexSerialPort
#endif
The way in which QueryMode in the QextSerialBase class reads the serial port:
Polling: Create a timer Read the serial port information
EventDrrivent: Once there is data to send the readyRead() signal
Set the serial port to event-driven mode
mycom = new Win_QextSerialPort(“COM1”,QextSerialBase::EventDriven);
mycom-> open(QIODevice::ReadWrite);
mycom->setBaudRate(BAUD9600);
mycom->setDataBits(DATA_8);
mycom->serPar ity(PAR_NONE);
mycom->setStopBits(STOP_1);
mycom->setFlowControl(FLOW_OFF); data flow control
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);
}
} p>
Use Polling mode:
mycom = new Win_QextSerialPort(“Com1”,QextSerialBase::Polling);
readTimer = new QTimer(this);
readTimer->start(100); < br>mycom->setTimeout(10); Put data into serial buffer
connect(readTimer,SIGNAL(timeout()),this,SLOT(readMyCom()));
Linux:
mycom = new Posix_QextSerialPort(“/dev/ttyS0”,QextSerialBase::Polling)
www.yafeilinux.com documentation