COM interface MATLAB ==> ZEN

Everything OAD-related that won't fit in the other categories: share general aspects of macro programming and discuss the OAD environment
Post Reply
user-5562
Posts: 2
Joined: Thu Jan 01, 1970 1:00 am

COM interface MATLAB ==> ZEN

Post by user-5562 »

I am running ZEN(blue) 2.6 on Win10 with Matlab 9.5 / 8.5 and I am having troubles getting this example to run:

https://github.com/sebi06/ZEN_Matlab/blob/master/RunZenExperimentFromMATLAB.m

after registering the DLLs with regScripting_Release.bat as Admin and enabling the service with

enableservice('AutomationServer',true)

When I try:

Zen = actxGetRunningServer('Zeiss.Micro.Scripting.ZenWrapperLM');

I get back an Zen object if ZEN is running ( and an error otherwise). However the Zen Object is empty:
The attachment ZenObject.jpg is no longer available
Zen.IsLiveRunning does not change independent of the actual state in ZEN.
The experiment ('bob') that I have defined in ZEN is not visible and consequently I can't access it:

ZEN_Experiment = 'bob.czexp';
exp = Zen.Acquisition.Experiments.GetByName(ZEN_Experiment);


leads to an error "Attempt to reference field of non-structure array" or "dot indexing not allowed" (depending on the version of Matlab).

I have no idea what I do wrong and would appreciate any help!

I should say that the reverse way (ZEN calling Matlab ) works and I have no problem whatsoever to run MATLAB from a czmac.

For example:

from System.Runtime.InteropServices import Marshal
from System.IO import Path, File, Directory, FileInfo
import os
MATLAB = Marshal.GetActiveObject('MATLAB.Application.9.5')
MATLAB.execute("eval('2+2')")
exp=Zen.Acquisition.Experiments.GetByName("bob")
img=Zen.Acquisition.Execute(exp)
MATLAB.PutWorkspaceData("A", "base", img)

works fine.

Robert
Attachments
ZenObject.jpg
ZenObject.jpg (140.68 KiB) Viewed 2678 times
user-5562
Posts: 2
Joined: Thu Jan 01, 1970 1:00 am

apparently the COM interface is currently broken in Zen 2.6

Post by user-5562 »

and will be fixed with an upcoming hotfix

Robert
user-4
Posts: 397
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

COM Interface in Zen 2.6
To solve your problem, please install Zen 2.6 Hotfix 5, which will be released soon.
user-6267
Posts: 2
Joined: Thu Jan 01, 1970 1:00 am

Still broken even after Hotfix?

Post by user-6267 »

As mentioned in this thread, the COM Object for external OAD Scripting usage seems to be broken. Though I applied the mentioned Hotfix 5 to my Zen Version (Zen Blue 2.6). Although the Zen Version I'm using is not upgraded from a former Zen Version as e.g. 2.3 but a fresh installed one.
Unfortunately I'm still running into problems calling the COM object from python.
When I'm trying to run this script:

import sys
import os
import win32com.client

Zen = win32com.client.GetActiveObject("Zeiss.Micro.Scripting.ZenWrapperLM")

i get the error message:

Traceback (most recent call last):
File "ZeissTestScript.py", line 5, in <module>
Zen = win32com.client.GetActiveObject("Zeiss.Micro.Scripting.ZenWrapperLM")
File "C:\Program Files\Python36\lib\site-packages\win32com\client\__init__.py", line 78, in GetActiveObject
resultCLSID = pywintypes.IID(Class)
pywintypes.com_error: (-2147221005, 'Ungültige Klassenzeichenfolge', None, None)

also a look at the registry shows that the object isn't registered.

I have no idea what I do wrong and would appreciate any help especially after applying the mentioned hotfix!

Best Regards
user-4
Posts: 397
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

also a look at the registry shows that the object isn't registered
Hello mrathke,

Applying Hotfix 5 (or later) to Zen Blue 2.6 is a must to use the COM interface.

You have to register the COM interface like

Code: Select all

cd "C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
regasm /codebase /tlb "C:\Program Files\Carl Zeiss\ZEN 2\ZEN 2 (blue edition)\Zeiss.Micro.LM.Scripting.dll"
regasm /codebase /tlb "C:\Program Files\Carl Zeiss\ZEN 2\ZEN 2 (blue edition)\Zeiss.Micro.Scripting.dll"
Also discussed here
Post Reply