Example #1
0
        private void RegisterEventHandlers()
        {
            //  Register OBJECT events
            m_edsObjectEventHandler = new EDSDK.EdsObjectEventHandler(objectEventHandler);
            uint result = EDSDK.EdsSetObjectEventHandler(
                this.Handle,
                (uint)ObjectEvent.All,
                m_edsObjectEventHandler,
                IntPtr.Zero);

            ReturnValueManager.HandleFunctionReturnValue(result);
        }
Example #2
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";
            }
        }
Example #3
0
        public Camera(IntPtr aPointer, ICameraNotifications aCameraNotifications)
        {
            _onCameraEvent           = DownloadImage;
            _onCameraStateChanged    = CameraStateChanged;
            _onCameraPropertyChanged = CameraPropertyChanged;
            _pointer             = aPointer;
            _cameraNotifications = aCameraNotifications;
            _eventHandlers       = new List <CameraEvent>();

            SDKHelper.CheckError(EDSDK.EdsOpenSession(_pointer));
            SDKHelper.CheckError(EDSDK.EdsSetObjectEventHandler(_pointer, EDSDK.ObjectEvent_All, _onCameraEvent, IntPtr.Zero));
            SDKHelper.CheckError(EDSDK.EdsSetCameraStateEventHandler(_pointer, EDSDK.StateEvent_All, _onCameraStateChanged, IntPtr.Zero));
            SDKHelper.CheckError(EDSDK.EdsSetPropertyEventHandler(_pointer, EDSDK.PropertyEvent_All, _onCameraPropertyChanged, IntPtr.Zero));
        }
Example #4
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);
        }