• 4558阅读
  • 0回复

qte透過rs232接收資料的問題 [复制链接]

上一主题 下一主题
离线evanishbreak
 

只看楼主 倒序阅读 楼主  发表于: 2007-08-20
qte透過rs232接收資料的問題
— 本帖被 XChinux 从 Qt Programming 移动到本区(2008-07-18) —
想清教一下各位大大,我現在用一條rs232連接到一塊版子和x86上(linux),讓版子跑while的程式不斷的寫出資料,要讓x86接收,但是都無法正確的接收跟顯示收的的資料,請各位大大幫忙,謝謝。

下面是code


#include <qapplication.h>
#include <qwaitcondition.h>
#include <qlabel.h>
#include "posix_qextserialport.h"
#include <qtextedit.h>

int main(int argc, char **argv)
{
QApplication myApp(argc, argv);
QLabel myLabel("hello",0);

Posix_QextSerialPort *RS232 = new Posix_QextSerialPort("/dev/ttyS1");
RS232->setBaudRate(BAUD9600);
RS232->setFlowControl(FLOW_OFF);
RS232->setParity(PAR_NONE);
RS232->setDataBits(DATA_8);
RS232->setStopBits(STOP_1);

if (RS232->open())
{
int numBytes = RS232->bytesWaiting();
if(numBytes > 0){
    if(numBytes > 80) numBytes = 80;
    char buff[80];
    buff[numBytes]='\0';
    QString msg = buff;
    QTextEdit *received_msg ;
    RS232->readBlock(buff,4);
    received_msg->append(msg);
}
    RS232->flush();
    RS232->close();
}
myApp.setMainWidget(&myLabel);
myLabel.show();
return myApp.exec();
}

快速回复
限100 字节
 
上一个 下一个