1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
   | #include "MyPort.h"
 
MyPort::MyPort(): QThread(){
 
  port = new QextSerialPort("/dev/ttyS0");
  port->setBaudRate(BAUD9600);   
  port->setFlowControl(FLOW_OFF);
  port->setParity(PAR_NONE);    
  port->setDataBits(DATA_8);   
  port->setStopBits(STOP_2);    
 
  received_msg = new QTextEdit("empty");
  QString text();  
}
void MyPort::closePort(){
	port->close();
}
 
void MyPort::openPort(){
	port->open(QIODevice::ReadWrite);
}
 
void MyPort::run(){
  	char buff[2048]={0};
  	int numBytes;
 
  	while(1){
		numBytes = port->bytesAvailable();
		if(numBytes > 0){
	    	if(numBytes > 2048) numBytes = 2048;
 
	    	int i = port->read(buff, numBytes);
			buff[i] = '\0';
			text.append(buff); 
	    	received_msg->setPlainText(text);
	    	emit MonSignal();
	    	text.clear();
		}
  	}
}
 
QString MyPort::getReceived_msgTxt(void) const{
	return received_msg->toPlainText();
} |