Exemple #1
0
        private void Initialize()
        {
            SDKHelper.CheckError(EDSDK.EdsInitializeSDK());
            SDKHelper.CheckError(EDSDK.EdsGetCameraList(out _cameraListPointer));

            LoadCamerasList(_cameraListPointer);
        }
Exemple #2
0
        public static void Initialize()
        {
            lock (lockObj) {
                if (!initialized)
                {
                    if (!DllLoader.IsX86())
                    {
                        //When EOS Utility by Canon is open in the background the EDSDK.EdsInitializeSDK throws an uncatchable AccessViolation Exception
                        //Therefore the system processes are scanned for this program and if found the initialization is prevented
                        var eosUtil = System.Diagnostics.Process.GetProcessesByName("EOS Utility");
                        if (eosUtil.Length > 0)
                        {
                            throw new Exception("Cannot initialize Canon SDK. EOS Utiltiy is preventing the DLL to load. Please close EOS Utility first to be able to connect to your Canon Camera!");
                        }
                    }

                    var err = EDSDK.EdsInitializeSDK();
                    if (err > 0)
                    {
                        throw new Exception($"Canon EdsInitializeSDK failed with code {err}");
                    }
                    else
                    {
                        initialized = true;
                    }
                }
            }
        }
Exemple #3
0
        private void btn_connect_click(object sender, RoutedEventArgs e)
        {
            IntPtr cameraList = new IntPtr(0);

            camera = new IntPtr(0);

            Int32 cameraCount = 0;
            EDSDK sdk         = new EDSDK();

            EDSDK.EdsInitializeSDK();
            EdsError = EDSDK.EdsGetCameraList(out cameraList);

            //EdsError = EdsGetCameraList(out cameraList);
            EDSDK.EdsGetChildCount(cameraList, out cameraCount);
            label.Content = "Connected camera count : " + cameraCount.ToString();


            if (cameraCount != 0)
            {
                EdsError = EDSDK.EdsGetChildAtIndex(cameraList, 0, out camera);
                //MessageBox.Show("EdsGetChildAtIndex err code : " + EdsError.ToString());
            }



            EdsError = EDSDK.EdsOpenSession(camera);
            if (EdsError == EDSDK.EDS_ERR_OK)
            {
                label.Content = "Camera connected";

                EDSDK.EdsSetPropertyEventHandler(camera, EDSDK.PropertyEvent_All, propertyEventHandler, IntPtr.Zero);


                SDKObjectEvnet += new EDSDK.EdsObjectEventHandler(objectEventHandler);
                //SDKObjectEvent += new SDKObjectEventHandler(objectEventHandler);

                EdsError = EDSDK.EdsSetObjectEventHandler(camera, EDSDK.ObjectEvent_All, SDKObjectEvnet, IntPtr.Zero);
                if (EdsError == EDSDK.EDS_ERR_OK)
                {
                    label.Content = "NO ERROR";
                }
                else
                {
                    label.Content = "ERROR : " + EdsError;
                }
                EDSDK.EdsSetCameraStateEventHandler(camera, EDSDK.StateEvent_All, cameraStateEventHandler, IntPtr.Zero);
            }
            else
            {
                label.Content = "Camera not connected";
            }
        }
Exemple #4
0
        public static uint InitCamera()
        {
            uint success;

            success = EDSDK.EdsInitializeSDK();
            if (success != EDSDK.EDS_ERR_OK)
            {
                Console.WriteLine("InitializeSDK failed");
            }
            else
            {
                Console.WriteLine("InitializeSDK success");
            }
            return(success);
        }
Exemple #5
0
        public SDK()
        {
            uint tmpError;

            tmpError = EDSDK.EdsInitializeSDK();
            if (tmpError != 0)
            {
                this.SDKState = false;
                //TODO Fehler behandeln
            }
            else
            {
                this.SDKState = true;
            }
        }
Exemple #6
0
        public bool Init()
        {
            IntPtr camList;
            int    camCount = 0;
            uint   err      = 0;

            //SETUP DELEGATES FOR LATER USE
            objEventHandlerDelegate   = new EDSDK.EdsObjectEventHandler(objEventHandler);
            propEventHandlerDelegate  = new EDSDK.EdsPropertyEventHandler(propEventHandler);
            stateEventHandlerDelegate = new EDSDK.EdsStateEventHandler(stateEventHandler);

            //INIT THE SDK THIS MUST BE CALLED BEFORE ANYTHING ELSE CAN BE DONE
            err = EDSDK.EdsInitializeSDK();
            if (err != EDSDK.EDS_ERR_OK)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed to init SDK");
                }

                return(false);
            }

            //GET ALL ATTACHED CAMERAS
            err = EDSDK.EdsGetCameraList(out camList);
            if (err != EDSDK.EDS_ERR_OK)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed to find a camera");
                }

                return(false);
            }

            //GET THE NUMBER OF ATTACHED CAMERAS
            err = EDSDK.EdsGetChildCount(camList, out camCount);
            if (err != EDSDK.EDS_ERR_OK)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed to get camera count");
                }

                return(false);
            }

            //IF THERE ARE 0 CAMERAS DETECETED THEN THROW AN ERROR
            if (camCount == 0)
            {
                if (errorEvent != null)
                {
                    errorEvent("No cameras found");
                }

                return(false);
            }

            //WE ONLY CARE ABOUT THE FIRST CAMERA WE FIND
            err = EDSDK.EdsGetChildAtIndex(camList, 0, out camObj);
            if (err != EDSDK.EDS_ERR_OK)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed to retrieve camera object");
                }

                return(false);
            }

            //SET THE EVENT HANDLERS FOR LATER USE
            err = EDSDK.EdsSetObjectEventHandler(camObj, EDSDK.ObjectEvent_All, objEventHandlerDelegate, IntPtr.Zero);
            if (err != EDSDK.EDS_ERR_OK)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed to set event handler");
                }

                return(false);
            }
            err = EDSDK.EdsSetPropertyEventHandler(camObj, EDSDK.PropertyEvent_All, propEventHandlerDelegate, IntPtr.Zero);
            if (err != EDSDK.EDS_ERR_OK)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed to set event handler");
                }

                return(false);
            }
            err = EDSDK.EdsSetCameraStateEventHandler(camObj, EDSDK.StateEvent_All, stateEventHandlerDelegate, IntPtr.Zero);
            if (err != EDSDK.EDS_ERR_OK)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed to set event handler");
                }

                return(false);
            }

            //OPEN THE SESSION TO THE CAMERA
            err = EDSDK.EdsOpenSession(camObj);

            //LET THE CALLING FUNCTION KNOW THIS ALL WORKED
            return(true);
        }
        /// <summary>
        /// Initializes the SDK.
        /// </summary>
        /// <remarks></remarks>
        private void initializeSDK()
        {
            UInt32 returnValue = EDSDK.EdsInitializeSDK();

            ReturnValueManager.HandleFunctionReturnValue(returnValue);
        }