3

I am using EDSDK v2.13 with my EOS 50D camera. I want to save taken pictures in my host. I am using this code (c++):

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

    EdsCapacity newCapacity = {0x7FFFFFFF, 0x1000, 1};
    err = EdsSetCapacity(camera, newCapacity);

  const char* ch_dest = "C:\\photo\\Img.jpg";
  EdsCreateFileStreamEx( ch_dest ,kEdsFileCreateDisposition_CreateNew,kEdsAccess_ReadWrite, 0);

    EdsSendCommand(camera, kEdsCameraCommand_TakePicture, 0);
    EdsCloseSession(camera);
    EdsTerminateSDK();

The camera shutter fires normally and I find the picture in the memory card of my camera but I cannot find it in my PC.

Please help.

user3510821
  • 113
  • 1
  • 5
  • 15

1 Answers1

11

it doesn't work that way. After you have taken the photo you need to catch the ObjectEvent and then download the file. It works something like this:

  • Open session
  • Set SaveTo_Both or Host
  • Set Capacity
  • Subscribe to the object event with EdsSetObjectEventHandler
  • Take photo
  • The object event should fire with "inEvent" being "kEdsObjectEvent_DirItemRequestTransfer"
  • Download the data:
    • Get info with EdsGetDirectoryItemInfo where "inDirItemRef" is "inRef" from the event
    • Create file stream with EdsCreateFileStream
    • Download the data with EdsDownload (inRef from the event, size from the DirectoryItemInfo)
    • Mark as finished with EdsDownloadComplete (inRef from the event)
    • Release the data with EdsRelease (inRef from the event)
    • Release the stream with EdsRelease

I'm sorry that I can't provide you actual code, I'm not a C++ developer. If you want I can show you some C# code though. To get more details on how the functions work, you could also check the documentation of the SDK.

Kind regards

Edit:

Ok, some C++ code with help of the documentation: Note that this is how it would work in it's barest form. You should always check if err != EDS_ERR_OK. And you should call Close only after the image has been downloaded.

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

    err = EdsInitializeSDK();
    err = EdsGetCameraList(&cameraList);
    err = EdsGetChildCount(cameraList, &count);
    if (count > 0)
    {
        err = EdsGetChildAtIndex(cameraList, 0, &camera);
        cameraList = NULL;
        err = EdsSetObjectEventHandler(camera, kEdsObjectEvent_All, handleObjectEvent, NULL);
        err = EdsOpenSession(camera);
        err = EdsSendCommand(camera, kEdsCameraCommand_TakePicture, 0);
    }
}

void Close(EdsCameraRef *camera)
{
    err = EdsCloseSession(camera);
    EdsRelease(camera);
    EdsTerminateSDK();
}

static EdsError EDSCALLBACK handleObjectEvent(EdsObjectEvent event, EdsBaseRef object, EdsVoid * context)
{
    if (event == kEdsObjectEvent_DirItemRequestTransfer)
    {
        EdsError err = EDS_ERR_OK;
        EdsStreamRef stream = NULL;
        EdsDirectoryItemInfo dirItemInfo;
        err = EdsGetDirectoryItemInfo(object, &dirItemInfo);
        err = EdsCreateFileStream(dirItemInfo.szFileName, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
        err = EdsDownload(object, dirItemInfo.size, stream);
        err = EdsDownloadComplete(object);
        EdsRelease(stream);
        stream = NULL;
    }
    if (object) EdsRelease(object);
}
Johannes Bildstein
  • 1,069
  • 2
  • 8
  • 20
  • Actually I am EDSDK new user, so I think an example of code will help (even in c#). Thanks in advance – user3510821 Apr 10 '14 at 07:58
  • Thanks for your response, but I still not able to find the image in my computer. – user3510821 Apr 11 '14 at 09:40
  • 1
    The image should be located right beside your program. If you need a different path you can add a path to "dirItemInfo.szFileName" in the EdsCreateFileStream line. If that doesn't work, did you get any errors? – Johannes Bildstein Apr 11 '14 at 11:14
  • No there is no errors. Does the image need time to be downloaded? because in my case I take a picture every 3 seconds? – user3510821 Apr 11 '14 at 13:02
  • 1
    @user3510821 Did you check the "err" variable every single line? there won't be an exception, it just returns an error value. It takes a bit time to download yes, but 3 seconds should be fine. If not, the the return value for "SendCommand" will be something like "Device busy" – Johannes Bildstein Apr 11 '14 at 13:11
  • can you share the c# code for the flow you described above ? – David Gidony Dec 20 '17 at 08:03
  • 1
    @DavidGidony have a look here: https://www.codeproject.com/Articles/688276/Canon-EDSDK-Tutorial-in-Csharp – Johannes Bildstein Dec 20 '17 at 09:26
  • hi Johannes, thanks for your help, I'm getting the image this way, but it is very small, how can I control it ? how does the Capacity = {0x7FFFFFFF, 0x1000, 1} translates to actual picture size ? thanks. – David Gidony Jan 10 '18 at 14:08
  • 1
    @DavidGidony you can set the image size with the ImageQuality property. The capacity command has nothing to do with it. Setting the capacity only tells the SDK how much space is left on the PC drive. – Johannes Bildstein Jan 17 '18 at 13:28
  • what is EdsBaseRef object in event handler. object is always null.How do I set this object. – debendra nath tiwary Mar 11 '20 at 18:08