简体   繁体   中英

Canon EDSDK EdsObjectEventHandler not called

We have a proper working C# Windows Forms Application to take pictures on external Events, send from external hardware connected by Ethernet. Now it should be used by a Broswser via a Webinterface instead of the Forms.WebBrowser control.

So I added a minimal Webserver, running in a Thread:

private void WebServerThread(int port)
{
  try
  {
    //start listing on the given port
    IPAddress localAddr = IPAddress.Parse("127.0.0.1");
    tcpIpListener = new TcpListener(localAddr, (int)port);
    tcpIpListener.Start();
    //start the thread which calls the method 'StartListen'
    Thread th = new Thread(new ThreadStart(StartListen));
    th.Start();
  }
  catch (Exception e)
  {
    ...
  }
}
public void StartListen()
{
  while (bServerRunning)
  {
    ...
    Socket mySocket = tcpIpListener.AcceptSocket();
    ...
    data = getHtmlPageFromSequencer(dataFromClient);
    SendToBrowser(data, ref mySocket);
    ...
  }
}

Opening the "StartWorkAndTakePictures"-Page starts the same process like before (in the old IEBrowserControl), the next Page is displayed, the Camera is initialised, the external device is started, send it's events, the camera take the shots at the correct times. Up to here it's like before...

BUT the event "Camera_SDKProgressCallbackEvent" (EDSDK.ObjectEvent_DirItemRequestTransfer = 0x00000208) from the Canon-SDK is not send (or recogniced), the the pictures are still on the Camera and not downloaded.

To clearify it: The same Program used with the WebBrowser-Control of the Main-Window works fine - the Event is called and the pictures are downloaded as well.

I'm thinking it's a Message Loop Problem, but I'm not so familiar with C# to fnd the error.

After many researches I reached to the solution, EDSDK sends callbacks over the main thread that enables windows forms message loop. So when you create the object that holds the implementation of EDSDK and callbacks, create it at that thread, this is a sample

Task.Run(() =>
{
    try
    {
        if (ConfigurationsManager.Instance.Configurations.Camera == CameraTypes.Nikon)
            _cameraService = new DslrCameraService(true);
        else if (ConfigurationsManager.Instance.Configurations.Camera == CameraTypes.CanonEOS1200)
            _cameraService = new CanonCameraService(true);
        else if (ConfigurationsManager.Instance.Configurations.Camera == CameraTypes.Multiple)
            _cameraService = new MultipleCameraService(true);
    }
    catch (Exception ex)
    {
        throw ex;
    }
}, TaskScheduler.FromCurrentSynchronizationContext());

Solution:

Adding "Application.DoEvents();" at the Loop which receives the commands from the external hardware and trigger the camera solves my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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