How to synchronize QTcpSocket data and timer data in the GUI
-
Hi,
- I used
QwtPlot's x axis asQwtSystemClockobject (seconds) it will keep running on the GUI. - I will get 256
QPointFpoints throughQTCPSocketper second inSocket.cppby socket. - How to synchronize received 256
QPointF'sSetX()values according toQwtSystemClock's per second . - Each point's
xshould have a difference (1/256=0.00390625)
- I used
-
Hi,
- I used
QwtPlot's x axis asQwtSystemClockobject (seconds) it will keep running on the GUI. - I will get 256
QPointFpoints throughQTCPSocketper second inSocket.cppby socket. - How to synchronize received 256
QPointF'sSetX()values according toQwtSystemClock's per second . - Each point's
xshould have a difference (1/256=0.00390625)
IMHO you will need time tags from device sending through tcp/ip. That is the most accurate possibility.
QTcpSocket has a buffer and all in-coming data will be accumulated there. Typically sometime at the beginning you will receive a readyRead signal. At which time your application will react on the signal is dependend on a couple of factors (e.g. cpu load, time retrieve each data record, time to plot, ...).
If you have a fast machine with a couple of cores, there might be possibility to run a thread checking the contents of the buffer very quickly. This would allow for assigning a time-tag for each value, but probably not too close to actual measuring time.
- I used
-
IMHO you will need time tags from device sending through tcp/ip. That is the most accurate possibility.
QTcpSocket has a buffer and all in-coming data will be accumulated there. Typically sometime at the beginning you will receive a readyRead signal. At which time your application will react on the signal is dependend on a couple of factors (e.g. cpu load, time retrieve each data record, time to plot, ...).
If you have a fast machine with a couple of cores, there might be possibility to run a thread checking the contents of the buffer very quickly. This would allow for assigning a time-tag for each value, but probably not too close to actual measuring time.
@koahnig said in How to synchronize QTCPSOCKET data and timer data in the GUI:
there might be possibility to run a thread checking the contents of the buffer very quickly.
I can go with a thread.
if I connectreadyRead()tocollectData()and store the data in buffer.
after that by usingQwtSystemClockclock insocket.cppand callingsendToGui()every second and passing the data, Can I go with it?. -
@koahnig said in How to synchronize QTCPSOCKET data and timer data in the GUI:
there might be possibility to run a thread checking the contents of the buffer very quickly.
I can go with a thread.
if I connectreadyRead()tocollectData()and store the data in buffer.
after that by usingQwtSystemClockclock insocket.cppand callingsendToGui()every second and passing the data, Can I go with it?. -
If this is your only option, you can try. Note, gut feeling on my side is that you will have varying time intervals between your "measured values". If this is acceptable, you need to decide.
-
If this is your only option, you can try. Note, gut feeling on my side is that you will have varying time intervals between your "measured values". If this is acceptable, you need to decide.
-
@koahnig
Will this help me?double elapsed=clock.elapsed(); int no_of_interval=256; double msecs=no_of_interval-(clock.elapsed()-elapsed); if(msecs>0.0) QThread::usleep(qRound(msecs*1000));Best you try it with a small example. Within the thread you need to read the system clock and output.
At the day's end all depends on the actual thread scheduling of your computer and device. The weakest link in the chain determines the accuracy.
You will probably need to do a lot of testing. Also you need to consider what you actually want to have. One thing could be the even scaling for plotting or is it the precise and accurate knowledge of when the values are taken. -
Best you try it with a small example. Within the thread you need to read the system clock and output.
At the day's end all depends on the actual thread scheduling of your computer and device. The weakest link in the chain determines the accuracy.
You will probably need to do a lot of testing. Also you need to consider what you actually want to have. One thing could be the even scaling for plotting or is it the precise and accurate knowledge of when the values are taken.