我正在开发一个可以控制佳能相机的 Windows 8 Metro 应用程序。我的应用程序检测到相机并获取设备信息。但是当我打开相机会话“err = EdsOpenSession(cRef)”时,我收到错误“EDS_ERR_DEVICE_NOT_FOUND”。
但是当我调用以下函数时,我检测到了相机 -
private uint GetFirstCamera()
{
// Variable initilazions
IntPtr cameraList;
uint err;
int count;
// Get list of cameras;
err = EdsGetCameraList(out cameraList);
if (err != EDS_ERR_OK)
{
return err;
}
// Get count of cameras in list
err = EdsGetChildCount(cameraList, out count);
if (err != EDS_ERR_OK)
{
return err;
}
if (count == 0)
{
return EDS_ERR_DEVICE_NOT_FOUND;
}
// Get first camera to public cRef
err = EdsGetChildAtIndex(cameraList, 0, out cRef);
if (err != EDS_ERR_OK)
{
return err;
}
EDSDKLib.EDSDK.EdsDeviceInfo deviceInfo;
//Canon EOS REBEL T1i
if (err == EDS_ERR_OK)
{
err = EdsGetDeviceInfo(cRef, out deviceInfo);
if (err == EDS_ERR_OK & (cRef == null) == true)
{
err = (uint)EDS_ERR_DEVICE_NOT_FOUND;
}
}
// release camera list
if (cameraList != null)
{
EdsRelease(cameraList);
}
// everything went just fine
return EDS_ERR_OK;
}
这是我完整的初始化代码 -
public uint Initialize()
{
// err init
uint err;
// Initilize SDK.
// SDK initilizion is needed to use EDSDK functions
err = EdsInitializeSDK();
// In case of error pass it on...
if (err != EDS_ERR_OK)
{
return err;
}
// get first camera connected to computer
err = GetFirstCamera(); // **MY CAMERA IS DETECTED IN THIS FUNCTION**
if (err != EDS_ERR_OK)
{
return err;
}
err = EdsSetObjectEventHandler(cRef, ObjectEvent_All, ObjectEventHandler, IntPtr.Zero);
// Open session to camera
// **ERROR HAPPENS HERE .RETURNS ERROR CODE 128 - EDS_ERR_DEVICE_NOT_FOUND**
err = EdsOpenSession(cRef);
if (err != EDS_ERR_OK)
{
return err;
}
// We don't want to save pictures to the camera so lets set save target to host
err = EdsSetPropertyData(cRef, PropID_SaveTo, 0, 4, 1);
return err;
}
我在 WPF 应用程序上尝试了相同的代码并且它有效。这只发生在 Windows 商店应用程序/Metro 应用程序中。我的相机型号是佳能 EOS REBEL T1i。我使用的 SDK 版本是 2.11。