我编写了一个简单的控制台程序来在佳能 EOS 600D 上拍照。到目前为止它工作正常,但我想
- 拍摄照片时获取事件
- 如果它是导致事件的新图像,我想将它作为文件对象来访问它的属性,如文件名
我的事件处理程序已初始化,但在拍照时我没有收到事件/回调。
我在其他线程中读到,如果我在 Windows 64Bit 上工作可能会出现问题,但今天几乎所有系统都是 64 位的。这真的是个问题吗?
这是我到目前为止的代码:
#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;
}
谢谢你的帮助!
最好的问候,理查德