Note
Go to the end to download the full example code.
12.1.10.1.8. Timer#
This script creates an instance of a DummyGrabber
and implements a timer with an interval of 1000ms.
Every time, the interval is expired the method imageAcquisition
is called. It acquires a new image an appends it to the global
list myImages.
To stop the timer, call the method cancel. Additionally, the timer
is automatically interrupted after 10 iterations.
from itom import timer
from itom import dataIO
from itom import dataObject
Function for the image acquisition.
def imageAcquisition():
global iters
global t
global cam
global myImages
print("acquire next image")
cam.acquire()
d = dataObject()
cam.getVal(d)
globals()["myImages"].append(d.copy())
iters += 1
if iters >= 10:
t.stop()
Call this method (e.g. by your gui) to stop the timer.
def cancel():
global t
global cam
t.stop()
cam.stopDevice()
Define a DummyGrabber camera and timer for a timed acquisition.
cam = dataIO("DummyGrabber")
myImages = []
iters = 0
cam.startDevice()
t = timer(1000, imageAcquisition)
Total running time of the script: (0 minutes 0.040 seconds)