MaxIm + JavaScript and MaxIm + PHP and ...

Discussion in 'Scripting and Programming' started by MikeT, Sep 12, 2015.

  1. MikeT

    MikeT Cyanogen Customer

    Joined:
    Apr 10, 2015
    Messages:
    8
    Hi there,

    Is there a way to control MaxIm DL from Java whitout using VB code?

    I am not a software development expert, so I don't know how I can create the MaxIm DL object same than VBScript but with Java code.

    Anyone knows?

    Regards,
    Mike.
     
  2. MikeT

    MikeT Cyanogen Customer

    Joined:
    Apr 10, 2015
    Messages:
    8
    Anyone?
     
  3. Doug

    Doug Staff Member

    Joined:
    Sep 25, 2014
    Messages:
    6,988
    Sure, you can control the Automation interface from just about any language. You'll have to find a Java reference for information on how to access COM Automation objects.
     
    MikeT likes this.
  4. MikeT

    MikeT Cyanogen Customer

    Joined:
    Apr 10, 2015
    Messages:
    8
    Thank you Doug,

    I spent two weeks looking for the way to control Maxim DL with Java in Google and I have not search anything about it. So, now I have one new thing to looking for.

    Thanks again, and if anyone have an example on how to do it, it will be welcome ;-)

    Mike.
     
  5. Doug

    Doug Staff Member

    Joined:
    Sep 25, 2014
    Messages:
    6,988
    MikeT likes this.
  6. Bob Denny

    Bob Denny Cyanogen Customer

    Joined:
    Oct 12, 2014
    Messages:
    801
    Location:
    DC-3 Dreams, SP, Mesa, Arizona +1 480 396 9700
    Mike T - Do you mean JavaScript? Then it is totally and effortlessly possible. Windows includes a killer good JavaScript engine, and it is natively able to talk to any Windows (COM) object in its native syntax. If this is what you mean, reply here and I will write up a simple little demo. Or you could download Microsoft's JScript 5.7 (not the .NET one, the one that is intrinsic to Windows) documentation. It's a bit daunting though. Ask me and I'll try to answer specific questions. If you mean real full Oracle Java then ignore the above.

    Instead of Java what about Python, Matlab, etc.? Could we broaden the question and get a really good answer? The super-cool thing about Windows objects is that they can be accessed from 22 languages.
     
    MikeT likes this.
  7. MikeT

    MikeT Cyanogen Customer

    Joined:
    Apr 10, 2015
    Messages:
    8
    Oh!! It can be done in Javascript!?!? It would be great!

    My main purpose is to control it via web, and as I didn't know that it can do with javascript, I thought to do it with java and jsp, but if it is possible to do with javascript, it would be.... simply amazing!

    If you can help me in my first step please, I would be very grateful.

    Thank you both for your big help.

    Regards,
     
  8. Bob Denny

    Bob Denny Cyanogen Customer

    Joined:
    Oct 12, 2014
    Messages:
    801
    Location:
    DC-3 Dreams, SP, Mesa, Arizona +1 480 396 9700
    Without trying to give you all info needed to know about the scripting environment in Windows, here is hopefully a quick start. The most difficult thing is to know that there is a 32- and 64-bit environment on Windows, and that MaxIm operates in the 32-bit environment. So you must be in a 32-bit environment to talk to it. To open a 32-bit shell, run C:\Windows\SYSWOW64\cmd.exe (yes, syswow64 for 32-bit). Save a shortcut to this on your desktop then modify its properties for font, size, color whatever, and for the startup folder (desktop is good). Now you have a nice 32-bit Windows shell icon. Copy the following into a Notepad and save as MaxTest.js on the desktop, save as ANSI not Unicode. Now open a shell and change directory to where this script is located. Try tab completion in the shell to help with files that contain spaces. FInally

    c:\foo> cscript MaxTest.js
    Code:
    //
    // Sample MaxIm control using Microsoft JScript/Javascript with COM extensions
    // Ref: http://www.microsoft.com/en-us/download/details.aspx?id=2764  (Script 5.6 Documentation)
    //      http://www.microsoft.com/en-us/download/details.aspx?id=22185 (Script Debugger)
    //      MaxIm DL help, Scripting
    //
    var SH = new ActiveXObject("WScript.Shell");
    var FSO = new ActiveXObject ("Scripting.FileSystemObject");
    var deskPath = SH.SpecialFolders("Desktop");
    WScript.StdOut.WriteLine("The desktop path is " + deskPath);  // WScript.Echo()
    var MaxCam = new ActiveXObject("MaxIm.CCDCamera");
    MaxCam.LinkEnabled = true;
    WScript.StdOut.WriteLine("Camera connected, starting 30 sec exposure");
    MaxCam.Expose(5, 1, 1);
    while(!MaxCam.ImageReady)
    {
        WScript.Sleep(1000);
        WScript.StdOut.WriteLine(".. tick ..");
    }
    WScript.StdOut.WriteLine(".. completed, image ready!");
    MaxCam.SaveImage(deskPath + "\\MyTestImage.fit");
    WScript.StdOut.WriteLine(".. Saved to the desktop");
    MaxCam.LinkEnabled = false;
    
    If you don't have the full Visual Studio, install the Microsoft Script Debugger (link in the sources, along with the Script docs) and put a statement debugger; in there to force a break. You must run with the //D switch. See the Script docs on how to make this permanent.
     
    MikeT likes this.
  9. MikeT

    MikeT Cyanogen Customer

    Joined:
    Apr 10, 2015
    Messages:
    8
    Wow! Thank you very much Bob Denny.

    Last night, I was investigating about COM Automation, and I saw that PHP could also control the COM Automation, so I tried and I could control MaxIm with PHP.

    If it could help to anyone I leave here the code I made:

    Code:
    <?php
    
    /**
    * @author Mike T
    * @copyright ©2015 Mike T
    */
    
    /*
    * To use the Class COM in your php files, if you get an error like this:
    * "Fatal error: Class 'COM' not found in C:\xampp\htdocs\control\index.php on line 13"
    * you need to indicate that you are going to use it to your php.ini
    * You can do it adding the follow lines to the php.ini:
    * ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    * [PHP_COM_DOTNET]
    * extension=php_com_dotnet.dll
    * ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    * I add it in the Dynamic Extensions space, after this line:
    * extension=php_bz2.dll
    */
    
    try {
      
        //Create the MaxIm.CCDCamera object
        $camara = new COM ("MaxIm.CCDCamera") or die ("cannot create the MaxIm.CCDCamera object");
      
        //Connect the camera
        $camara->LinkEnabled = true;
    
        //If not connect, a warning
        if(!$camara){
            echo "Failed to start camera! <br>";
        }
    
        echo "Camera is ready, Exposing... <br>";
    
        //Exposing
        //1st parameter = exposition time
        //2nd parameter = 1 for light frame, 0 for dark frame
        //3rd parameter = (optional) index of filter used (if empty = 0 (no filter))
        $camara->Expose (5, 1, 0);
    
        //Do nothing until ImageReady will finish
        do {
          
        } while (!$camara->ImageReady);
        /*
         * Si aparece un error como "Fatal error: Maximum execution time of 30 seconds exceeded in...."
         * es por que el "set_time_limit" en "php.ini" es donde sestablece el número de segundos que se
         * permite la ejecución de un script. Si se sobrepasa este tiempo, el script devuelve un error
         * fatal. El límite predeterminado es de 30 segundos o, si es que existe, el valor "max_execution_time"
         * definido en el php.ini.
         * Así que hay que cambiar el valor, bien en uno (set_time_limit) o en (max_execution_time)
         */
    
        //Save the image in the path
        $camara->SaveImage ("C:\Users\<user-name>\Documents\Script.fit");
    
        echo "Exposure is done, Image saved as Script.fit <br>";
    
        } catch (com_exception $ce) {
            //If have any error
            echo $ce->getMessage();
        }
      
        //Disconnect the camera
        $camara->LinkEnabled = false;
    
    ?>
    As I said, thank you very much Bob Denny and thank you also Doug for your big, big help
     
    Last edited: Sep 17, 2015
  10. Bob Denny

    Bob Denny Cyanogen Customer

    Joined:
    Oct 12, 2014
    Messages:
    801
    Location:
    DC-3 Dreams, SP, Mesa, Arizona +1 480 396 9700
    Yes, PHP is one of the languages. No other OS has his ability to talk to detached objects from multiple languages! Not cross platform, but cross language. It's why Windows makes a really great OS for developing systems.
     
    Last edited: Sep 18, 2015

Share This Page