Exemple #1
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));
        }
Exemple #2
0
 public Cameralist()
 {
     uint error = 0;
     //TODO export to init method
     this.cameraList = new ObservableCollection<Camera>();
     this.CameraAddedHandler = new EDSDKLib.EDSDK.EdsCameraAddedHandler(onCameraAdded);
     error = EDSDKLib.EDSDK.EdsSetCameraAddedHandler(cameraAddedHandler, IntPtr.Zero);
     this.cameraPropertyEventHandler = new EDSDK.EdsPropertyEventHandler(onCameraPropertyChanged);
     this.cameraStateEventHandler = new EDSDK.EdsStateEventHandler(onCameraStateChanged);
     if (error != EDSDK.EDS_ERR_OK)
     {
         //TODO Fehler behandeln
     }
     this.eventIDs = new EventCodes();
     this.propertyCodes = new PropertyCodes();
     scanToCameras();
 }
Exemple #3
0
        public Cameralist()
        {
            uint error = 0;

            //TODO export to init method
            this.cameraList         = new ObservableCollection <Camera>();
            this.CameraAddedHandler = new EDSDKLib.EDSDK.EdsCameraAddedHandler(onCameraAdded);
            error = EDSDKLib.EDSDK.EdsSetCameraAddedHandler(cameraAddedHandler, IntPtr.Zero);
            this.cameraPropertyEventHandler = new EDSDK.EdsPropertyEventHandler(onCameraPropertyChanged);
            this.cameraStateEventHandler    = new EDSDK.EdsStateEventHandler(onCameraStateChanged);
            if (error != EDSDK.EDS_ERR_OK)
            {
                //TODO Fehler behandeln
            }
            this.eventIDs      = new EventCodes();
            this.propertyCodes = new PropertyCodes();
            scanToCameras();
        }
Exemple #4
0
        int volumeChangedCounter; //used to measure the times of the "volume changed" events (two per download)

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initialises the SDK and adds events
        /// </summary>
        public SDKHandler(LogFile  _logFile, SettingsManager settings)
        {
            Error = EDSDK.EdsInitializeSDK();

            SDKStateEvent               += new EDSDK.EdsStateEventHandler(Camera_SDKStateEvent);
            SDKPropertyEvent            += new EDSDK.EdsPropertyEventHandler(Camera_SDKPropertyEvent);
            SDKObjectEvent              += new EDSDK.EdsObjectEventHandler(Camera_SDKObjectEvent);

            logFile = _logFile;

            photoParameters = new PhotoParameters();
            photoStats = new PhotoStats();

            PhotoInProgress = false;
            photoTimer = new Stopwatch();
            volumeChangedCounter = 0;

            //get the camera list of attached cameras
            CamList = GetCameraList();

            if (CamList.Count == 0)
            {
                logFile.WriteLine("There are no attached cameras");
                MessageBox.Show("There are no attached cameras");
                return;
            }
            else if (CamList.Count > 1)
            {
                MessageBox.Show("Found more than one attached Canon camera");
                logFile.WriteLine("There is more than one attached camera");
                return;
            }

            //open the session with the first camera (only a single camera is allowed)
            OpenSession(CamList[0]);

            //label the camera type
            String cameraDescription = MainCamera.Info.szDeviceDescription;
            //label camera serial number
            String cameraSN = GetSettingString((uint)EDSDK.PropID_BodyIDEx);
            //label firmware
            String cameraFirmware = GetSettingString((uint)EDSDK.PropID_FirmwareVersion);

            //CameraHandler.SetSetting(EDSDK.PropID_SaveTo, (uint)EDSDK.EdsSaveTo.Camera);
            //CameraHandler.SetSetting(EDSDK.PropID_SaveTo, (uint)EDSDK.EdsSaveTo.Host);
            SetSetting(EDSDK.PropID_SaveTo, (uint)EDSDK.EdsSaveTo.Both);
            SetCapacity();  //used to tell camera there is enough room on the PC HD (see codeproject tutorial)

            //get the capacity and loading of the camera card storage drive
            //also write out the names of the images to output
            cameraStats = StorageAssessment();

            //fill in the remainder of the camera parameters
            cameraStats.cameraDescription = cameraDescription;
            cameraStats.cameraSN = cameraSN;
            cameraStats.cameraFirmware = cameraFirmware;

            missionPlansFolder = settings.SaveToFolder;
            if (!Directory.Exists(missionPlansFolder)) Directory.CreateDirectory(missionPlansFolder);

            if (!Directory.Exists(missionPlansFolder + @"/TestImages/"))
                Directory.CreateDirectory(missionPlansFolder + @"/TestImages/");

            //default value -- update this
            ImageSaveDirectory = missionPlansFolder + @"/TestImages/";

            /////////////////////////////////////////////////////
            // camera settings for WaldoAir Flight Operations
            /////////////////////////////////////////////////////

            try
            {
                //set the aperture ---
                SetSetting(EDSDK.PropID_Av, CameraValues.AV(settings.Camera_fStop));
                logFile.WriteLine("Set the fStop:  " + settings.Camera_fStop);
                //set the shutter speed
                SetSetting(EDSDK.PropID_Tv, CameraValues.TV(settings.Camera_shutter));
                logFile.WriteLine("Set the shutter:  " + settings.Camera_shutter);
                //set the ISO
                SetSetting(EDSDK.PropID_ISOSpeed, CameraValues.ISO(settings.Camera_ISO));
                logFile.WriteLine("Set the ISO:   " + settings.Camera_ISO);
                //set the white balance to Daylight
                SetSetting(EDSDK.PropID_WhiteBalance, EDSDK.WhiteBalance_Daylight);
                logFile.WriteLine("Set the WhiteBalance:  DayLight");
            }
            catch
            {
                logFile.WriteLine(" could not set the camera parameters");
                MessageBox.Show("Problem setting the Camera parameters");
            }
        }
Exemple #5
0
        /// <summary>
        /// Registers API events
        /// </summary>
        private void registerEvents()
        {
            uint error;

                // Save image to Computer not camera
                 error = EDSDK.EdsSetPropertyData(this.CameraDevice, EDSDK.PropID_SaveTo, 0, 4, 2);

                //  Register STATE events
                edsStateEventHandler = new EDSDK.EdsStateEventHandler(stateEventHandler);
                error = EDSDK.EdsSetCameraStateEventHandler(this.CameraDevice, EDSDK.StateEvent_All, this.edsStateEventHandler, cameraDevice);
                if (EDSDK.EDS_ERR_OK != error)
                {
                    throw new CameraEventRegistrationException("Unable to register state events with the camera!", error);
                }

                //  Register PROPERTY events
                edsPropertyEventHandler = new EDSDK.EdsPropertyEventHandler(propertyEventHandler);
                error = EDSDK.EdsSetPropertyEventHandler(this.CameraDevice, EDSDK.PropertyEvent_All, edsPropertyEventHandler, cameraDevice);
                if (EDSDK.EDS_ERR_OK != error)
                {
                    throw new CameraEventRegistrationException("Unable to register property events with the camera!", error);
                }

                //  Register OBJECT events
                edsObjectEventHandler = new EDSDK.EdsObjectEventHandler(objectEventHandler);
                error = EDSDK.EdsSetObjectEventHandler(this.CameraDevice, EDSDK.ObjectEvent_All, edsObjectEventHandler, IntPtr.Zero);
                if (EDSDK.EDS_ERR_OK != error)
                {
                    throw new CameraEventRegistrationException("Unable to register object events with the camera!", error);
                }
            #if needed
                // Register PROGRESS events
                edsProgressCallbackHandler = new EDSDK.EdsProgressCallback(progressEventHandler);
                error = EDSDK.EdsSetProgressCallback(this.cameraDevice, edsProgressCallbackHandler, EDSDK.EdsProgressOption.Periodically, IntPtr.Zero);
                if (EDSDK.EDS_ERR_OK != error)
                {
                    //throw new CameraEventRegistrationException("Unable to register progress callback events with the camera!", error);
                }
            #endif
        }
Exemple #6
0
        public void CloseCamera()
        {
            if (this.cameraDevice != IntPtr.Zero)
                {
                    EDSDK.EdsCloseSession(this.cameraDevice);
                    this.cameraDevice = IntPtr.Zero;
                    this.edsObjectEventHandler = null;
                    this.edsPropertyEventHandler = null;
                    this.edsStateEventHandler = null;
            //                    this.edsProgressCallbackHandler = null;

                }
                EDSDK.EdsTerminateSDK();
        }
Exemple #7
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>
        /// Initialises the SDK and adds events
        /// </summary>
        public SDKHandler(StreamWriter _logFile, SettingsManager settings)
        {
            Error = EDSDK.EdsInitializeSDK();

            SDKStateEvent               += new EDSDK.EdsStateEventHandler(Camera_SDKStateEvent);
            SDKPropertyEvent            += new EDSDK.EdsPropertyEventHandler(Camera_SDKPropertyEvent);
            SDKObjectEvent              += new EDSDK.EdsObjectEventHandler(Camera_SDKObjectEvent);

            logFile = _logFile;

            PhotoInProgress = false;
            photoTimer = new Stopwatch();

            //get the camera list of attached cameras
            CamList = GetCameraList();

            if (CamList.Count == 0)
            {
                logFile.WriteLine("There are no attached cameras");
                MessageBox.Show("There are no attached cameras");
                return;
            }
            else if (CamList.Count > 1)
            {
                MessageBox.Show("Found more than one attached Canon camera");
                logFile.WriteLine("There is more than one attached camera");
                return;
            }

            //open the session with the first camera (only a single camera is allowed)
            OpenSession(CamList[0]);

            //label the camera type
            String cameraDescription = MainCamera.Info.szDeviceDescription;
            //label camera serial number
            String cameraSN = GetSettingString((uint)EDSDK.PropID_BodyIDEx);
            //label firmware
            String cameraFirmware = GetSettingString((uint)EDSDK.PropID_FirmwareVersion);

            logFile.WriteLine("Camera found");
            logFile.WriteLine("Camera description: " + cameraDescription);
            logFile.WriteLine("cameraSN:           " + cameraSN);
            logFile.WriteLine("cameraFirmware:     " + cameraFirmware);

            //CameraHandler.SetSetting(EDSDK.PropID_SaveTo, (uint)EDSDK.EdsSaveTo.Camera);
            //CameraHandler.SetSetting(EDSDK.PropID_SaveTo, (uint)EDSDK.EdsSaveTo.Host);
            SetSetting(EDSDK.PropID_SaveTo, (uint)EDSDK.EdsSaveTo.Both);
            SetCapacity();  //used to tell camera there is enough room on the PC HD (see codeproject tutorial)

            //get the capacity and loading of the camera card storage drive
            //also write out the names of the images to output
            CameraStorage cameraStorage = StorageAssessment();

            double freeSpace = (double)cameraStorage.FreeSpaceInBytes * 100.0 / (double)cameraStorage.MaxCapacity;
            logFile.WriteLine("Storage media:      " + cameraStorage.cardType);
            logFile.WriteLine("Capacity (GB):      " + (cameraStorage.MaxCapacity / 1024.0).ToString("F2"));
            logFile.WriteLine("Free Space (%):     " + freeSpace.ToString("F1"));
            logFile.WriteLine("number Photos:      " + cameraStorage.numImages.ToString());
            logFile.WriteLine("Avg Photo Size:     " + (cameraStorage.avgImageSize / 1024.0).ToString("F2"));
            logFile.WriteLine();

            if (freeSpace < 50)
            {
                MessageBox.Show("Camera memory card storage  " + freeSpace.ToString("F1") + "%");
            }

            if (!Directory.Exists(@"C://_Waldo_FCS/")) Directory.CreateDirectory(@"C://_Waldo_FCS/");
            if (!Directory.Exists(@"C://_Waldo_FCS/TestImages/")) Directory.CreateDirectory(@"C://_Waldo_FCS/TestImages/");

            //default value -- update this
            ImageSaveDirectory = @"C://_Waldo_FCS/TestImages/";

            /////////////////////////////////////////////////////
            // camera settings for WaldoAir Flight Operations
            /////////////////////////////////////////////////////

            //set the aperture ---
            SetSetting(EDSDK.PropID_Av, CameraValues.AV(settings.Camera_fStop));
            //set the shutter speed
            SetSetting(EDSDK.PropID_Tv, CameraValues.TV(settings.Camera_shutter));
            //set the ISO
            SetSetting(EDSDK.PropID_ISOSpeed, CameraValues.ISO(settings.Camera_ISO));
            //set the white balance to Daylight
            SetSetting(EDSDK.PropID_WhiteBalance, EDSDK.WhiteBalance_Daylight);
        }