Data stream throught QSerialPort
-
Hello,
i have a measuring device connected to PC via QSerialPort (bluetooth). It supports 2 communication modes:- sending some settings in a manner of command-optional answer pair which I already implemented
- online measurment in which it streams continuous data until being stopped (by sending proper command)
I am wondering which approach would be the best (mayby easiest to code) for getting streamed data if I want to plot it in real-time. I am considering
QSerialPort::readData()
combined withQSerialPort::availableBytes()
to read only full data samples (2 to 4 bytes depending on settings). I also read something aboutQDataStream(QIODevice)
but since I havent worked withQDataStrem
yet I assume it might be more problematic. However class name promises wanted behaviour so I find it tempting :D
Long story short - I would appreciate any kind of help/suggestions! -
Hi,
QDataStream is indeed not what you are looking for. Using readyRead should do what you want. Does the data you receive follow a pattern ?
-
Yep it does, however this pattern depends on previously programmed pattern eg.: if i program N-channel measurment I'll be getting data like [L byte ch1] [H byte ch1] ... [L byte ch_N] [H byte ch_N] [END OF SAMPLE L] [END OF SAMPLE H]. So basicly after every portion of data I'll have an end-of-sample info (2 bytes) and the next byte will be already from another sample.
@SGaist Do you have some particular solution in mind regarding your question? :) -
Yes, use a buffer where you append the data you receive from the serial port then check if it contains one or more complete packet. If so extract it/them from the buffer and do your processing the way you want it.