C # Canon SDK: no callback after CameraCommand_TakePicture

I have been trying to make this work for some time ... I read a lot of messages, but none of them could fix this problem.

I am connecting to the EOS 550D using the Canon SDK. I am running win7 64bit and Visual Studio C # 2010.

What I do step by step:

-> 0 Init SDK

err = EDSDK.EdsInitializeSDK(); 

-> 1 Get a list of cameras

  err = EDSDK.EdsGetCameraList(out cameraList); 

-> 2 Getting the number of children

  err = EDSDK.EdsGetChildCount(cameraList, out cameraCount); 

-> 3 If there is a child, take the first child

  err = EDSDK.EdsGetChildAtIndex(cameraList, 0, out cameraDev); 

-> 4 Opening a session

 err = EDSDK.EdsOpenSession(cameraDev); 

-> 5 Specifying sdk to save images locally

 IntPtr saveTo = (IntPtr)EDSDK.EdsSaveTo.Host; err = EDSDK.EdsSetPropertyData(cameraDev, EDSDK.PropID_SaveTo, 0, 4, saveTo); 

-> 6 Setting the available capacity on the host machine

  EDSDK.EdsCapacity capacity = new EDSDK.EdsCapacity(); if (err == EDSDK.EDS_ERR_OK) { capacity.NumberOfFreeClusters = 0x7FFFFFFF; capacity.BytesPerSector = 0x1000; capacity.Reset = 1; err = EDSDK.EdsSetCapacity(cameraDev, capacity); } 

-> 7 Processing the registration status recorder

 err = EDSDK.EdsSetCameraStateEventHandler(cameraDev, EDSDK.StateEvent_All, stateEventHandler, new IntPtr(0)); 

-> 8 Register an object's event handler

  EDSDK.EdsObjectEventHandler edsObjectEventHandler = new EDSDK.EdsObjectEventHandler(objectEventHandler); err = EDSDK.EdsSetObjectEventHandler(cameraDev, EDSDK.ObjectEvent_All, edsObjectEventHandler, IntPtr.Zero); 

....

I get no errors when doing this, everything seems to be all right.

Here is my handler

  private uint objectEventHandler(uint inEvent, IntPtr inRef, IntPtr inContext) { Console.WriteLine("HALLLOOOOOOOOOO"); switch (inEvent) { case EDSDK.ObjectEvent_DirItemCreated: //this.invokeNewItemCreatedEvent(new NewItemCreatedEventArgs(getCapturedItem(inRef))); Console.WriteLine("Directory Item Created"); break; case EDSDK.ObjectEvent_DirItemRequestTransfer: Console.WriteLine("Directory Item Requested Transfer"); break; default: Console.WriteLine(String.Format("ObjectEventHandler: event {0}, ref {1}", inEvent.ToString("X"), inRef.ToString())); break; } return 0x0; } public uint stateEventHandler(uint inEvent, uint inParameter, IntPtr inContext) { Console.WriteLine("stateEventHandler " + inEvent); switch (inEvent) { case EDSDK.StateEvent_JobStatusChanged: Console.WriteLine(String.Format("There are objects waiting to be transferred. Job status {0}", inParameter)); break; case EDSDK.StateEvent_ShutDownTimerUpdate: if (inParameter != 0) Console.WriteLine(String.Format("shutdown timer update: {0}", inParameter)); break; case EDSDK.ObjectEvent_DirItemRequestTransfer: //WHAT I NEED!!! Console.WriteLine("Hallo DirItemRequestTransfer"); //DownloadImage(obj); break; default: Console.WriteLine(String.Format("StateEventHandler: event {0}, parameter {1}", inEvent, inParameter)); break; } return 0; } 

...

So now my problem is that none of the handlers are ever called. I don’t know why, I searched for pure fpr for a long time, tried different approaches, but did not receive a callback ...

Here is my method invoking the take picture command:

  public void takePic() { if (cameraOpened) { Console.WriteLine( "taking a shot"); err = EDSDK.EdsSendCommand(cameraDev, EDSDK.CameraCommand_TakePicture, 0); if (err != EDSDK.EDS_ERR_OK) Console.WriteLine("TakeCommand Error: " + err.ToString()); Console.WriteLine("Finished taking a shot"); } } 

Perhaps someone has an idea that I could try to make this work?

Thanks in advance!

Regards, Tobias

+7
source share
4 answers

I know that the SDK documentation says that the callback functions will be executed in a different thread, but for me, using the SDK 2.11 under Windows, callbacks always occur in the main thread and seem to be sent via Windows messages. This means that if you do not have a message pump, you will not receive callbacks. If your application is a C # graphical interface, you should have a message pump, but if it has a console application, it probably won't, try manually pumping messages after sending the TakePicture command. You can use Application.Run, but you will need to call Application.Exit somewhere, otherwise your message loop will never exit (for example, you can call it after loading the image from the camera).

+6
source

I have been using the C ++ SDK version for several months now.

After a quick scan, everything seems good in your code. I'm not sure about the C # / scoping garbage collection in this example, but you want your handlers to still "surround" after you install them.

Also, for the final EdsContext parameter, I use a pointer to my containing class instead of a null pointer.

 err = EDSDK.EdsSetObjectEventHandler(cameraDev, EDSDK.ObjectEvent_All, edsObjectEventHandler, IntPtr.Zero); 

If you don't need to contain event handlers in the class, this might not be a problem, but maybe multithreading in your application will bite you. From the EDSDK manual:

Assign the application information to be transmitted using the callback function. Any data required for your application may be transferred. In multi-threaded environments, the callback function is performed by the thread exclusively for the event . Use it appropriately, as when specifying this pointer to transfer data to user interface threads. Assign a NULL pointer if not needed.

You can also try and add a handlePropertyEvent handler that should activate white balance changes / switching to liveview, etc.

+1
source

I am connecting to the EOS 550D using the Canon SDK. I am running win7 64bit and Visual Studio C # 2010.

Your problem: Canon SDK compiled for X86. Do not look further! You must change the target architecture.

0
source

The way you subscribe to an object event does not really subscribe to anything. This is how I do it and it works great:

 event EDSDK.EdsObjectEventHandler SDKObjectEvent; void Init(IntPtr cameraDev) { SDKObjectEvent += new EDSDK.EdsObjectEventHandler(objectEventHandler); EDSDK.EdsSetObjectEventHandler(cameraDev, EDSDK.ObjectEvent_All, SDKObjectEvent, IntPtr.Zero); } 

Same principle for EdsStateEventHandler, EdsPropertyEventHandler and EdsCameraAddedHandler (and a bit different, but still with the EdsProgressCallback event)

Yours faithfully

0
source

All Articles