我在EdsDownload上有内部错误。我使用没有SD卡的EOS 1100D。佳能示例代码(CameraContorol)可以下载图像。使用的SDK:2.13和2.12(我对两者都有同样的问题)。请帮帮我 注意:运行后“picture000x.jpg”大小为0(因为EdsCreateFileStream调用)。
我的代码输出:
设备名称:Canon EOS 1100D
获得图片:
'调用'handleObjectEvent
事件:kEdsStateEvent_JobStatusChanged,
活动代码:770
EdsDownload的内部错误。
stream!= NULL
下载h.ended。
按键退出。
我的代码:
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;
}
主要功能:
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功能:
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;
}
答案 0 :(得分:1)
感谢All!
我有解决方案。这不在sdk文档中。
Here is
和here。如果您使用的是Windows操作系统,则存在此问题
具体的解决方案:
while(GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
我将修复代码,提出不必要的评论,这对每个人都有用! (不久。)
答案 1 :(得分:0)
你能检查一下“EdsCreateFileStream”的调用,特别是第一个参数吗?根据文档“它在主机上创建一个新文件(或打开一个现有文件)并创建一个文件流来访问该文件。”第一个参数应该是一个本地的,可访问的文件路径(例如Windows上的“C:\ tmp.jpg”),并且从快速查看它可能是你没有正确指定它。你能打印出来吗?