Question

I'm trying to download the images taken by my canon camera from its SD card to the host PC, I've written code so that it takes a shot and no longer saves it on the SD card, but I cannot find it on the host PC either. Does anyone have any directions?? My main and functions is shown below, with the getFirstCamera function excluded.

I don't really know how the callback functions etc work at all.. so it'd be great if anyone could provide snippets of code if there're things to fix

#include <stdio.h>
#include "EDSDK.h"
#include "EDSDKTypes.h"
#include "EDSDKErrors.h"

EdsError getFirstCamera(EdsCameraRef *camera);
EdsError downloadImage(EdsDirectoryItemRef directoryItem);
EdsError EDSCALLBACK handleStateEvent (EdsStateEvent event,EdsUInt32 parameter,EdsVoid * context);
EdsError EDSCALLBACK handleObjectEvent( EdsObjectEvent event,EdsBaseRef object,EdsVoid * context);
EdsError EDSCALLBACK handlePropertyEvent (EdsPropertyEvent event,EdsPropertyID property,EdsUInt32 inParam, EdsVoid * context);


int main(int argc, char **argv)
{
    EdsError err;
    EdsCameraRef camera = NULL;
    bool isSDKLoaded = false;
    EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
    EdsInt32 saveTarget = kEdsSaveTo_Host;

// 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
    err = EdsOpenSession(camera);

// Set event handler
    if(err == EDS_ERR_OK)   err = EdsSetObjectEventHandler(camera, kEdsObjectEvent_All,handleObjectEvent, NULL);
    if(err == EDS_ERR_OK)   err = EdsSetPropertyEventHandler(camera, kEdsPropertyEvent_All,handlePropertyEvent, NULL);
    if(err == EDS_ERR_OK)   err = EdsSetCameraStateEventHandler(camera, kEdsStateEvent_All,handleStateEvent, NULL);

    err = EdsSetPropertyData( camera, kEdsPropID_SaveTo, 0, 4, &saveTarget );

    err = EdsSetCapacity(camera, capacity);

///// Take picture
    err = EdsSendCommand(camera, kEdsCameraCommand_TakePicture, 0);
////

// Close session with camera
if(err == EDS_ERR_OK)
{
    err = EdsCloseSession(camera);
}

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

// Terminate SDK
if(isSDKLoaded)
{
    EdsTerminateSDK();
}
}


EdsError EDSCALLBACK handleObjectEvent( EdsObjectEvent event,EdsBaseRef object,EdsVoid * context)
{
    EdsError err=EDS_ERR_OK;

switch(event)
{
    case kEdsObjectEvent_DirItemRequestTransfer:
        err = downloadImage(object);
        break;
    default:
        break;
}

// Object must be released
if(object){
    err = EdsRelease(object);
}
return err;
}

EdsError EDSCALLBACK handlePropertyEvent (EdsPropertyEvent event,EdsPropertyID     property,EdsUInt32 inParam, EdsVoid * context)
{
return EDS_ERR_OK;
}

EdsError EDSCALLBACK handleStateEvent (EdsStateEvent event,EdsUInt32 parameter,EdsVoid * context)
{
return EDS_ERR_OK;
}





EdsError downloadImage(EdsDirectoryItemRef directoryItem)
{
EdsError err = EDS_ERR_OK;
EdsStreamRef stream = NULL;
// Get directory item information
EdsDirectoryItemInfo dirItemInfo;
err = EdsGetDirectoryItemInfo(directoryItem, & dirItemInfo);

// Create file stream for transfer destination
if(err == EDS_ERR_OK)
{
err = EdsCreateFileStream(     dirItemInfo.szFileName,kEdsFileCreateDisposition_CreateAlways,kEdsAccess_ReadWrite,     &stream);
}
// Download image
if(err == EDS_ERR_OK)
{
err = EdsDownload( directoryItem, dirItemInfo.size, stream);
}
// Issue notification that download is complete
if(err == EDS_ERR_OK)
{
err = EdsDownloadComplete(directoryItem);
}
// Release stream
if( stream != NULL)
{
EdsRelease(stream);
stream = NULL;
}
return err;
}

No correct solution

OTHER TIPS

When you call EdsCreateFileStream, just prepend the fully qualified path where you want the file to go. dirItemInfo.szFileName is the file name only, so the image should appear in your working directory if you don't include a path.

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