May 29, 2012

CanonEOSLib. An Adobe Native Extension to control a DSLR Canon camera

Article update: Canon EOSLib. Update

CanonEOSLib is an Adobe native extension for Windows that allows to control a Canon DSLR camera from an Adobe Air application. Following features are supported:

  1. Read or modify camera settings: Iso, Metering Mode, AeMode, Av, Tv, Image Quality, Exposure Compensation.
  2. Take pictures and save them on the file system.
  3. Press the shutter in three different ways.
  4. Capture the Live Preview signal.
  5. Change Live Preview focus.
CanonEosLib Sample App

Sample app using CanonEOSLib ANE

The extension should work – according to the manufacturer’s data – with the following models: Canon EOS-1Ds Mark III, Canon EOS-1D Mark IV, Canon EOS 5D Mark III, Canon EOS 5D Mark II, Canon EOS 7D, Canon EOS 60D, Canon EOS 600D/Rebel T3i, Canon EOS 550D/Rebel T2i, Canon EOS 1100D/Rebel T3 o Canon EOS 1000D/Rebel XS. Development and testing have been done with Canon EOS 1000D/Rebel XS.

Starting communication with the camera:

Using the following code we create the extension and we obtain a CanonEOSCamera object. This object represents a remotely connected camera and it is used to pass commands or to retrieve setting values. If multiple cameras are connected, we’ll get access only to one of them.

// init camera object

var canonLib : CanonEOSLib  = new CanonEOSLib();
var camera Camera : CanonEOSCamera = canonLib.getCamera();
camera.addEventListener( StatusEvent.STATUS, onChangeStatus );

// release camera object

camera.removeEventListener( StatusEvent.STATUS, onChangeStatus );
camera.release();
canonLib.dispose();

Read or modify settings:

In order to read or modify the camera settings there are three kind of methods we can use:

  1. Read the setting value, for example getIso()
  2. Get the possible values related with a setting​​, these values ​​change according to the camera model, current mode, etc. For example, if we set the camera to manual mode the setting values of ISO, Image Quality among others will be enabled and ready to modify, however, in video mode the only setting enabled is Exposure Compensation.
  3. Define a new value. For example setIso( newValue : uint ) . This new value must be in the list of possible values, if not, the camera will ignore the command.

For example, to obtain the current ISO value:

// get the current value

var currentIso : unit  = camera.getIso();

// get possible values
// EDSDKTypes.kEdsPropID_ISOSpeed is 
// a constant value representing the parameter Iso

var possibleValues : Array = new Array();
camera.getCameraPropertyDesc( EDSDKTypes.kEdsPropID_ISOSpeed,  possibleValues );

// set new value

var newIso : uint = 0x48;
var result : Boolean = camera.setIso( newValue );

//

The functions available to read or modify camera settings are:

// ISO
getIso()
setIso( newValue : uint )

// Aperture
getAv()	
setAv( newValue : uint )

// Velocity 
getTv()	
setTv( newValue : uint )

// AeModes ( Program, Manual, ...)
getAeMode()
setAeMode( newValue : uint )

// Metering mode
getMeteringMode()
setMeteringMode( newValue : uint )

// Image quality
getImageQuality()
setImageQuality( newValue : uint ) 

// Exposure compensation
getExposureCompensation()
setExposureCompensation( value : uint )

Available commands to execute:

Take a photo and save it in a given location:

camera.takePicture( "c:\Temp\test.jpg" )

Press the shutter button in three different ways:

pressingHalfway()
pressingCompletely()
pressingOff()

Start and stop LiveView and automatic focus :

// start liveView

camera.startEVF();

// start automatic focus

camera.evfAFOn();

// stop automatic focus

camera.evfAFOff();

// get liveView and draw it on bitmap object

var bmd : BitmapData = new BitmapData( camera.getEvfWidth(), camera.getEvfHeight(), false, 0xffffff );
var bm : Bitmap = new Bitmap( bmd );
addChild( bm );
camera.getEVF( bmd);

// stop liveView

camera.endEVF()

//

The getEVF(bitmapData) method captures the content visible on the Live Preview screen if it is active. To obtain a video sequence, the method should be called every time the camera dispatchs an EvfDataChanged event. This type of event notifies us the content of Live Preview has changed.

Events dispatched by the camera:

The camera generates different events to notify us changes in settings values. The following types of events are supported:

  • PropertyChanged : a setting has changed.
  • PropertyDescChanged : the possible values related with a setting have changed
  • EvfDataChanged : the Live Preview screen has changed.
  • DeviceBusy : the camera is processing an order.
  • Error: the last command has failed
  • Other: information about other events are not implemented

An example:

private function onChangeStatus(event : StatusEvent ):void
{

	var propId : uint;

	if( event.level == CanonEOSCamera.EvfDataChanged  )
	{
		// read new bitmap
	}

	else if( event.level == CanonEOSCamera.DeviceBusy )
	{
		// device unavailable
	}

	else if( event.level == CanonEOSCamera.PropertyChanged )
	{
		// the property id can be read 
		// inside the variable code in  
		// the StatusEvent object 

		propId = uint( "0x" +  event.code );
		if( propId == EDSDKTypes.kEdsPropID_IsoSpeed )
		{
			// actions when the property
			// Iso has changed
			
			var newIso : uint = camera.getIso();
	
                 }
	}
	
        else if( event.level == CanonEOSCamera.PropertyDescChanged )
	{
		var newIsoValues : Array = new Array();
		propId = uint( "0x" +  event.code );

		if( propId == EDSDKTypes.kEdsPropID_IsoSpeed )
		{
			camera.getCameraPropertyDesc( EDSDKTypes.kEdsPropID_Av, newIsoValues );
			
			// the new values ​​of the parameter uint Iso
                        // are stored in newIsoValues array
		}
	}

}

How to use Canon libraries

In order to connect the Adobe AIR runtime with the camera is essential to have the Windows libraries provided by Canon. You can get them at Canon program developers. The libraries you need are: EdsImage.dll, EDSDK.dll, DPPRSC.dll, DPPLibCom.dll and DPPDll.com.

We also require two files related with the Visual Studio: msvcp100.dll and msvcr100.dll or have .Net Framework 4.0 installed.

If we develop an C++ application, a single installer file is generated. This file contains extra files such as DLLs and it can be distributed as a whole. In case of an AIR app, we should add the .dll files to the src folder and then use the Flash Builder wizard to include them as part of the executable file.

export_app

Export to native installer

Conclusions

CanonEOSLib is another example of how to extend the capabilities of Adobe AIR. In the future, the extension could be extended to support multicamera functionality or maybe it could try to repeat the same functionality but using a Nikon camera.

25 Comments

  1. gokhan January 27, 2014

    hello how can use this code in adobe flash?

    • anton February 16, 2014

      in theory yes. My sample is done with Adobe Flash Builder 4.6

  2. Woojin January 28, 2014

    Hello~
    First.. Sorry my english..

    I live in South Korea.
    My name is Woojin.

    I’m looking at CanonEOSLib…
    Canon SDK version you are using please let us know.

    My FlashBuilder results are..
    “ArgumentError: Error #3500: The extension context does not have a method with the name initCamera.”

    SDK version is different?

    My development environment is..
    Windows7 x64, FlashBuilder4.7, Air SDK3.9, Canon EOS 5D Mark3

    I need your help.
    Please answer me..

    • Dave February 25, 2014

      Yes, I have this same problem with the no method named initCamera. What to do??? Really want to try and use this!

    • Dave February 25, 2014

      OK, got a little further with this. I copied the 5 canon dll’s to Windows\SysWOW64 and everything seems much happier.

  3. Andrew February 18, 2014

    Hello

    Thanks for the guide, I’m using adobe flash cs6.
    I’ve added libraries, EdsImage.dll, EDSDK.dll, DPPRSC.dll, DPPLibCom.dll and DPPDll.com as an included files.

    But when i publish it. it is saying error reading library files.

    Is there anything i missed?

    • Andre August 15, 2014

      Hi I have the same error and I trying since 3hours to get this to work. How did you do it?

  4. Andrew February 18, 2014

    I manage to got it working however when i start live preview it starts to crash.

    I believe it is too heavy. Can i know what setting to use?

    Thanks
    Andrew

  5. Dave February 25, 2014

    I got past the initCamera error, but now I have this problem:

    var canonLib:CanonEOSLib = new CanonEOSLib();
    trace(canonLib.extensionContextReady);

    I just get false from the trace always. So I can’t do this line:

    var camera:CanonEOSCamera = canonLib.getCamera();

    Any ideas?

    • Dave February 25, 2014

      OK, getting further still. Now I am able to issue:

      camera.takePicture( “c:\test\test.jpg” )

      And the camera takes a picture! Awesome. However, I get no image in c:\test

      Also, it works in Flash Pro, but when I make an AIR .exe file it fails to work.

  6. henri_b February 26, 2014

    can you upload the .air to test with my eos ?

  7. dseeker March 22, 2014

    I’ve got all the .dll in the same folder as the ANE, and configured the folder as included files in the AIR.

    still I only get to the second line (getCamera()) and get “ArgumentError: Error #3500: The extension context does not have a method with the name initCamera.”

    I understand it’s because flash is not talking to the library, just don’t understand why, any suggestions to debug?

    • dseeker March 22, 2014

      I was able to make it work only when published as a .exe, inside flash it doesn’t work. when I try to execute startEVF() the application closes with an error

  8. Gabriel May 2, 2014

    HI, Any chance you have an OSX version?

  9. amrit May 21, 2014

    I am not able to run above code i m using flash cs5.5 can anybody give me solution plz

  10. kilelr June 30, 2014

    any to update the ane to latest canon sdk?

  11. kilelr June 30, 2014

    any way to update this ane to latest sdk?

  12. jo July 2, 2014

    700d possible?

    • Jason October 27, 2014

      Do you solve problem based on 700d?
      I have a same issue.
      If you have a solution, let me know plz.
      thx.

  13. andre August 9, 2014

    Hi anybody knows how to get this to run? I’ve downloaded the Sample Code, I have Flash Builder 4.5, but how do I get this Code to run or how to import it? The Dll-files I haave already.

  14. Andre August 11, 2014

    Hi there, I only get packaging errors. Can you give us a little readme on github on how to bring this to work?

  15. chousse September 24, 2014

    When you take a picture, is it a snapshot of the liveview or it take a “real” photo ?

    THX

  16. Mr12 Fingers October 13, 2014

    Hi,
    Thanks for making this available. I’m trying to use the .ane and can compile an app properly but when I try to connect my camera the log spits out a ton of error codes such as:

    status: level error. code = 7
    status: level error. code = c1
    status: level error. code = 50

    It does say the device properties changes but the remote shooting dropdown is unavailable and the start EVF logs “device busy”. Is there somewhere I can find the error codes to see what’s wrong or do you have any clue? I’m using a Canon EOS 5D Mark III.

    Thank you in advance.

  17. unfinished November 17, 2014

    Dear all,
    It is just a joke for everyone, I was try many many times in different way. host never reply

Post a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>