OPS>SOFTWARE>DOCUMENTATION>MATLAB CONFIGURATION

Matlab Configuration

Controlling LC Device via Micro-Manager from your Matlab environment

Reference: https://micro-manager.org/wiki/Matlab_Configuration

The following was tested using MM of version 1.4.5 with MatLab 2012a. Matlab has an extensive Java support which makes things easy and support Windows, Mac and Linux, just do the following:

The Micro-Manager Core Java API is contained in the file MMCoreJ.jar. Any Java program (including Matlab) that wants to use the Micro-Manager API needs to put MMCoreJ.jar in its ClassPath. When CMMCore Java object is first created in the calling program it will automatically attempt to load native library MMCoreJ_wrap. This library must be visible to the Java run-time. Default locations and exact names of libraries are platform dependent.

On Windows, the native library file is MMCoreJ_wrap.dll and it must reside either in the system path or in the current working directory of the program in order to be detected by the Java run-time.

MMCore can be used in Matlab through its Java interface. After setting up the Java environment as described above, MMCoreJ.jar must be added to Matlab Java class path and the directory for the MMCore dynamic libraries (including MMCoreJ_wrap) must be added to the system path.


  1. Install Micro-Manager in a path without any spaces (for instance: C:\Micro-Manager-1.4). Start by creating a configuration file. For this tutorial we use the GenericLC (demo) device adapter which is included in the OpenPolScope software installer. Any MatLab script developed using the GenericLC device adapter is applicable to actual device adapters. Please note some LC hardware may only work under centain OS supported by their device driver.

    Matlab_Config

    Matlab_Config

    Save this configuration file to 'C:\Micro-Manager1.4\MM_GenericLC_demo.cfg' and exit Micro-Manager

  2. Add the path with the drivers (all the .dll files) to the windows PATH enviromental variable (Start->Settings->Control Panel->System->Advanced->Environment Variables, make a new 'User variable for Administrator named 'PATH' and set it to the location of Micro-Manager (for instance: C:/Micro-Manager-1.4).

  3. In Matlab command prompt
    >> edit classpath.txt

    Add the location of the jar file you just installed (its in the Micro-Manager folder), include the .jar at the end, for instance:

    C:/Micro-Manager-1.4/ij.jar
    C:/Micro-Manager-1.4/plugins/Micro-Manager/MMCoreJ.jar
    C:/Micro-Manager-1.4/plugins/Micro-Manager/MMJ_.jar
    C:/Micro-Manager-1.4/plugins/Micro-Manager/bsh-2.0b4.jar
    C:/Micro-Manager-1.4/plugins/Micro-Manager/swingx-0.9.5.jar

  4. In Matlab command prompt

    >> edit librarypath.txt

    Add the location of the dll files, for instance:

    C:\Micro-Manager-1.4

  5. Restart Matlab

The following MatLab script provides an example of controlling (setting & reading) properties available via the device adapter interface.

% MatLab 2012a script for Micro-Manager & LC device control
import mmcorej.*; mmc = CMMCore; mmc.loadSystemConfiguration ('C:\Micro-Manager-1.4\MM_GenericLC_demo.cfg'); % Define Device Label that was used in the Micro-Manager Hardware Config. Wizard % Define Properties to be used - refer image below for examples (greyed out properties are read only) STR_KEY_DeviceLabel = 'GenericLC'; STR_KEY_VLC_PropertyRetardanceLC_A = 'Retardance LC-A [in waves]'; STR_KEY_VLC_PropertyRetardanceLC_B = 'Retardance LC-B [in waves]'; STR_KEY_VLC_PropertyRetardanceLC_A_nm = 'Retardance LC-A [in nm.]'; STR_KEY_VLC_PropertyRetardanceLC_B_nm = 'Retardance LC-B [in nm.]'; STR_KEY_VLC_PropertyStringSendTo = ['String send to -']; STR_KEY_VLC_PropertyStringFrom = ['String from -']; V1 = mmc.getProperty(STR_KEY_DeviceLabel, STR_KEY_VLC_PropertyRetardanceLC_A_nm); V2 = mmc.getProperty(STR_KEY_DeviceLabel, STR_KEY_VLC_PropertyRetardanceLC_B_nm); disp(['Values LC-A (nm) : ', char(V1.toString())]); disp(['Values LC-B (nm) : ', char(V2.toString())]); disp('Setting LC values using Property'); mmc.setProperty(STR_KEY_DeviceLabel, STR_KEY_VLC_PropertyRetardanceLC_A,'0.33'); mmc.setProperty(STR_KEY_DeviceLabel, STR_KEY_VLC_PropertyRetardanceLC_B,'0.55'); disp('Retrieved LC values using Property'); V1 = mmc.getProperty(STR_KEY_DeviceLabel, STR_KEY_VLC_PropertyRetardanceLC_A_nm); V2 = mmc.getProperty(STR_KEY_DeviceLabel, STR_KEY_VLC_PropertyRetardanceLC_B_nm); disp(['Values LC-A (nm) : ', char(V1.toString())]); disp(['Values LC-B (nm) : ', char(V2.toString())]); disp('Setting LC values using command'); mmc.setProperty(STR_KEY_DeviceLabel, STR_KEY_VLC_PropertyStringSendTo,'L 0.21 0.42'); % command 'L 0.21 0.42' sets retardance value of LC A & B to 0.21 & 0.42 respectively (refer device manual for command operations) disp('Retrieved command query response'); ret = mmc.getProperty(STR_KEY_DeviceLabel, STR_KEY_VLC_PropertyStringFrom); disp(['Command response : ', char(ret.toString())]); disp('Retrieved LC values using Property'); V1 = mmc.getProperty(STR_KEY_DeviceLabel, STR_KEY_VLC_PropertyRetardanceLC_A); V2 = mmc.getProperty(STR_KEY_DeviceLabel, STR_KEY_VLC_PropertyRetardanceLC_B); disp(['Values LC-A (waves) : ', char(V1.toString())]); disp(['Values LC-B (waves) : ', char(V2.toString())]); clear mmc

The other properties that are available can be viewed by opening Micro-Manager's Property Browser interface. Please note that while all the core properties are available for different LC device adapters, some are specifc (eg. Temp., TNE) to each device manufacturer.

Matlab_Config


© OpenPolScope | All Rights Reserved | Contact
Last Page Update on April 13 2015 13:09