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
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.