Unsolved Read buffer QSerialPort
-
Hello I have some questions.
- I want read buffer from device and send command every 1ms.
Buffer it looks like this: AAAABBBBCCCCDDDDEEEEFFFFGGHHIIJJ
I want read only A,B,C,F. How to get only specific bytes numbers.
Shoud I check currect amount of bytes?
And later save to:QByteArray data
Access to A,B,C,F only with for loop and QByteArray.append?
- After some time I want save this data in Excel file, where keep large amounts of data?
- I want read buffer from device and send command every 1ms.
-
Hi
Will it be fixed amount of each ?
like 4 AAAA, 4 BBBB up to f ?- After some time I want save this data in Excel file, where keep large amounts of data?
What do you mean ? And excel sheet is not good for large amounts of data.
- After some time I want save this data in Excel file, where keep large amounts of data?
-
Yes always 4A , 4B etc.
Maybe .csv file. -
@erytcg
well then you can just add to the read buffer
when size is 4 x 5, you should have all data.
Then you can process the buffer save save to file or what you need. -
QByteArray data = serialPort->readAll(); QByteArray aaaa; for (int i = 0; i <= 3 i++) { aaaa.append(data[i]); }
it's ok?
-
@erytcg
Nope, that would crash pretty fast if you receive less than 3 chars first read.QByteArray data; // move to member of class.
then in read do
data += serialPort->readAll(); // add them up. they might come in blocks.
if (data.size() > 19 ) { // now we got at 20 minimum
... do what u need.
data.clear(); // clear read buffer
} -
Is there method to read QByteArray some byte?
-
@erytcg
Not that i saw, but you can use
QString AString( data );
then use
http://doc.qt.io/qt-5/qstring.html#mid
to grab only a substring from it -
Hi,
No need to change classes: QByteArray::mid.
-
@SGaist
Oh, how could it miss that :)