简体   繁体   English

c#Canon SDK:CameraCommand_TakePicture之后没有回调

[英]c# Canon SDK: No callback after CameraCommand_TakePicture

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. 我使用Canon SDK连接到EOS 550D。 I am running win7 64bit and Visual Studio c# 2010. 我正在运行win7 64bit和Visual Studio c#2010。

What I do step by step is: 我一步一步做的是:

--> 0 Init SDK - > 0 Init SDK

 err = EDSDK.EdsInitializeSDK();

--> 1 Getting camera list - > 1获取相机列表

 err = EDSDK.EdsGetCameraList(out cameraList);

--> 2 Getting child count - > 2让孩子数

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

--> 3 If there is a child, get first child - > 3如果有孩子,请先生孩子

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

--> 4 Opening a session - > 4开会

err = EDSDK.EdsOpenSession(cameraDev);

--> 5 Telling the sdk to save images locally - > 5告诉sdk在本地保存图像

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 - > 6设置主机上的可用容量

 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 - > 7 Registring State事件处理程序

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

--> 8 Registring Object Event Handler - > 8 Registring对象事件处理程序

 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... 不知道为什么,我搜索网络fpr相当一段时间,尝试了不同的方法,但没有得到回调...

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 最好的问候,托比亚斯

I know the SDK documentation says that the callback functions will be executed in another thread, but for me, using SDK 2.11 under Windows, the callbacks always happen on the main thread and seem to be sent via Windows messages. 我知道SDK文档说回调函数将在另一个线程中执行,但对我来说,在Windows下使用SDK 2.11,回调总是发生在主线程上,似乎是通过Windows消息发送的。 This means that if you don't have a message pump you won't get the callbacks. 这意味着如果您没有消息泵,则无法获得回调。 If your app is a C# GUI app you should have a message pump, but if it's a console app you probably won't have one, so try manually pumping messages after sending the TakePicture command. 如果你的应用程序是一个C#GUI应用程序,你应该有一个消息泵,但如果它是一个控制台应用程序你可能没有,所以尝试在发送TakePicture命令后手动泵送消息。 You can use Application.Run but you'll need to call Application.Exit somewhere or else your message loop will never exit (eg you can call it after downloading the picture from the camera). 您可以使用Application.Run但是您需要在某处调用Application.Exit,否则您的消息循环将永远不会退出(例如,您可以在从相机下载图片后调用它)。

I'm using the C++ version of the SDK for some months now. 我正在使用SDK的C ++版本几个月了。

After a quick scan, all seems fine in your code. 快速扫描后,代码中的一切似乎都很好。 I'm not sure about the C# garbage collection/scoping in this example, but you want to make sure your handlers still "around" after you've set them. 我不确定这个例子中的C#垃圾收集/范围,但是你想确保你的处理程序在你设置之后仍然“在”周围。

Also, for the final EdsContext parameter I use a pointer to my containing class instead of your zero pointer. 另外,对于最终的EdsContext参数,我使用指向包含类而不是零指针的指针。

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

If you don't need to contain your event handlers in a class this might not be a problem, but perhaps multi-threading in your app bites you. 如果您不需要在类中包含事件处理程序,这可能不是问题,但您的应用程序中的多线程可能会让您感到困惑。 From the EDSDK manual: 从EDSDK手册:

Designate application information to be passed by means of the callback function. 通过回调函数指定要传递的应用程序信息。 Any data needed for your application can be passed. 您的应用程序所需的任何数据都可以传递。 In multithreaded environments, the callback function is executed by a thread exclusively for the event . 多线程环境中,回调函数由专用于该事件的线程执行 Use it appropriately, as in designating the this pointer to pass data to UI threads. 正确使用它,就像指定this指针将数据传递给UI线程一样。 Designate a NULL pointer if it is not needed. 如果不需要,则指定NULL指针。

You could also try and add a handlePropertyEvent handler that should trigger on changes in white balance/ switching to liveview, etc. 您还可以尝试添加一个handlePropertyEvent处理程序,该处理程序应该触发白平衡的变化/切换到实时视图等。

I am connecting to a EOS 550D using the Canon SDK. 我使用Canon SDK连接到EOS 550D。 I am running win7 64bit and Visual Studio c# 2010. 我正在运行win7 64bit和Visual Studio c#2010。

Your problem is there: the Canon SDK is compiled for X86. 你的问题是:Canon SDK是为X86编译的。 Don't look further ! 别再看了! You must change your target architecture. 您必须更改目标体系结构。

The way you subscribe to the object event doesn't really subscribe to anything. 订阅对象事件的方式并不真正订阅任何内容。 This is how I do it and it works fine: 我就是这样做的,它运行正常:

event EDSDK.EdsObjectEventHandler SDKObjectEvent;

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

Same principle goes for EdsStateEventHandler, EdsPropertyEventHandler and EdsCameraAddedHandler (and a bit different but still with an event EdsProgressCallback) EdsStateEventHandler,EdsPropertyEventHandler和EdsCameraAddedHandler的原理相同(有点不同但仍然带有事件EdsProgressCallback)

Kind regards 亲切的问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM