Question

I've written a simple console program to take a picture on Canon EOS 600D. It works fine so far but I would like to

  • get an event when the picture is taken
  • if it was a new image causing the event I would like to get it as a file object to access it's properties like file name

My event handler gets initialized but I don't get an event/callback when a picture is taken.

I read in other threads that it can be a problem if I'm working on Windows 64Bit but nearly all systems are 64 Bit today. Is that really a problem?

Here is the code I have so far:

#include "stdafx.h"
#include <EDSDK.h>
#include <EDSDKErrors.h>
#include <EDSDKTypes.h>
#include <string>
#include <iostream> 

using namespace std; 

EdsError getFirstCamera(EdsCameraRef *camera);
EdsError EDSCALLBACK handleObjectEvent(EdsObjectEvent event, EdsBaseRef object,     EdsVoid * context);

string nmea = "$GPRMC,122030.232,A,4317.2345,N,14025.3423,W,12.2,245.1,230711,002.5,E*6F";

int _tmain(int argc, _TCHAR* argv[])
{   
EdsError err=EDS_ERR_OK;
EdsCameraRef camera=NULL;
bool isSDKloaded=false;

// Initialize SDK
err=EdsInitializeSDK();
if(err==EDS_ERR_OK)
{
    isSDKloaded=true;
}

// Get first camera
if(err==EDS_ERR_OK)
{
    err=getFirstCamera(&camera);
}

// Open session with camera
if(err==EDS_ERR_OK)
{
    err=EdsOpenSession(camera);

    if(err==EDS_ERR_OK)
    {
        cout << "session started successfully" << endl;
    }
    else
    {
        cout << "session failed" << endl;
    }
}

EdsInt32 saveTarget = kEdsSaveTo_Camera;

// Set camera properties
if(err==EDS_ERR_OK)
{
    err = EdsSetPropertyData( camera, kEdsPropID_SaveTo, 0, 4, &saveTarget );

    if(err==EDS_ERR_OK)
    {
        cout << "camera properties set!" << endl;
    }
    else
    {
        cout << "not able to set camera properties" << endl;
    }
}

// Set object event handler
if(err==EDS_ERR_OK)
{
    err = EdsSetObjectEventHandler(camera, kEdsObjectEvent_All, 
                                                        handleObjectEvent, 
                                                        NULL);
    if(err==EDS_ERR_OK)
    {
        cout << "Event handler initialized!" << endl;
    }
    else
    {
        cout << "Not able to initialize event handler" << endl;
    }
}

// Take picture
if(err==EDS_ERR_OK)
{

    err = EdsSendCommand(camera, kEdsCameraCommand_TakePicture, 0);
    if(err==EDS_ERR_OK)
    {
        cout << "Picture successfully taken!" << endl;
    }
    else
    {
        cout << "not able to set camera properties" << endl;
    }
}

// End session and release SDK
EdsCloseSession(camera);
EdsTerminateSDK();

if(nmea != "")
{
    cout << nmea <<endl;
}
else
{
    cout << "das kann eigentlich nicht sein!" << endl;
}

system("Pause");

return 0;
}



EdsError getFirstCamera(EdsCameraRef *camera)
{
EdsError err=EDS_ERR_OK;
EdsCameraListRef cameraList=NULL;
EdsUInt32 count=0;

// Get camera list
err = EdsGetCameraList(&cameraList);

// Get number of cameras
if(err == EDS_ERR_OK)
{
    err = EdsGetChildCount(cameraList, &count);
    if(count == 0)
    {
        err = EDS_ERR_DEVICE_NOT_FOUND;
    }
}

// Get first camera retrieved
if(err == EDS_ERR_OK)
{
    err = EdsGetChildAtIndex(cameraList , 0 , camera);
}

// Release camera list
if(cameraList != NULL)
{
    EdsRelease(cameraList);
    cameraList = NULL;
}

return err;
}

EdsError EDSCALLBACK handleObjectEvent(EdsObjectEvent event, EdsBaseRef object, EdsVoid * context)
{
EdsDirectoryItemInfo objectInfo;
EdsError err=EDS_ERR_OK;
cout << "Event ausgelöst!" << endl;

switch(event)
{
    case kEdsObjectEvent_DirItemCreated:
        err = EdsGetDirectoryItemInfo(object, &objectInfo);

        if(objectInfo.isFolder == 1)
        {
            cout << "Der Ordner " << objectInfo.szFileName << " wurde erzeugt" << endl;
        }

        if(objectInfo.isFolder == 0)
        {
            cout << "Die Datei " << objectInfo.szFileName << " wurde erzeugt" << endl;
        }

        break;
    default:
        cout << "Prüfe den EventHandler!" << endl;
        break;
}

//Release object
if(object)
{
    EdsRelease(object);
}

return err;
}

Thank you for some help!

Best regards, Richard

No correct solution

OTHER TIPS

As stated in Seth's answer, you need a Windows message loop for the Canon SDK to work. No callbacks will be called if you are not processing the Windows messages.

Based on your code, you probably want to do something like this pseudocode:

bool bPhotoTaken = false;
main()
{
 // Initialize EDSDK, start session with camera, change SaveTo property
 // register ObjectEventHandler
 // send kEdsCameraCommand_TakePicture

   while((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
   {
     if(bRet == -1 || bPhotoTaken)
     {
         break;
     }
     else
     {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
     }
   }

  // Cleanup EDSDK
}

and your ObjectEventHandler callback, upon recieving the DirItemRequestTransfer, will download the image, and then set bPhotoTaken=true;, which will break the message loop and exit your application.

if you use sdk the version is 13.13.0, you can call EdsGetEvent() to get event from camera.

3.1.50 EdsGetEvent
Description
This function acquires an event from camera.
In console application, please call this function regularly to acquire the event from a camera.
Syntax
EdsError EdsGetEvent()

Firstly, the EDSDK doesn't really work in 64-bit mode, so use 32-bit. 64-bit is experimental at best.

Secondly, the EDSDK uses the legacy COM STA threading model, which requires that you have a Windows message loop running in your main thread. If you don't have a message loop, you won't get any callbacks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top