1

我在 EdsDownload 中有内部错误。我正在使用没有 SD 卡的 EOS 1100D。佳能示例代码(CameraContorol)可以下载图像。使用的 SDK:2.13 和 2.12(我有同样的问题)。请帮我。
注意:运行后“picture000x.jpg”大小为 0(因为 EdsCreateFileStream 调用)。

我的代码输出
设备名称:Canon EOS 1100D。
获取图片:
“调用”handleObjectEvent。
事件:kEdsStateEvent_JobStatusChanged,
事件代码:770

                          EdsDownload 内部错误。
流!= NULL
下载已结束。
按 键退出。

我的代码

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

EdsError DownloadImage(EdsDirectoryItemRef directoryItem);

处理状态事件:

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;
}

处理对象事件:

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;
}

主功能:

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;
}

下载图片功能:

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;
}
4

2 回答 2

1

感谢所有人!
我有解决办法。这不在 sdk 文档中。 这里是 这里如果您使用的是 Windows 操作系统,则存在此问题。
具体解决方案:

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

我将修复代码,删除不必要的注释,它对每个人都有效!(很快。)

于 2013-05-30T13:27:50.357 回答
0

你能检查一下“EdsCreateFileStream”的调用,尤其是第一个参数吗?根据文档“它在主机上创建一个新文件(或打开现有文件)并创建一个文件流以访问该文件。” 第一个参数应该是本地的、可访问的文件路径(例如,Windows 上的“C:\tmp.jpg”),快速查看可能是您没有正确指定它。你能打印这个吗?

于 2013-05-28T11:20:15.333 回答