Micro-Manager Core API


Move through this tutorial using the arrow keys.

Code looks like this.

Try to write the requested lines or scripts yourself, before looking at one of the many possible solutions. Use the web resources provided to find the appropriate functions. If you can not easily figure things out, do not hesitate to look at the answer, and use the example given to make your code work.

Documentation


The Micro-Manager wiki has a Programming Guide, which contains loads of useful information. In particular, the 2.0 Core API reference on the sidebar will be helpful in this tutorial.

There are two versions of the API reference, that contain the same information, but are built for different language bindings to the core (i.e. C++ or Java). Either one can work for this tutorial since they define the same functions. But one or the other might be easier to read depending on your programming background .

The C++ Core API Reference has the nice feature that the functions are grouped according to their function. The Java Core API Reference may have slightly more readable functions because the argument and return types are the ones you use in Beanshell, making it easier to figure out how to call a particular function. Refering to one (or both) of these will be useful throughout this tutorial.

Micro-Manager Beanshell scripting

Script-Button Panel Editor Pane Immediate Pane (REPL)

Generic Microscope control

Use the REPL to do the following:

Get the camera's current exposure:
mmc.getExposure();


Double the camera's current exposure:
mmc.setExposure(2 * mmc.getExposure());


Generic Microscope control

Shutter and Autoshutter

Detect if autoshutter is currently on. If so, turn it off. Open the shutter, snap an image, and close the shutter.

if (mmc.getAutoShutter()) 
   mmc.setAutoShutter(false);
mmc.setShutterOpen(true);
mmc.snapImage();
mmc.setShutterOpen(false);
To update the GUI to reflect the state of the hardware, use:
mm.app().refreshGUIFromCache();

Generic Microscope control

XY stage position

Figure out what position the XY stage is at, then move it to a position roughly 1000 µm away (be careful you dont smash an objective if youre on a real microscope)

p = mmc.getXYStagePosition();
mmc.setXYPosition(p.getX() + 1000.0, p.getY() + 200.0);
mm.app().refreshGUIFromCache();

Device Properties

In addition to these generic microscope functions, micro-manager has a generic system for exposing hardware functionality through Device properties. In this system, every Device has a set of Properties which have certain allowed Values.

For example, an XY stage device might have properties for accelleration and velocity, which accept positive floating point numbers as values. A Camera device might have a property for bit depth, which accepts 8, 10, 12, 14, or 16 as values. Properties can be controlled through the core. Every unique property is identified by the device name and the property name.

Device Properties

Get the name of all currently loaded devices and show them (using mm.scripter().message(name)). Note that the function to use returns a rather complex data structure, and you may need to look at the Java API to figure out how to handle it


devices = mmc.getLoadedDevices();
for (device: devices)
   mm.scripter().message(device);
                  

Device Properties

Get the name of the camera device, find the names of all its properties, and display them.


camera = mmc.getCameraDevice();
props = mmc.getDevicePropertyNames(camera);
propString = "";
for (prop: props) 
   propString += prop + ", ";
mm.scripter().message(propString);
               

Device Properties

Pick an interesting property, get its current value, then set a new value


mmc.getProperty(camera, "Binning");
               


mmc.setProperty(camera, "Binning", "2");
mm.app().refreshGUIFromCache();
               

Config groups

In order to avoid having to control each property individually, Config groups allow you to group multiple properties together, and define Presets, which have a single value for each property in the group. Usually, you will save these groups to a Micro-Manager configuration file, so that they will be automatically present when restarting the application. Since you're using the demo configuration here, there are already config groups defined.

Get the names of all config groups

configs = mmc.getAvailableConfigGroups();
configString = "";
for (config: configs) 
   configString += config + ", ";
mm.scripter().message(configString);
               

Config groups

Pick a config group and find the names of all its preset values

presets = mmc.getAvailableConfigs("Channel");
presetString = "";
for (preset : presets) 
   presetString += preset + ", ";
mm.scripter().message(presetString);
               
Change the config group to a different preset value

mmc.setConfig("Channel", "FITC");
mm.app().refreshGUIFromCache();
               
The End
Overview