Adding a method to main application eventloop

Hello Rooters,

I want to write a simple DAQ, which currently runs as a while() loop. Attached is a macro that explains my problem. When I click on start, MyDaq::start() is executed. But this never returns unless the while loop is finished.

Instead of putting the acquisition in a while loop, I am thinking of putting it in the main application event loop, which is hopefully basicly the same thing as a while loop. (Please correct me if I am wrong here.)

I already have tried using the TTimer::SingleShot() Method to start the while loop. But this crashes the program after 32000 loops or so.

Also I did use a TTimer and connected the Timout() Signal to the acquire() slot (after removing the while() statement), but unfortunatly you cannot exceed ~100Hz eventrate doing that, because of some restrictions, as far as I understand.

Does anybody know a better aproach to solve this problem. (without using different threads)?

Thank you

Lutz
testpro.c (2.76 KB)

Hi Lutz,

what is the problem with your current approach? It is ok to let the DAQ loop run at full speed and only once in a while (relatively speaking) check for other ROOT events (like GUI updates, sync timers, etc.).

To exit the loop you can check the return value of TSystem::ProcessEvents(), if true, break. TO break use TROOT::SetInterrupt() (see ProcessEvents() description in doc or source).

Alternatively, if you don’t want to slow down the DAQ loop too much by calling ProcessEvents() at every iteration, either do it every so many iterations or, better use the TProcessEventTimer:

TProcessEventTimer *timer = TProcessEventTimer(100) //100ms
while (1) {


if (timer->ProcessEvents()) break;

}

Cheers, Fons.