Software control of a Nikon Ti Z-drive

Dear all,

I would like to control the Z-drive of a Nikon Ti microscope (without PFS) from a home-written program. (The program is in Python, but I don’t mind using other languages if necessary.) I have found and tried using various solutions: directly controlling the (undocumented?) Nikon.TiScope.NikonTi COM object via pywin32, or controlling the Z-drive via Micro-Manager and pymmcore or pycro-manager. In all cases I have found that the control is rather brittle: requests for position change (MoveRelative()/MoveAbsolute() on the COM object, or setPosition() on MMCore) only sometimes result in actual physical motion; even when it does, the position reported back (Position() on the COM object, or getPosition() on MMCore) often fails to correctly update (and in any case never includes the “custom” z-offset set on the microscope, although that’s a much less important issue that can be worked around); and, on top of that, the whole process crashes with Windows access violations every so often.

Are these problems that others here have seen before? Does anyone have a solution for more robust control of the Nikon Ti Z-drive?

Thanks in advance,

Antony

Hi Anthony,

Does the Ti Z-drive function correctly in straight up Micro-Manager (i.e., in the MM UI)? If it does, I am quite confused why it would not work correctly through the pycro-manager bridge (or using pycro-manager). If it does not, there is most likely some kind of version mis-match somewhere (between firmware and driver, or MM version requirement and driver). COM objects are very annoying to work with, they need their own “COM event loop”, and hooks for callbacks, so you would somehow need to provide all that from your Python code (but maybe someone has figured that out). I wish that we could share the MM Nikon TI adapter code for inspiration, but Nikon does not allow us to do so…

Hi,
Thanks for your reply. Things work OK in the MM UI, but I haven’t tested it for very long periods of time with interlaced manual motion (via the physical scroll wheel on the microscope) and computer control, whereas I mostly see the computer control breaking after more or less long periods of such mixed controls, so perhaps I simply didn’t try the MM UI for long enough…
In any case I made some progress on my side via trial and error, so I’ll post this here in case it helps anyone: it looks like the value reported via the ZDrive.Position property of the COM object (which is the one that tends to go out of sync every once in a while) can be forcefully updated by first checking the the ZDrive.IsMounted property (even though that should always be true).