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