Results 1 to 5 of 5

Thread: Setting hardware configuration from external Python script

  1. #1
    Junior Member
    Join Date
    Apr 2018
    Posts
    4

    Setting hardware configuration from external Python script

    I have been working with the OAD to figure out what kind of control I can have over Zen. I have successfully loaded in the ZenWrapperLM and can control things like the light source. One command I am trying to gain access to is the "ReadHardwareSettings" so that I can update different aspects of the setup. When I use the command:

    Code:
    zen = win32com.client.GetActiveObject("Zeiss.Micro.Scripting.ZenWrapperLM")
    hw = zen.Devices.ReadHardwareSetting()
    print(type(hw))
    I get a str object that is "Zeiss.Micro.Scripting.ZenHardwareSetting"

    Is there a way to use the OAD to gain access to the ZenHardwareSetting object?

  2. #2
    CZ Administrators Carl Zeiss Microscopy 3's Avatar
    Join Date
    Jan 2013
    Posts
    397
    Is there a way to use the OAD to gain access to the ZenHardwareSetting object?
    Hello chris2018,

    First, I would like to recommend that you use the Macro Environment with its intellisense etc. to explore what you can do in OAD, especially with the ZenHardwareSetting-Object.

    The next step is to transfer this coding to the COM-world.

    But please be always aware that COM is different, which means that hw = zen.Devices.ReadHardwareSetting() will work but the ZenHardwareSetting generated is just in ZEN, not in your application. What I mean is that you just get a pointer to the ZenHardwareSetting but the ZenHardwareSetting itself is still only in ZEN.
    Last edited by Carl Zeiss Microscopy 3; 07-26-2018 at 10:12 AM.

  3. #3
    Junior Member
    Join Date
    Apr 2018
    Posts
    4

    Post Shutter control

    This makes sense. What I am looking for is a way to toggle the shutter on my microscope through Python3. Are there any suggestion on how to do this?

  4. #4
    CZ Administrators Carl Zeiss Microscopy 3's Avatar
    Join Date
    Jan 2013
    Posts
    397
    Hello chris2018,

    I would do it like this:

    1. Configure and save a hardware setting for each status, e.g. shutter status
    2. Open the hardware-settings just generated with an editor and remove all the things not related to what you intend to change.
      But be careful, the XML-file must still be valid!
    3. Load and Execute the hardware-setting(s) according to your needs


    I hope this gives you an idea

  5. #5
    CZ Administrators Carl Zeiss Microscopy 3's Avatar
    Join Date
    Jan 2013
    Posts
    397
    Hello all,

    I get a str object that is "Zeiss.Micro.Scripting.ZenHardwareSetting"
    let us first look up what type() does.

    If the single object argument is passed to type(), it returns type of the given object.

    E.g. see https://www.programiz.com/python-pro.../built-in/type

    The type is of course a string, saying that in this case it is a "Zeiss.Micro.Scripting.ZenHardwareSetting".
    I do not understand what is "really annoying" when it works as expected.

    To investigate the HardwareSetting please use the integrated Python-Editor of ZEN and start with steps like

    Code:
    hardwareSetting = Zen.Devices.ReadHardwareSetting()
    
    componentIds = hardwareSetting.GetAllComponentIds()
    
    for componentId in componentIds:
        print componentId
        
        parameterNames = hardwareSetting.GetAllParameterNames(componentId)
        
        for parameterName in parameterNames:
            print parameterName
            
            parameter = hardwareSetting.GetParameter(componentId, parameterName)
            print parameter
            
            hardwareSetting.SetParameter(componentId, parameterName, parameter)
    before using the COM-Interface.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •