Hello,
I'm interfacing with ZEN through the Python COM interface to handle hardware control for a GUI I'm developing. Has anyone successfully enabled multithreading for commands to ZEN through the COM interface?
For instance, my GUI becomes unresponsive while the it waits for focusing to finish (Zen.Devices.Focus.MoveTo(position)). I tried running that command in a thread and I get an error:
"pywintypes.com_error (-2147221008, 'CoInitialize has not been called.', None, None)"
Pleas let me know if you have any suggestions or alternative ways to maintain GUI responsiveness while ZEN commands are executing.
Python threading for hardware control (COM interface)
-
- Posts: 1
- Joined: Wed Aug 03, 2022 4:03 pm
-
- Posts: 180
- Joined: Wed May 20, 2020 10:10 am
Re: Python threading for hardware control (COM interface)
Hello Jacob O'Brien,
The 'SimpleInterface' of OAD, which is the basis for e.g. the macro commands and the COM interface, is by design not meant to be used in an multithreading environment.
One of the main features of the SimpleInterface is that commands work sequentially, which makes it easy for 'normal programmers' to set up a macro etc. for a certain workflow.
In other words: Zen.Devices.Focus.MoveTo(position) is waiting for the MoveTo to finish before the next command is executed ‘by philosophy’.
I hope this helps.
Sorry, but there seems to be some basic misunderstanding.multithreading for commands to ZEN through the COM interface
The 'SimpleInterface' of OAD, which is the basis for e.g. the macro commands and the COM interface, is by design not meant to be used in an multithreading environment.
One of the main features of the SimpleInterface is that commands work sequentially, which makes it easy for 'normal programmers' to set up a macro etc. for a certain workflow.
In other words: Zen.Devices.Focus.MoveTo(position) is waiting for the MoveTo to finish before the next command is executed ‘by philosophy’.
I hope this helps.
-
- Posts: 180
- Joined: Wed May 20, 2020 10:10 am
Re: Python threading for hardware control (COM interface)
Additional note for advanced programmers.
For various reasons the 'Simple Interface' has to run in the 'GUI-Thread of ZEN' and it is not possible to 'get hold of' or 'interact with' the 'GUI-Thread' via COM or macro.
For various reasons the 'Simple Interface' has to run in the 'GUI-Thread of ZEN' and it is not possible to 'get hold of' or 'interact with' the 'GUI-Thread' via COM or macro.