0

I am trying to creat an Program for my Canon EOS Rebel T7, but when I try to send the command EDSDK.EdsSendCommand(CamConn,EDSDK.CameraCommand_TakePicture, 0) the program returns the error EDS_ERR_INVALID_HANDLE, how I can add an proper Handle for taking picktures? Thanks! Print of code here

1 Answers1

0

First, welcome to StackOverflow.

Tip for the future: copy/paste code into your question and don't link to a picture. It's easier for everyone to read and maybe copy it to try things themselves.


Now to your question:

Where does the CamConn handle come from? It's very likely that the OpenConnection call already returns an invalid handle error.

To get a valid camera handle you have to do the following:

public IntPtr[] GetConnectedCameraPointers()
{
    // get a list of connected cameras
    EDSDK.EdsGetCameraList(out IntPtr cameraList);
    // get the number of entries in that list
    EDSDK.EdsGetChildCount(cameraList, out int cameraCount);

    // create an array for the camera pointers and iterate through the list
    var cameras = new IntPtr[cameraCount];
    for (int i = 0; i < cameraCount; i++)
    {
        // gets an item of the list at the specified index
        EDSDK.EdsGetChildAtIndex(cameraList, i, out IntPtr cameraPtr);
        // get a device info for that camera, this is optional but may interesting to have
        EDSDK.EdsGetDeviceInfo(cameraPtr, out EdsDeviceInfo cameraInfo);
        // store the camera pointer in our array
        cameras[i] = cameraPtr;
    }

    // release the camera list
    EDSDK.EdsRelease(cameraList);

    return cameras;
}

Note that I haven't checked the returned error codes for simplicity but you should definitely check them.

Johannes Bildstein
  • 1,069
  • 2
  • 8
  • 20
  • Hi, Thanks for replying. I tested the open connection checking the errors, and the problem was there in open connetion. I used the code that your sent for select the camera id and I added the command for take pictures again, and it worked pretty well. Thanks a lot!! – Jhonny Andreatta Mar 25 '20 at 21:21
  • @JhonnyAndreatta sure thing, glad I could help! – Johannes Bildstein Mar 25 '20 at 23:01