Call device functions in scripting enviroment

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Call device functions in scripting enviroment

Siemons, M.E. (Marijn)

Hi all,

 

I am (relatively) new to micromanager and have a question about the scripting environment. I’m building a  device adapter for a deformable mirror in our set up and want to call functions from the device class using the script panel. Something like: mydevice.myfunction(‘input’). What would be the proper way to do this?

 

I think a workaround would be to add the functions as device properties and call them using mmc.setProperty(“mydevice”,”myfunction”,’input’) but there is probably a better solution.

 

Many thanks in advance!

 

Met vriendelijke groet, with kind regards,

 

Marijn Siemons

PhD candidate

 

Biophysics (Kapitein lab) | Cell Biology | Department of Biology | Faculty of Science | Utrecht University 
Visit us at: http://cellbiology.science.uu.nl/

 

Email: [hidden email]

Padualaan 8, 3584 CH Utrecht, Room O.502

 


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Call device functions in scripting enviroment

Nico Stuurman-2
Hoi Marijn,

On 2/8/18 6:47 AM, Siemons, M.E. (Marijn) wrote:
> I am (relatively) new to micromanager and have a question about the
> scripting environment. I’m building a  device adapter for a deformable
> mirror in our set up and want to call functions from the device class
> using the script panel. Something like: mydevice.myfunction(‘input’).
> What would be the proper way to do this?

As you probably already discovered, the Micro-Manager core strictly
separates its bottom level api (i.e. the interface to devices), and the
top level api (the interface to the user interface, scripts, etc..).  It
is therefore not possible to simply define a function in your device
adapter and call that from the top level api. Annoying?  Maybe, but this
separation of user interface and device interface has served well in
keeping everything working.

There are function calls to devices that have equivalents in the top
level api.  However, this set of calls depend on the device type. My
first instinct would be to implement a deformable mirror as an SLM
device
(https://valelab4.ucsf.edu/~MM/doc/MMDevice/html/class_m_m_1_1_s_l_m.html).
This gives you a set of functions that let you set "images" (I imagine
that your deformable mirror has a set of "pixels" whose state you can
set), and has the ability to upload a sequence of "images" that the
device can cycle through (hardware triggered).

It is possible that deformable mirrors warrant their own device type. 
To make that decision, one would need to study the interface of a couple
such devices and work out what the essential communality is.
>
> I think a workaround would be to add the functions as device
> properties and call them using
> mmc.setProperty(“mydevice”,”myfunction”,’input’) but there is probably
> a better solution.
>
Since it is impossible to abstract all functions needed each device,
every device can always declare properties.  So yes, you can more or
less always emulate whatever you need using properties (although that
can get cumbersome, and MM is not well structured to deal with
properties that are only available based on the state of other
properties, and or properties that need to be set in a certain order).

Hope this helps.  Good luck with your project!

Best,


Nico



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Call device functions in scripting enviroment

Avi.Ring
(as noted recently) an alternative (possibly desperate)  workaround if you need to call a (void) function from script with a small number of parameters, is to use a "stand alone" console app and call it, in script, with beanshells exec(). E.g in a windows MM setup: exec("C:\path..\program.exe arg1 arg2 arg3 arg4.."). It even worked very well using it inside Nico's  "runnables" script. Using a "dummy channel" it did the job inside the loop in multidimenisonal acquisition. The arg1 arg2... were changed under program control in the loop in order to switch wavelengths.

Should work if the deformable mirror is controlled with a reasonably small number of parameters.  

I used this to let  an old  LabJackU12 D/A (with VB DLL driver) switch wavelengths of an ancient sTILL going strong  Polychrome II (for which there is no documentation how to program). Neither the LabJack nor monochromator would have been easy to build proper device adaptors for.  But calling my VB.net console app from script was trivially easy to get to work (MM1.4).  (Of course, the downside with these cheap workarounds is the lack of initialization, shutdown, status messages callback and possibly a load of other resource/garbage problems I'm not aware of),  

Still a newbie to MM, I too had problems with the beanshell script examples, most of them didn't work for me with the DEMO configuration. Recent MM 1.4 build. Didn't research the problem).

Avi Ring
FFI, Norway
________________________________________
From: Nico Stuurman [[hidden email]]
Sent: Thursday, February 08, 2018 18:56
To: Micro-Manager General
Subject: Re: [micro-manager-general] Call device functions in scripting enviroment

Hoi Marijn,

On 2/8/18 6:47 AM, Siemons, M.E. (Marijn) wrote:
> I am (relatively) new to micromanager and have a question about the
> scripting environment. I’m building a  device adapter for a deformable
> mirror in our set up and want to call functions from the device class
> using the script panel. Something like: mydevice.myfunction(‘input’).
> What would be the proper way to do this?

As you probably already discovered, the Micro-Manager core strictly
separates its bottom level api (i.e. the interface to devices), and the
top level api (the interface to the user interface, scripts, etc..).  It
is therefore not possible to simply define a function in your device
adapter and call that from the top level api. Annoying?  Maybe, but this
separation of user interface and device interface has served well in
keeping everything working.

There are function calls to devices that have equivalents in the top
level api.  However, this set of calls depend on the device type. My
first instinct would be to implement a deformable mirror as an SLM
device
(https://valelab4.ucsf.edu/~MM/doc/MMDevice/html/class_m_m_1_1_s_l_m.html).
This gives you a set of functions that let you set "images" (I imagine
that your deformable mirror has a set of "pixels" whose state you can
set), and has the ability to upload a sequence of "images" that the
device can cycle through (hardware triggered).

It is possible that deformable mirrors warrant their own device type.
To make that decision, one would need to study the interface of a couple
such devices and work out what the essential communality is.
>
> I think a workaround would be to add the functions as device
> properties and call them using
> mmc.setProperty(“mydevice”,”myfunction”,’input’) but there is probably
> a better solution.
>
Since it is impossible to abstract all functions needed each device,
every device can always declare properties.  So yes, you can more or
less always emulate whatever you need using properties (although that
can get cumbersome, and MM is not well structured to deal with
properties that are only available based on the state of other
properties, and or properties that need to be set in a certain order).

Hope this helps.  Good luck with your project!

Best,


Nico



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Call device functions in scripting enviroment

Siemons, M.E. (Marijn)
In reply to this post by Nico Stuurman-2
Hi Nico,

Thanks for the detailed explanation.

A SLM like implementation would sound the most straight forward approach. However, we aim to control the DM through the library provided by the manufacturer (in this case it is a Mirao 52e from Imagine Optic) where we set Zernike modes values instead of actuator voltages.  For this reason I implemented it is a shutter device where each Zernike mode has an 'intensity'. It is however not ideal either.

I hope I can share de device adapter when I'm finished!

Met vriendelijke groet, with kind regards,

Marijn Siemons
PhD candidate

Biophysics (Kapitein lab) | Cell Biology | Department of Biology | Faculty of Science | Utrecht University 
Visit us at: http://cellbiology.science.uu.nl/

Email: [hidden email]
Padualaan 8, 3584 CH Utrecht, Room O.502

-----Original Message-----
From: Nico Stuurman [mailto:[hidden email]]
Sent: donderdag 8 februari 2018 18:56
To: Micro-Manager General
Subject: Re: [micro-manager-general] Call device functions in scripting enviroment

Hoi Marijn,

On 2/8/18 6:47 AM, Siemons, M.E. (Marijn) wrote:
> I am (relatively) new to micromanager and have a question about the
> scripting environment. I'm building a  device adapter for a deformable
> mirror in our set up and want to call functions from the device class
> using the script panel. Something like: mydevice.myfunction('input').
> What would be the proper way to do this?

As you probably already discovered, the Micro-Manager core strictly separates its bottom level api (i.e. the interface to devices), and the top level api (the interface to the user interface, scripts, etc..).  It is therefore not possible to simply define a function in your device adapter and call that from the top level api. Annoying?  Maybe, but this separation of user interface and device interface has served well in keeping everything working.

There are function calls to devices that have equivalents in the top level api.  However, this set of calls depend on the device type. My first instinct would be to implement a deformable mirror as an SLM device (https://valelab4.ucsf.edu/~MM/doc/MMDevice/html/class_m_m_1_1_s_l_m.html).
This gives you a set of functions that let you set "images" (I imagine that your deformable mirror has a set of "pixels" whose state you can set), and has the ability to upload a sequence of "images" that the device can cycle through (hardware triggered).

It is possible that deformable mirrors warrant their own device type. To make that decision, one would need to study the interface of a couple such devices and work out what the essential communality is.
>
> I think a workaround would be to add the functions as device
> properties and call them using
> mmc.setProperty("mydevice","myfunction",'input') but there is probably
> a better solution.
>
Since it is impossible to abstract all functions needed each device, every device can always declare properties.  So yes, you can more or less always emulate whatever you need using properties (although that can get cumbersome, and MM is not well structured to deal with properties that are only available based on the state of other properties, and or properties that need to be set in a certain order).

Hope this helps.  Good luck with your project!

Best,


Nico



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Call device functions in scripting enviroment

Nico Stuurman-2
Hi Marijn,

> A SLM like implementation would sound the most straight forward approach. However, we aim to control the DM through the library provided by the manufacturer (in this case it is a Mirao 52e from Imagine Optic) where we set Zernike modes values instead of actuator voltages.  For this reason I implemented it is a shutter device where each Zernike mode has an 'intensity'. It is however not ideal either.

In that case, create a property "Zernike Mode" that allows the same
values as the Imagine Optic api.  Sounds like a 1:1 match (unless
something more complex is going on).

> I hope I can share de device adapter when I'm finished!

Looking forward!  And have fun getting that interesting piece of
technology do something nice for your microscope!


Best,

Nico



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general