i've been trying to make this work for some time now... read a lot of posts but none of them could fix this issue.
I am connecting to a EOS 550D using the Canon SDK. I am running win7 64bit and Visual Studio c# 2010.
What I do step by step is:
--> 0 Init SDK
err = EDSDK.EdsInitializeSDK();
--> 1 Getting camera list
err = EDSDK.EdsGetCameraList(out cameraList);
--> 2 Getting child count
err = EDSDK.EdsGetChildCount(cameraList, out cameraCount);
--> 3 If there is a child, get first child
err = EDSDK.EdsGetChildAtIndex(cameraList, 0, out cameraDev);
--> 4 Opening a session
err = EDSDK.EdsOpenSession(cameraDev);
--> 5 Telling the 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 Registring State event Handler
err = EDSDK.EdsSetCameraStateEventHandler(cameraDev, EDSDK.StateEvent_All, stateEventHandler, new IntPtr(0));
--> 8 Registring Object Event Handler
EDSDK.EdsObjectEventHandler edsObjectEventHandler = new EDSDK.EdsObjectEventHandler(objectEventHandler);
err = EDSDK.EdsSetObjectEventHandler(cameraDev, EDSDK.ObjectEvent_All, edsObjectEventHandler, IntPtr.Zero);
....
I dont get any error while doing this, all seems to be fine.
Here are 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 handler is ever called. Don't know why, I searche the net fpr quite some time, tried different approaches but did not get the callback...
Here is my method calling 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");
}
}
Maybe someone has an idea what I could try to make this work?
Thanks in advance!
Best regards, Tobias
MailboxProcessor
, so there were a million variables, turns out this is what fixed it. Specifically I had to callInitialzeSDK
andSetCameraAddedHandler
in a new thread, and callApplication.Run()
at the end of the thread. – Steffi