micro-manager / pycro-manager

Python control of micro-manager for customized data acquisition
https://pycro-manager.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
165 stars 52 forks source link

Listing a device properties from the Core instance #710

Closed jacopoabramo closed 1 year ago

jacopoabramo commented 1 year ago

Greetings,

I'm trying to access the entire list of properties of a device currently loaded in to the Micro-Manager core and categorize them to discern of what types they are using the getPropertyType function. Ideally I would like this process to be transparent of the device. From the snippet below:

from pycromanager import Core, start_headless, stop_headless, multi_d_acquisition_events, Acquisition
from pycromanager.zmq_bridge.bridge import Bridge

import logging

logging.basicConfig(level=logging.INFO)

logger = logging.getLogger()

mm_app_path = "C:\\Program Files\\Micro-Manager-2.0"

logger.info("Found Micro-Manager at: " + mm_app_path)

# Start the Java process
start_headless(mm_app_path, config_file=None)

logger.info("Started Micro-Manager headless, creating core... ")

core = Core()

demoDevices = {
    "Camera": ("DemoCamera","DCam")
}

try:

    for label, hardware in demoDevices.items():
        adapter, device = hardware
        core.load_device(label, adapter, device)
        core.initialize_device(label)

    core.set_camera_device("Camera")
    core.initialize_circular_buffer()

    print(core.get_device_property_names("Camera"))
except Exception as e:
    print(e)

logger.info("Done")

I get the following output:

INFO:root:Found Micro-Manager at: C:\Program Files\Micro-Manager-2.0
INFO:root:Started Micro-Manager headless, creating core... 
<pycromanager.zmq_bridge.bridge.mmcorej_StrVector object at 0x0000013F77B8B310>
INFO:root:Done

As one can see, it returns a mmcorej_StrVector

I've been checking the documentation a bit, and noticed the existance of the JavaClass class, but I'm not exactly sure how to use it for my purpose - or if it's of any use at all.

Thanks in advance

henrypinkard commented 1 year ago

Yes, this is one of the quirks of calling the Java wrapped core in python. You have to deal with these StrVector objects, rather than a list of str directly. you'll have to add another line to convert it to str:

str_vector = core.get_device_property_names("Camera")
list_of_str = [str(str_vector.get(i)) for i in range(str_vector.size())]

I've been checking the documentation a bit, and noticed the existance of the JavaClass class, but I'm not exactly sure how to use it for my purpose - or if it's of any use at all.

I don't think you'll need this for anything you're trying to do

jacopoabramo commented 1 year ago

Yep, that did the trick. Thanks.

Closing.