GUI, Sleep() and Windows XP


I have attached a root macro with a code that shows the problems that I am experiencing.
I have a string of temperature sensors that I want to read and I have created a code that interfaces with the root GUI to show a graph in real time of the temperature reading. IMPORTANT For hardware reasons there has to be one second delay between one temp reading and the next. I have in mind a GUI with two buttons:

  1. Draw-> That connects to the sensor and starts reading/plotting the temp sensor reading. Inside this function I would have a do loop that keeps reading/plotting every second until the button “Exit” is clicked.
  2. Exit-> Closes the connection to the temp sensor, saves the plot, etc…

Because the temp sensor only has a windows driver I have to do this in WINDOWS (XP).

My problems:
After reading the temp for a couple of seconds my root GUI freezes completely and it doesn’t show the plot or the buttons. The attached macro simulates the same effect when run in WINDOWS XP. If I comment the gSystem->Sleep(1000);
line it all works fine.
Incidentally I don’t experience this problem in my mac, but, when the program is executing the temp reading loop it does not respond to me clicking the “Exit” button.

Any suggestion on how to address these problems?

example.C (1.97 KB)


There are several solutions… See for example the attached macro using a timer (based on your macro).

Cheers, Bertrand.
timer_example.C (2.86 KB)

Thanks Bertrand!

Clever solution! I am having some issues implementing your suggestion on my non-CINT program though, but I think it is mainly due to my lack of understanding on how TTimer works. If I haven’t figured it out by next week I will let you know.



You might find this recent discussion (and the source code posted there) interesting: [url]ROOT not responding