{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Timer\n\nThis script creates an instance of a ``DummyGrabber``\nand implements a timer with an interval of ``1000ms``.\n\nEverytime, the interval is expired the method ``imageAcquisition``\nis called. It acquires a new image an appends it to the global\nlist ``myImages``.\n\nTo stop the timer, call the method ``cancel``. Additionally, the timer\nis automatically interrupted after ``10`` iterations.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from itom import timer\nfrom itom import dataIO\nfrom itom import dataObject" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Function for the image acquisition.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def imageAcquisition():\n global iters\n global t\n global cam\n global myImages\n\n print(\"acquire next image\")\n cam.acquire()\n d = dataObject()\n cam.getVal(d)\n globals()[\"myImages\"].append(d.copy())\n iters += 1\n if iters >= 10:\n t.stop()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Call this method (e.g. by your gui) to stop the timer.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def cancel():\n global t\n global cam\n t.stop()\n cam.stopDevice()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define a ``DummyGrabber`` camera and timer for a timed acquisition.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "cam = dataIO(\"DummyGrabber\")\nmyImages = []\niters = 0\ncam.startDevice()\nt = timer(1000, imageAcquisition)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }