OK. Create an else for if in line 13Qt Code:
if(one_packet[0] == 's') // 's' buldur kodu yaz dene! { } else { qDebug() << one_packet; }To copy to clipboard, switch view to plain text mode
OK. Create an else for if in line 13Qt Code:
if(one_packet[0] == 's') // 's' buldur kodu yaz dene! { } else { qDebug() << one_packet; }To copy to clipboard, switch view to plain text mode
Code never fall into there because i always handling with that error with this code.
Qt Code:
indexOfType = ArrayBuffer.indexOf('s'); if(indexOfType >= 1) { ArrayBuffer.remove(0,indexOfType); }To copy to clipboard, switch view to plain text mode
If any errorful package comes starting without 's' it will be removed from package and my loss will be just 1 number. But i'm losing 3000-4000 numbers.
After ArrayBuffer.remove(0,indexOfType); ArrayBuffer can be shorter than ExpectedPacketLength.
P.S.
If data in frame are binary then every byte in frame can be 's'.
Last edited by Lesiok; 23rd January 2017 at 12:09.
Actually it is not a problem because when ArrayBuffer.size below the expected packet length its leaving the slot and waiting for readyRead signal and i debugged it and see that:
Last 6 bytes to be processed e.g : {value,value,'s',value,value,value}. first two value is removed. and became {'s',value,value,value}. Then readyRead is emitted by the QT and data is appending to buffer again and these 4 bytes of ArrayBuffer which inherited by the last process is appended with the other {value,'s',value, bla bla... } data. And i checked their CRC and values. Everything is ok. But sometimes this buffer gets wrong number. Lets say we counted 1 to 150 without error and our buffer stayed like i exampled. Then its not 151 it became 500 or 1000 directly.
Really hard to explain. I'm trying my best. Thanks for trying to help.
It is a problem because after remove You have in buffer only 4 bytes not 5. Try this code :Qt Code:
if(indexOfType >= 1) { ArrayBuffer.remove(0,indexOfType); if( ArrayBuffer.size() < ExpectedPacketLength ) break;//We exit the loop }To copy to clipboard, switch view to plain text mode
I added this but nothing changed. I will struggle more about this. If i can find the bug will post it to here.
Thanks for all your helps really.
Hi again to everyone.
I figure out the problem it's about while loop when readyread signal is emitted in the parsing state. Now if i remove the loops and just emit the readyread signal and directly parse , it became correct but really slow because everytime when data is received parsing will be done.
Have i got any option to receive data and parse it simultaneously. How can i use serial thread and my object simultaneously ? Just need a documentation or an idea. I searched documentation but couldn't understand fully. Thanks a lot.
About which loop you speak ? Basically, you do not need an additional thread to handle serial port.
Qt Code:
while(ArrayBuffer.size() >= ExpectedPacketLength)To copy to clipboard, switch view to plain text mode
here this is the loop i mention about. When parsing is going on readAll can't get the data while loop was going on. I'm thinking creating another thread and when run it arraybuffer will be parsed simultaneously while reading data from serial port is going on.
Am i thinking wrong ?
Thanks.
What are You doing in "parsing" ?
If signal emiter and receiver are both in this same thread sending signal is like normal function calling. So that a new signal is issued only after the previous service.
Bookmarks