Getting Callbacks to work?  Topic is solved

Discussion regarding version 2.5 of the Canon EDSDK.

Re: Getting Callbacks to work?

Postby Joe » Wed Jan 13, 2010 7:13 pm



Hi pick,

I greatly appreciate your answer, thanks a lot. I added your hints to my program but it still doesn't work. The camera takes a picture but then the program gets deadlocked in the message loop. When I terminate the app and switch off the camera, the cam-display shows a message indicating that there are images left to be saved. This wasn't the case before. I suspect the sdk doesn't get the messages, but I'm not very familiar with this. Can you please look at my code again? Could you test if it works on your system? Thanks in advance!
Code: Select all
int main(int argc, char* argv[])
{
   EdsInitializeSDK();
   EdsError error ;
   EdsCameraListRef cameraList = NULL;
   EdsUInt32 count = 0;
   EdsCameraRef camera;

   error = EdsGetCameraList(&cameraList);
   error += EdsGetChildCount(cameraList, &count);
   error += EdsGetChildAtIndex(cameraList, 0, &camera);

   error += EdsSetPropertyEventHandler(camera, kEdsPropertyEvent_All, CameraEventListener::handlePropertyEvent, NULL);
   error += EdsSetObjectEventHandler(camera, kEdsPropertyEvent_All, CameraEventListener::handleObjectEvent, NULL);
   error += EdsSetCameraStateEventHandler(camera, kEdsPropertyEvent_All, CameraEventListener::handleStateEvent, NULL);

   error += EdsOpenSession(camera);

   EdsUInt32 saveTo = kEdsSaveTo_Host;
   error += EdsSetPropertyData(camera, kEdsPropID_SaveTo, 0, sizeof(saveTo), &saveTo);

   error += EdsSendStatusCommand(camera, kEdsCameraStatusCommand_UILock, 0);
   EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
   error += EdsSetCapacity(camera, capacity);
   error += EdsSendStatusCommand(camera, kEdsCameraStatusCommand_UIUnLock, 0);

   if(error == EDS_ERR_OK)
   {
      EdsSendCommand(camera, kEdsCameraCommand_TakePicture, 0);

      MSG Msg;
      BOOL bRet;

      while( (bRet = GetMessage( &Msg, NULL, 0, 0 )) != 0)
      {
         if (bRet == -1)
         {
            // handle the error and possibly exit
         }
         else
         {
            printf("Msg.message:%u\n", Msg.message);
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
         }
      }
   }   

   if(cameraList != NULL)
   {
      EdsRelease(cameraList);
      cameraList = NULL;
   }
   error = EdsCloseSession(camera);

   return 0;
}


Joe
 
Posts: 5
Joined: Tue Jan 12, 2010 10:56 am

Re: Getting Callbacks to work?

Postby pick » Wed Jan 13, 2010 7:30 pm

In your chunk of code:
Code: Select all
   error += EdsSetPropertyEventHandler(camera, kEdsPropertyEvent_All, CameraEventListener::handlePropertyEvent, NULL);
   error += EdsSetObjectEventHandler(camera, kEdsPropertyEvent_All, CameraEventListener::handleObjectEvent, NULL);
   error += EdsSetCameraStateEventHandler(camera, kEdsPropertyEvent_All, CameraEventListener::handleStateEvent, NULL);

It looks like you have a copy/paste error. The second parameter the function calls should not be kEdsPropertyEvent_All for all of them, it should be
kEdsObjectEvent_All for the object handler
kEdsStateEvent_All for the camera state handler, and
kEdsPropertyEvent_All only for the property handler

That may fix up your issues.....

Based on the camera behavior that you describe, I'd say all of your settings are now correct. The SDK/camera are just waiting for your handler to download the picture....

I can't run your code here, as our camera setup is in the field right now, and because you didn't include any of your handler code....
pick
Canon SDK Expert
 
Posts: 61
Joined: Mon Jan 19, 2009 6:45 pm

Re: Getting Callbacks to work?

Postby Joe » Thu Jan 14, 2010 8:26 am

Hi Pick,

It's working now and I'm feeling a little embarassed by that stupid mistake. The whole thing took me two days... :lol:
I'm in the mood of sending you a large pie, thanks for your help!

Best regards
Johannes
Joe
 
Posts: 5
Joined: Tue Jan 12, 2010 10:56 am

Re: Getting Callbacks to work?

Postby pick » Thu Jan 14, 2010 1:22 pm

No problem. I know how hard it is to sort through all the documentation. The more people that are successfully using the SDK the better off we all are.
pick
Canon SDK Expert
 
Posts: 61
Joined: Mon Jan 19, 2009 6:45 pm

Re: Getting Callbacks to work?

Postby jumpfroggy » Thu Jan 14, 2010 5:33 pm

pick wrote:No problem. I know how hard it is to sort through all the documentation. The more people that are successfully using the SDK the better off we all are.


So true. It's amazing; most of these hardships when learning the SDKs could be avoided by having good examples to work from, not the typo'd nonsense that comes in the SDK documentation. Maybe we should start posting some tutorial/examples on the wiki.
jumpfroggy
Canon SDK Professional
 
Posts: 21
Joined: Sat Oct 24, 2009 6:10 am

Re: Getting Callbacks to work?

Postby pick » Thu Jan 14, 2010 5:55 pm

I think Joe's example program above is a very good example. It is the bare-minimum (if you include the code for the handlers) required to get a command-line programming running. It demonstrates the requirement for a message pump (which can be excluded for some GUI related examples that only deal with the SDK in the main thread).

If it was better commented with eg:
- comments saying that the save-to and capacity are required to get the camera to download pictures
- a comment that says the image quality property must be read on some camera's to get a RAW+JPEG callback to work
- one for the message-pump and why it must be included

Maybe Joe would be willing to provide a stripped-down version of his command line example that you could post to the wiki...Joe?
pick
Canon SDK Expert
 
Posts: 61
Joined: Mon Jan 19, 2009 6:45 pm

Previous

Return to Canon EDSDK 2.5

Who is online

Users browsing this forum: No registered users and 2 guests