Scripting Resources for DigitalMicrograph™ |
Live Image Simulator - Periodic Thread |
|
Function |
Dialog-based script which uses a periodic thread to simulate a live camera view image. |
Version |
version:20210921, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
Thanks to Bernhard Schaffer for a good explanation of the MainThreadAddPeriodicTask() function in his Scripting Handbook available from: http://digitalmicrograph-scripting.tavernmaker.de/HowToScript_index.htm |
Comments |
This script uses a dialog to control a periodic thread, in this case updating an image with a changing geometric design. The periodic thread is useful because it runs in background and consumes no system resources when not active. Its timing is more reliable than script-based delays. However, it is still affected by script overheads and is not particularly precise. Aside from demonstrating dialog-script interactions and use of the very useful periodic thread function, this script may be useful for anyone developing acquisition or processing scripts which rely on an updating live camera image. This script can be used to create a simulated live view image and preliminary script develoment and testing can then be done away from the microscope. The output image is a cyclically varying geometric design. The image values vary between 0 and 255 making it suitable for integer, 1 byte acquisition.
|
System Requirements |
Tested on GMS 2.32, but should work on all versions of GMS. |
Known Issues |
Script is interpreted and not compiled, which makes it very slow. As such, execution is affected by the processing overhead. The periodic thread function timing is somewhat variable, though is probably a lot more precise than timing things with script delay loops or similar. The overhead is a function of what the periodic thread is being tasked to do. Here it simply updates an image using intrinsic variables. This is very fast and is not affected by image size. The fastest processing time per frame is around 0.03s. However, occasionally this would increase to 0.04s. For this reason, the minimum frame time (interval) in the script is set to 0.05s. However, if the processing step you were tasking the thread with were to be very intensive, then much longer intervals might be needed. Running the thread at shorter intervals than the minimum processing time could become problematic. When using periodic threads, it is essential that the minimum processing time is NOT set to 0.00s. This would cause the thread to run flat out, and it then becomes impossible to break in to stop it with the dialog. |
Supported |
Yes. |
Included Files |
Main script. |
Source Code |
see attached script |