سؤال

I have internal error at the EdsDownload. I'am using EOS 1100D without sdcard. The Canon sample code (CameraContorol) can download image. Used SDK: 2.13 and 2.12 (i have same problem with both). Please help me.
Note: the "picture000x.jpg" size is 0 after the run (because the EdsCreateFileStream call).

My code output:
Device name: Canon EOS 1100D.
GET PICTURE:
'Call' handleObjectEvent.
Event: kEdsStateEvent_JobStatusChanged,
Event code: 770

                          Internal error at EdsDownload.
stream != NULL
Download h.ended.
Press key to quit.

My code:

bool getPictureEnabled = false,
     hasCamera = false;
EdsCameraRef camera;
EdsImageRef picture;
volatile EdsUInt32 bufferSize;

EdsError DownloadImage(EdsDirectoryItemRef directoryItem);

handleSateEvent:

EdsError EDSCALLBACK handleSateEvent(EdsStateEvent event, EdsUInt32 parameter, EdsVoid * context) {
    switch(event) {
    case kEdsStateEvent_CaptureError:
        printf("Event: kEdsStateEvent_CaptureError,\n");
        throw "Camera capture error.";

    case kEdsStateEvent_JobStatusChanged:
        printf("Event: kEdsStateEvent_JobStatusChanged,\n");
        break;

    default:
        break;
    }

    printf("Event code: %d.\n", (int)event);

    return EDS_ERR_OK;
}

handleObjectEvent:

EdsError EDSCALLBACK handleObjectEvent(EdsObjectEvent event, EdsBaseRef object, EdsVoid * context) {
    if(event == kEdsObjectEvent_DirItemCreated || event == kEdsObjectEvent_DirItemRequestTransfer || event == kEdsObjectEvent_DirItemRequestTransferDT) {
        if(!getPictureEnabled)  {
            printf("object event handler: FALSE alert\n");
            if(object) EdsRelease(object);
            return EDS_ERR_OK;
        }
        //EdsRetain(object);
        DownloadImage(object);
    }

    if(object) EdsRelease(object);

    return EDS_ERR_OK;
}

main function:

int main(int parC, char *pars[]) {
    int processCounter = 0;
    EdsCameraListRef eclr;
    EdsError edsError = EdsInitializeSDK();
    if(edsError)  {
        printf("I can't initialize the Eds sdk.\n");
        goto stop;
    }

    processCounter = 1;
    edsError = EdsGetCameraList(&eclr);
    if(edsError)  {
        printf("I can't get the camera list.\n");
        goto stop;
    }

    processCounter = 2;
    EdsUInt32 camCount;
    edsError = EdsGetChildCount(eclr, &camCount);
    if(edsError)  {
        printf("I can't read the camera count.\n");
        goto stop;
    }

    hasCamera = camCount > 0;
    if(!hasCamera)  {
        printf("There is no camera in the list.\n");
        goto stop;
    }

    edsError = EdsGetChildAtIndex(eclr, 0, &camera);
    if(edsError)  {
        printf("I can't get the camera.\n");
        goto stop;
    }

    edsError = EdsSetCameraStateEventHandler(camera, kEdsStateEvent_All, handleSateEvent, NULL);
    if(edsError) printf("Error at EdsSetCameraStateEventHandler.\n");

    edsError = EdsSetObjectEventHandler(camera, kEdsObjectEvent_All, handleObjectEvent, NULL);
    if(edsError)  {
        printf("Error at EdsSetObjectEventHandler.\n");
        goto stop;
    }

    edsError = EdsOpenSession(camera);
    if(edsError)  {
        printf("I can't open the session.\n");
        goto stop;
    }

    processCounter = 3;

    EdsDeviceInfo outDeviceInfo;
    edsError = EdsGetDeviceInfo(camera, &outDeviceInfo);
    if(edsError) printf("I can't get device info.\n");
    else printf("Device name: %s.\n", (char *) outDeviceInfo.szDeviceDescription);

    EdsUInt32 saveTo = kEdsSaveTo_Host;
    edsError = EdsSetPropertyData(camera, kEdsPropID_SaveTo, 0, sizeof(EdsUInt32) , &saveTo);
    if(edsError != EDS_ERR_OK) printf("Error at EdsSetPropertyData -> kEdsSaveTo.\n");

    EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
    edsError = EdsSetCapacity(camera, capacity);
    if(edsError != EDS_ERR_OK) printf("Error at EdsSetPropertyData -> kEdsSaveTo.\n");

    printf("GET PICTURE:\n");
    getPictureEnabled = true;
    edsError = EdsSendCommand(camera, kEdsCameraCommand_TakePicture , 0);

    if(edsError) printf("ERROR: Take picture.\n");
    else { //handleObjectEvent "call":
        printf("'Call' handleObjectEvent.\n");
        edsError = EdsCloseSession(camera);
        if(edsError) printf("I can't close the session 1.\n");

        edsError = EdsOpenSession(camera);
        if(edsError) printf("I can't open the session 2.\n");
    }

stop:
    printf("Press key to quit...\n");
    getchar();

    switch (processCounter) {

    case 3:
        edsError = EdsCloseSession(camera);
        if(edsError) printf("I can't close the session 2.\n");

    case 2:
        edsError = EdsRelease(eclr);
        if(edsError) printf("I can't release eds cam. list.\n");

    case 1:
        EdsTerminateSDK();

    default: break;
    }

    return 0;
}

DownloadImage function:

EdsError DownloadImage(EdsDirectoryItemRef directoryItem) {
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED ); //i tried without this, and don't screen change

    EdsError err;
    EdsStreamRef stream = NULL;

    EdsDirectoryItemInfo dirItemInfo;
    err = EdsGetDirectoryItemInfo(directoryItem, &dirItemInfo);

    if(err == EDS_ERR_OK) {
        err = EdsCreateFileStream(dirItemInfo.szFileName, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream);
        if(err != EDS_ERR_OK) printf("ERROR: EdsCreateFileStream.\n");
        bufferSize = dirItemInfo.size; 
        //EdsSetProgressCallback(stream, ProgressFunc, kEdsProgressOption_Periodically, NULL);
    }
    else printf("ERROR 1\n");

    //err = EdsSendStatusCommand(camera, kEdsCameraStatusCommand_UILock, 0); //i tried with this, and don't screen change
    //err = EdsSendStatusCommand(camera, kEdsCameraStatusCommand_EnterDirectTransfer, 0); //i tried with this, and don't screen change
    if(err) {
        printf("ERROR: transfer lock.\n");
    }//*/

    //if(err == EDS_ERR_OK)
    //do
    //{
        err = EdsDownload(directoryItem, dirItemInfo.size, stream); //HERE IS THE PROBLEM: EDS_ERR_INTERNAL_ERROR! (after that row: err = 2)
    //}
    //while(err != EDS_ERR_OK);//*/
    if(err == EDS_ERR_INTERNAL_ERROR) printf("\n\t\tInternal error at EdsDownload.\n");

    //if(err == EDS_ERR_OK)
    {
        err = EdsDownloadComplete(directoryItem);
    }

    // Release stream
    if( stream != NULL) {
        EdsCreateImageRef(stream, &picture);
        EdsRelease(stream);
        stream = NULL;
        printf(" stream != NULL\n");
    }

    //err = EdsSendStatusCommand(camera, kEdsCameraStatusCommand_ExitDirectTransfer, 0); //i tried with this, and don't screen change
    //err = EdsSendStatusCommand(camera, kEdsCameraStatusCommand_UIUnLock, 0); //i tried with this, and don't screen change
    if(err) {
        printf("ERROR: transfer lock.\n");
        return NULL;
    }//*/
    printf("Download ended.\n");

    CoUninitialize(); //i tried without this, and don't screen change
    return err;
}
هل كانت مفيدة؟

المحلول

Thank to All!
I have the solution. This is not in the sdk document. Here is and here. This problem exists, if you are using Windows operation system.
The concrete solution:

    while(GetMessage(&msg, NULL, NULL, NULL))
    {        
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    }

I will fix the code, erease the unecessary comments and it will working to everyone! (Soon.)

نصائح أخرى

Could you check the call for "EdsCreateFileStream", especially the first parameter ? According to the docs "It creates a new file on a host computer (or opens an existing file) and creates a file stream for access to the file." The first parameter should be a local, accessible file path (e.g. "C:\tmp.jpg" on windows), and from quickly looking at this it might be you don't specify this correctly. Could you print this?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top