Exemplo n.º 1
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");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// assess the camera storage situation for the MainCamera
        /// </summary>
        public CameraStats StorageAssessment()
        {
            //reference to the camera storage device (SD card or CF card)
            CameraStats cameraStorage = new CameraStats();

            //get the storage card volume reference for this camera
            int volumeCount = 0;
            //get the number of storage drives -- the Canon 5D Mark III has two storage devices (CF and SD)
            Error = EDSDK.EdsGetChildCount(MainCamera.Ref, out volumeCount);

            //get the capacity for each of the storage drives
            EDSDK.EdsVolumeInfo vinfoMax = new EDSDK.EdsVolumeInfo(); //contains capacity information
            ulong maxCapacity = 0;
            int driveWithMax = 0;
            IntPtr cameraVolRef;
            for (int i = 0; i < volumeCount; i++)
            {
                //get the volume reference for the ith storage drive
                Error = EDSDK.EdsGetChildAtIndex(MainCamera.Ref, i, out cameraVolRef);

                EDSDK.EdsVolumeInfo vinfo = new EDSDK.EdsVolumeInfo(); //contains capacity information
                Error = EDSDK.EdsGetVolumeInfo(cameraVolRef, out vinfo);
                Debug.WriteLine(String.Format("DriveType: {0}, Max Capacity: {1}, Free Space: {2}",
                    vinfo.szVolumeLabel, vinfo.MaxCapacity, vinfo.FreeSpaceInBytes));
                if (vinfo.MaxCapacity > maxCapacity)
                {
                    maxCapacity = vinfo.MaxCapacity;

                    vinfoMax = vinfo;
                    driveWithMax = i;
                    MainCamera.Vol = cameraVolRef;

                    //report stats on the drive with max storage
                    //may want both drives reported -- SD card may be higher capacity by CF card may be faster
                    cameraStorage.cardType = vinfoMax.szVolumeLabel;
                    cameraStorage.MaxCapacity = vinfoMax.MaxCapacity / 1024; ;
                    cameraStorage.FreeSpaceInBytes = vinfoMax.FreeSpaceInBytes / 1024;
                }
            }

            //get the directory structure for the drive -- locate the "DCIM", "MISC" and "100Canon" folders
            int directoryCount = 0;
            IntPtr dirItem;
            EDSDK.EdsDirectoryItemInfo dirItemInfo; ;
            //get number of directories -- should be 2:  "DCIM" and "Misc"
            //locate the DCIM folder where the imagery is kept
            Error = EDSDK.EdsGetChildCount(MainCamera.Vol, out directoryCount);
            for (int i = 0; i < directoryCount; i++)
            {
                Error = EDSDK.EdsGetChildAtIndex(MainCamera.Vol, i, out dirItem);
                Error = EDSDK.EdsGetDirectoryItemInfo(dirItem, out dirItemInfo);
                if (dirItemInfo.szFileName == "DCIM")
                {
                    MainCamera.DCIMref = dirItem;
                    break;
                }
            }

            //get the number of images currently stored on the drive
            int CanonFolderCount = 0;
            // the DCIM folder has a single directory beneath it
            Error = EDSDK.EdsGetChildCount(MainCamera.DCIMref, out CanonFolderCount);
            //there should be a single folder called "100Canon" beneath the DCIM folder
            Error = EDSDK.EdsGetChildAtIndex(MainCamera.DCIMref, 0, out MainCamera.imageFolder);
            //CanonImageFolder is now the reference to the folder containing the images

            int imageCount = 0;
            Error = EDSDK.EdsGetChildCount(MainCamera.imageFolder, out imageCount);
            Debug.WriteLine(String.Format("number of images in the DCIM folder = {0} ", imageCount));

            cameraStorage.numImages = (uint)imageCount;

            IntPtr imageFile;
            EDSDK.EdsDirectoryItemInfo imageFileInfo; ;
            //cycle through all the images getting their name on the storage drive
            cameraStorage.avgImageSize = 0;
            for (int i = 0; i < imageCount; i++)
            {
                Error = EDSDK.EdsGetChildAtIndex(MainCamera.imageFolder, i, out imageFile);
                Error = EDSDK.EdsGetDirectoryItemInfo(imageFile, out imageFileInfo);
                Debug.WriteLine(String.Format("imageName " + imageFileInfo.szFileName + " size {0} ", imageFileInfo.Size));
                cameraStorage.avgImageSize += imageFileInfo.Size;
            }
            if (cameraStorage.numImages > 0)
                cameraStorage.avgImageSize /= (cameraStorage.numImages * 1024);
            else cameraStorage.avgImageSize = 0;

            return cameraStorage;
        }