You should declar variable dataBuffer in class Foo and then do something like this :
Foo::readyRead(){
int frameLen = 11;
dataBuffer.append(port->readAll());
if( dataBuffer.size() < frameLen )
return;// data to short
int indexOfFrame = dataBuffer.indexOf("\xAA\xAA");
if( indexOfFrame < 0)
return;// frame marker not found
QByteArray oneFrame
= dataBuffer.
mid(indexOfFrame,frameLen
);
// we have one frame, do something with this dataBuffer = dataBuffer.right(indexOfFrame,frameLen);//remove processed data from the buffer
}
Foo::readyRead(){
int frameLen = 11;
dataBuffer.append(port->readAll());
if( dataBuffer.size() < frameLen )
return;// data to short
int indexOfFrame = dataBuffer.indexOf("\xAA\xAA");
if( indexOfFrame < 0)
return;// frame marker not found
QByteArray oneFrame = dataBuffer.mid(indexOfFrame,frameLen);// we have one frame, do something with this
dataBuffer = dataBuffer.right(indexOfFrame,frameLen);//remove processed data from the buffer
}
To copy to clipboard, switch view to plain text mode
Bookmarks