I connected the ReadyRead-Signal from my SerialPort to the Slot
void Serial::handlePortReadyRead(){
qDebug()<<"Read from Port" << temp.toHex();
emit ReadFromPort(temp);
}
void Serial::handlePortReadyRead(){
QByteArray temp = serialPort.readAll();
qDebug()<<"Read from Port" << temp.toHex();
emit ReadFromPort(temp);
}
To copy to clipboard, switch view to plain text mode
When I start a process I connect the ReadFromPort(QByteArray)-Signal to a Slot, where I handle the repsonse from the port.
for(int charCount = 0; charCount < temp.count(); charCount++){
char singleInChar = temp.at(charCount);
validationFlag = handleResponse(&response, deviceAddress, FID, singleInChar, false);
break;
}
}
}
void Process::analyzeFrame(QByteArray temp){
for(int charCount = 0; charCount < temp.count(); charCount++){
char singleInChar = temp.at(charCount);
validationFlag = handleResponse(&response, deviceAddress, FID, singleInChar, false);
break;
}
}
}
To copy to clipboard, switch view to plain text mode
handleResponse returns 0 or 1. If it returns 1 I want the process to continue, 0 means I have to wait. If validationFlag does not get 1 within 100 msecs the process should stop.
serialPort.write(dataToSend);
TimerForReadingFromPort->start(100);
do{
if(validationFlag == 1){
//analyze response
...
response.clear();
}
else if(TimerForReadingFromPort->remainingTime() == 0){
....
return
}
}
while(validationFlag == 0);//end while-Schleife
serialPort.write(dataToSend);
TimerForReadingFromPort->start(100);
do{
QApplication::processEvents();
if(validationFlag == 1){
//analyze response
...
response.clear();
}
else if(TimerForReadingFromPort->remainingTime() == 0){
....
return
}
}
while(validationFlag == 0);//end while-Schleife
To copy to clipboard, switch view to plain text mode
So this process is a very long process. Sometimes it get stucked in the middle of the code, I think it is because of the QApplication:rocessEvents().
Is there any better way?
Bookmarks