And these packages do not have any fixed structure? If so, the protocol is incorrectly designed.
And these packages do not have any fixed structure? If so, the protocol is incorrectly designed.
Of course not, these packages have fixed structure. I have just 3 or 4 different patterns.
I had the same Problem few days ago,
try to add special characters like crlf and append your data on a QString (or anything you want) until you recieve crlf.
QSerialPort doesn't know your frame so it only recieve data when it is available.
Yes, it is possible way to solve this problem. But I can't be sure that this special character will not be part of correct data - packet and I think, in 21th century is possible to transfer all data without any special characters at the end. I'm just saying, when I sent 20B I also get 20B. So, I changed my program to check this length and it seems working correctly.
In any century, it is not possible to just 'transfer all data' via a serial port without some way to verify the data on the receiving end. The way you are doing WILL fail at some point. If your do not have a starting element or an ending element (preferably both), you can never be absolutely 100% sure you have the correct data.
My advice is if you truly know the structure of the 3 or 4 patterns like you mentioned above, then you should implement code to check the received data fits into one of those patterns.
If something should happen during transmission, and a byte is dropped... or part of the packet is corrupted, then your data will be wrong...and assuming that just because you received 20 bytes that the data is good... is a very, very bad idea.
Just my 2 cents...
Bookmarks