Micro-Manager Tutorial1 fail

I am learning how to write plugin/device adapters for MM. As I followed the instructions from https://micro-manager.org/wiki/Micro-Manager_Programming%20Guide .

I always get a error message of “Camera not loaded or initialized.”

Below is my code

import mmcorej.CMMCore;
public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World");
        CMMCore core = new CMMCore();
        String info = core.getVersionInfo();
        System.out.println(info);

      try {
         core.loadDevice("Camera", "DemoCamera", "DCam");
         core.initializeDevice("Camera");

         core.setExposure(50);
         //core.snapImage();
			
         if (core.getBytesPerPixel() == 1) {
            // 8-bit grayscale pixels
            byte[] img = (byte[])core.getImage();
            System.out.println("Image snapped, " + img.length + " pixels total, 8 bits each.");
            System.out.println("Pixel [0,0] value = " + img[0]);
         } else if (core.getBytesPerPixel() == 2){
            // 16-bit grayscale pixels
            short[] img = (short[])core.getImage();
            System.out.println("Image snapped, " + img.length + " pixels total, 16 bits each.");
            System.out.println("Pixel [0,0] value = " + img[0]);             
         } else {
            System.out.println("Dont' know how to handle images with " +
                  core.getBytesPerPixel() + " byte pixels.");             
         }
      } catch (Exception e) {
         System.out.println(e.getMessage());
         System.exit(1);
      }		
    }
    
} 

It runs and returns like below:

Hello, World
MMCore version 10.1.0
Camera not loaded or initialized.

I am using NetBeans IDE12.0 on windows 10.

Can any one help me out ?
thanks

Does your example has access to the mmgr_dal_DemoCamera.dll ?

"DemoCamera" is the dynamic library name where the adapter resides.

Hi phaub,

Thanks for reply!

Yes, I think my program does have access to mmgr_dal_DemoCamera.dll.

The Micro-Manager itself can run DemoCamera correctly. And I checked the installation directory to confirm the existence of that dll of which I even made a copy into my jar directory. So I guess it is not a accessibility problem…

Meanwhile, I also tried with BeanShell script language with MM script panel . Surprisingly, the same error message pops up. Have you or anyone ever encountered this problem ?

It’s hard to help without knowing your exact setup.

Your class file is neither a plugin nor a device adapter.
It is a class file how do you execute it?

The jar directory is not the right place for the dll’s.

What is the code you have tested in the MM script panel?

Are you using a full MM installation?
Which version?
Is MM working correctly?
Have you checked the ‘classpath setup’ and the ‘includes’ in your NetBeans?

More information can help.

Hi phaub,
Please allow me start from the simplest question:
The script code is from https://micro-manager.org/w/images/5/5f/Camera_test.bsh
I have installed both Ver1.4 and Ver2.0 gamma. (with win10 64bit homeEditon
And both gives me the following error message:
Line8:run-time error : Camera not loaded or initialized.
Both MM seem to work correctly.

I probably figured out the problem according to this link:

http://micro-manager.3463995.n2.nabble.com/strange-error-using-c-to-control-CMMCore-td7580869.html

The demo code is missing an important line: core.setCameraDevice("Camera");

1 Like

PERFECT ! :clap:
But be aware … it must be

core.setCameraDevice("Camera");

" … NOT … “
(maybe @nicost should notice this)

Hi phaub, thanks for point out the quotation mark problem :slight_smile:
And I also confirmed that, by adding the line of core.setCameraDecive("Camera") after camera initialization can help http://valelab.ucsf.edu/~MM/files/Tutorial1.java to run correctly.

I updated the Tutorial and the Tutorial files with that line of code.

Thanks for reporting, hopefully it will be easier for the next person going through that documentation!

Hi nicost,
Thanks for updating the Tutorial files.
Can you also please modify the “test script” from “Building_Micro-Manager_Device_Adapters”.
I found it has 2 errors:

  1. missing this line: mmc.setCameraDevice(“Camera”);
  2. missing a plus sign (+) in the last print() statement.

I post the tested script here:

mmc.unloadAllDevices();       
mmc.loadDevice("Camera", "DemoCamera", "DCam");
mmc.initializeDevice("Camera");
mmc.setCameraDevice("Camera");
mmc.setExposure(50); 
mmc.snapImage();
mmc.unloadAllDevices();       
mmc.loadDevice("Camera", "DemoCamera", "DCam");
mmc.initializeDevice("Camera");
mmc.setCameraDevice("Camera");
mmc.setExposure(50); 
mmc.snapImage();

if (mmc.getBytesPerPixel() == 1) {
  // 8-bit grayscale pixels
  byte[] img = (byte[])mmc.getImage();
  print("Image snapped, " + img.length + " pixels total, 8 bits each.");
  print("Pixel [0,0] value = " + img[0]);
}else if (mmc.getBytesPerPixel() == 2){
  // 16-bit grayscale pixels
  short[] img = (short[])mmc.getImage();
  print("Image snapped, " + img.length + " pixels total, 16 bits each.");
  print("Pixel [0,0] value = " + img[0]);             
}else {
  print("Dont' know how to handle images with " + mmc.getBytesPerPixel() 
                  +" byte pixels.");             
}