想清教一下各位大大,我現在用一條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();
}