Thursday, May 03, 2012

A short note about using Canon EDSDK


I had been trying to automate an imaging process using a Canon 40D and Canon EDSDK 2.10. Basically, I wanted the camera to take a picture and send the image (directly from the camera buffer) to my computer. The computer would save/process the image afterwards.

I didn't want to have the camera saved the images on the memory card, since I needed to take a lot of images and I only had a 2 GB card.

I followed the samples in the Canon EDSDK API document and the VC sample code. My code was written in C.

At start, I couldn't have the object event handler worked properly. No object event was detected, even property and camera state events could be found. After countless attempts, I finally know why. I wrote what I found here and hope that it will be useful for other people as well.

1. Add a Windows message loop. 
It seems that the EDSDK relies on the Windows message loop to fire and dispatch events. Without it, no object event can be fired (so the object event handlers are never called).



Note that my code is written in Visual C++ Express 2010, and the subsystem in the project setting is Console (not Windows).

2. Set kEdsPropID_SaveTo property to SaveTo_Host. 



Somehow this property on my camera was set to SaveTo_Camera. Therefore, event 520 (kEdsObjectEvent_DirItemRequestTransfer) had never been fired after a picture was taken. Set it to SaveTo_Host and everything is fine.

3. Catch event kEdsObjectEvent_DirItemCreated
It is possible to retrieve the image from the memory card when kEdsPropID_SaveTo property is set to SaveTo_Camera. The workaround is to catch is event 516 (kEdsObjectEvent_DirItemCreated). As this is more like a trick, I do not recommend using it.

Ensure that the memory card is inserted to the camera. Otherwise, no event 516 can be generated.