コード例 #1
0
        public IEnumerable <Camera> GetCameras()
        {
            UInt32 returnValue;

            IntPtr cameraListPointer;

            returnValue = EDSDK.EdsGetCameraList(out cameraListPointer);
            ReturnValueManager.HandleFunctionReturnValue(returnValue);

            try
            {
                Int32 cameraListCount;
                returnValue = EDSDK.EdsGetChildCount(cameraListPointer, out cameraListCount);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);

                for (var i = 0; i < cameraListCount; ++i)
                {
                    IntPtr cameraPointer;
                    returnValue = EDSDK.EdsGetChildAtIndex(cameraListPointer, i, out cameraPointer);
                    ReturnValueManager.HandleFunctionReturnValue(returnValue);

                    Camera camera = new Camera(cameraPointer);

                    yield return(camera);
                }
            }
            finally
            {
                // Release Camera List Pointer
                if (cameraListPointer != IntPtr.Zero)
                {
                    EDSDK.EdsRelease(cameraListPointer);
                }
            }
        }
コード例 #2
0
        private IntPtr getVolume()
        {
            uint   err;
            int    count = 0;
            IntPtr volume;

            //GET VOLUME COUNT ON CAMERA
            err = EDSDK.EdsGetChildCount(camObj, out count);
            if (err != EDSDK.EDS_ERR_OK || count == 0)
            {
                if (errorEvent != null)
                {
                    errorEvent("Volume Not Found!");
                }

                return(IntPtr.Zero);
            }

            //GET INITIAL VOLUME
            err = EDSDK.EdsGetChildAtIndex(camObj, 0, out volume);
            if (err != EDSDK.EDS_ERR_OK)
            {
                if (errorEvent != null)
                {
                    errorEvent("Directory Not Found!");
                }

                return(IntPtr.Zero);
            }

            return(volume);
        }
コード例 #3
0
        public byte[] DownloadLastPhoto()
        {
            int    count;
            uint   err;
            IntPtr?dirInfo = getDCIMFolder();
            IntPtr folderHandle;
            IntPtr imageHandle;

            EDSDK.EdsDirectoryItemInfo imageInfo;
            IntPtr memStream;
            IntPtr streamStart;

            //MAKE SURE WE HAVE A DCIM FOLDER
            if (dirInfo == null)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed To Find DCIM Folder");
                }

                return(null);
            }

            err = EDSDK.EdsGetChildCount(dirInfo.Value, out count);
            if (err != EDSDK.EDS_ERR_OK)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed To Get Child Folder!");
                }

                return(null);
            }


            err = EDSDK.EdsGetChildAtIndex(dirInfo.Value, count - 1, out folderHandle);
            err = EDSDK.EdsGetChildCount(folderHandle, out count);
            err = EDSDK.EdsGetChildAtIndex(folderHandle, count - 1, out imageHandle);
            err = EDSDK.EdsGetDirectoryItemInfo(imageHandle, out imageInfo);
            err = EDSDK.EdsCreateMemoryStream(0, out memStream);

            EDSDK.EdsDownload(imageHandle, imageInfo.Size, memStream);
            EDSDK.EdsDownloadComplete(imageHandle);

            byte[] imageData = new byte[imageInfo.Size];
            EDSDK.EdsGetPointer(memStream, out streamStart);
            Marshal.Copy(streamStart, imageData, 0, (int)imageInfo.Size);

            EDSDK.EdsRelease(streamStart);
            EDSDK.EdsRelease(memStream);
            EDSDK.EdsRelease(folderHandle);
            EDSDK.EdsRelease(imageHandle);
            EDSDK.EdsRelease(dirInfo.Value);

            DownloadingPhoto = false;

            return(imageData);
        }
コード例 #4
0
 private static IntPtr[] GetCameraPointers(IntPtr aCameraListPointer, int cameraCount)
 {
     IntPtr[] pointers = new IntPtr[cameraCount];
     for (int i = 0; i < cameraCount; ++i)
     {
         IntPtr cameraPointer;
         SDKHelper.CheckError(EDSDK.EdsGetChildAtIndex(aCameraListPointer, i, out cameraPointer));
         pointers[i] = cameraPointer;
     }
     return(pointers);
 }
コード例 #5
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";
            }
        }
コード例 #6
0
        private void scanForMemoryCards(string path)
        {
            IntPtr childPtr;
            int    childcount;

            publicError(EDSDK.EdsGetChildCount(this.Ptr, out childcount));
            for (int i = 0; i < childcount; i++)
            {
                publicError(EDSDK.EdsGetChildAtIndex(this.Ptr, i, out childPtr));
                this.MemoryCards.Add(new MemoryCard(childPtr));
                scanMemoryCard(childPtr, path);
            }
        }
コード例 #7
0
        private void scanToCameras()
        {
            IntPtr tmpptr;
            IntPtr tmpCameraPtr;
            int    tmpCount = 0;

            EDSDK.EdsGetCameraList(out tmpptr);
            EDSDK.EdsGetChildCount(tmpptr, out tmpCount);
            for (int i = 0; i < tmpCount; i++)
            {
                EDSDK.EdsGetChildAtIndex(tmpptr, i, out tmpCameraPtr);
                this.CameraList.Add(new Camera(tmpCameraPtr, ""));
                EDSDK.EdsSetPropertyEventHandler(tmpCameraPtr, EDSDK.PropertyEvent_All, cameraPropertyEventHandler, tmpCameraPtr);
                EDSDK.EdsSetCameraStateEventHandler(tmpCameraPtr, EDSDK.StateEvent_All, this.cameraStateEventHandler, tmpCameraPtr);
            }
        }
コード例 #8
0
        public static IntPtr[] OpenCameras(IntPtr CameraListRef, int Count)
        {
            int  i;
            uint success;

            IntPtr[] Camera  = new IntPtr[20];
            IntPtr   _camera = new IntPtr();

            for (i = 0; i < Count; i++)
            {
                EDSDK.EdsGetChildAtIndex(CameraListRef, i, out _camera);
                Camera[i] = _camera;
                success   = EDSDK.EdsOpenSession(_camera);
                if (success != EDSDK.EDS_ERR_OK)
                {
                    Console.WriteLine("OpenCamera failed\t" + "failed camera is:" + i.ToString() + "\t" + success.ToString());
                }
                else
                {
                    Console.WriteLine("OpenCamera successs\t" + i.ToString());
                }
            }
            return(Camera);
        }
コード例 #9
0
        private void scanMemoryCard(IntPtr ptr, string path)
        {
            Console.WriteLine("Scan for folder ....");
            IntPtr childPtr;
            int    childcount;
            Folder tmpFolder;

            EDSDK.EdsGetChildCount(ptr, out childcount);
            Console.WriteLine("Found : " + childcount + " folders.");
            for (int i = 0; i < childcount; i++)
            {
                EDSDK.EdsGetChildAtIndex(ptr, i, out childPtr);
                tmpFolder = new Folder(childPtr);
                Console.WriteLine(tmpFolder.ToString());
                if (tmpFolder.FolderInfo.isFolder == 1)
                {
                    scanMemoryCard(childPtr, path);
                }
                else
                {
                    savePictureToHost(childPtr, path);
                }
            }
        }
コード例 #10
0
        public static unsafe void DownloadImage(IntPtr[] camera, int Count)
        {
            IntPtr  sdRef    = IntPtr.Zero;
            IntPtr  dicmRef  = IntPtr.Zero;
            IntPtr  canonRef = IntPtr.Zero;
            int     nFiles;
            IniFile iniFile = new IniFile(configForm.iniFilePaths);

            for (int i = 0; i < Count; i++)
            {
                EDSDK.EdsGetChildAtIndex(camera[i], 0, out sdRef);
                EDSDK.EdsGetChildAtIndex(sdRef, 0, out dicmRef);
                EDSDK.EdsGetChildAtIndex(dicmRef, 0, out canonRef);
                EDSDK.EdsGetChildCount(canonRef, out nFiles);

                string dest = PicDest;

                //for (int i = 0; i < 5; i++)
                {
                    IntPtr fileRef = IntPtr.Zero;
                    EDSDK.EdsDirectoryItemInfo fileInfo;
                    #region Get Directory and download
                    try
                    {
                        EDSDK.EdsGetChildAtIndex(canonRef, (nFiles - 1), out fileRef);
                        EDSDK.EdsGetDirectoryItemInfo(fileRef, out fileInfo);

                        IntPtr fStream = IntPtr.Zero;  //it's a cannon sdk file stream, not a managed stream
                        uint   fSize   = fileInfo.Size;
                        #region DownLoad
                        try
                        {
                            EDSDK.EdsCreateMemoryStream(fSize, out fStream);
                            EDSDK.EdsDownload(fileRef, fSize, fStream);
                            EDSDK.EdsDownloadComplete(fileRef);
                            byte[] buffer = new byte[fSize];
                            IntPtr imgLocation;
                            //uint _imageLen;

                            if (EDSDK.EdsGetPointer(fStream, out imgLocation) == EDSDK.EDS_ERR_OK)
                            {
                                #region save
                                Marshal.Copy(imgLocation, buffer, 0, (int)fSize - 1);
                                EDSDK.EdsDeviceInfo deviceInfo;
                                EDSDK.EdsGetDeviceInfo(camera[i], out deviceInfo);
                                string deviceName;
                                deviceName = iniFile.IniReadValue("CameraID", deviceInfo.szPortName);
                                File.WriteAllBytes(dest + deviceName + "__" + fileInfo.szFileName, buffer);
                                //EDSDK.EdsGetLength(fStream, out _imageLen);
                                //UnmanagedMemoryStream ums = new UnmanagedMemoryStream((byte*)imgLocation.ToPointer(), _imageLen, _imageLen, FileAccess.Read);
                                //Bitmap _bmp = new Bitmap(ums, true);
                                //pictureBox1.Image = _bmp;
                                //_bmp.Save("new1", System.Drawing.Imaging.ImageFormat.Jpeg);
                                #endregion
                            }
                        }
                        finally
                        {
                            EDSDK.EdsRelease(fStream);
                            Console.WriteLine("DownloadSuccess\t" + i.ToString());
                        }

                        #endregion
                    }
                    finally
                    {
                        EDSDK.EdsRelease(fileRef);
                    }
                    #endregion
                }
            }
        }
コード例 #11
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);
        }
コード例 #12
0
        private IntPtr?getDCIMFolder()
        {
            uint   err;
            int    count  = 0;
            IntPtr volume = getVolume();
            IntPtr dirHandle;

            EDSDK.EdsDirectoryItemInfo dirInfo;

            //GET THE ROOT VOLUME FOR THE CAMERA
            if (volume == IntPtr.Zero)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed To Get Root Volume!");
                }

                return(null);
            }

            //GET THE COUNT OF FOLDERS ON THE VOLUME
            err = EDSDK.EdsGetChildCount(volume, out count);
            if (err != EDSDK.EDS_ERR_OK)
            {
                if (errorEvent != null)
                {
                    errorEvent("Failed To Get Folders on Volume!");
                }

                return(null);
            }

            for (int i = 0; i < count && err == EDSDK.EDS_ERR_OK; i++)
            {
                err = EDSDK.EdsGetChildAtIndex(volume, i, out dirHandle);
                if (err != EDSDK.EDS_ERR_OK)
                {
                    if (errorEvent != null)
                    {
                        errorEvent("Failed to get Folder at index " + i.ToString());
                    }

                    return(null);
                }

                err = EDSDK.EdsGetDirectoryItemInfo(dirHandle, out dirInfo);
                if (err != EDSDK.EDS_ERR_OK)
                {
                    if (errorEvent != null)
                    {
                        errorEvent("Failed To Get Folder At Index " + i.ToString());
                    }

                    return(null);
                }

                if (dirInfo.szFileName.ToUpper().Contains("DCIM") && dirInfo.isFolder == 1)
                {
                    EDSDK.EdsRelease(volume);
                    return(dirHandle);
                }
                else
                {
                    EDSDK.EdsRelease(dirHandle);
                }
            }

            return(null);
        }
コード例 #13
0
        public override void GetEquipment()
        {
            Devices.Clear();

            Devices.Add(new Model.DummyDevice(Locale.Loc.Instance["LblNoCamera"]));

            /* ASI */
            try {
                Logger.Trace("Adding ASI Cameras");
                for (int i = 0; i < ASICameras.Count; i++)
                {
                    var cam = ASICameras.GetCamera(i, profileService);
                    if (!string.IsNullOrEmpty(cam.Name))
                    {
                        Logger.Trace(string.Format("Adding {0}", cam.Name));
                        Devices.Add(cam);
                    }
                }
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            /* Altair */
            try {
                Logger.Trace("Adding Altair Cameras");
                foreach (var instance in Altair.AltairCam.EnumV2())
                {
                    var cam = new AltairCamera(instance, profileService);
                    Devices.Add(cam);
                }
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            /* Atik */
            try {
                Logger.Trace("Adding Atik Cameras");
                var atikDevices = AtikCameraDll.GetDevicesCount();
                Logger.Trace($"Cameras found: {atikDevices}");
                if (atikDevices > 0)
                {
                    for (int i = 0; i < atikDevices; i++)
                    {
                        var cam = new AtikCamera(i, profileService);
                        Devices.Add(cam);
                    }
                }
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            /* FLI */
            try {
                Logger.Trace("Adding FLI Cameras");
                List <string> cameras = FLICameras.GetCameras();

                if (cameras.Count > 0)
                {
                    foreach (var entry in cameras)
                    {
                        var camera = new FLICamera(entry, profileService);

                        if (!string.IsNullOrEmpty(camera.Name))
                        {
                            Logger.Debug($"Adding FLI camera {camera.Id} (as {camera.Name})");
                            Devices.Add(camera);
                        }
                    }
                }
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            /* QHYCCD */
            try {
                Logger.Trace("Adding QHYCCD Cameras");
                uint numCameras = QHYCameras.Count;

                if (numCameras > 0)
                {
                    for (uint i = 0; i < numCameras; i++)
                    {
                        var cam = QHYCameras.GetCamera(i, profileService);
                        if (!string.IsNullOrEmpty(cam.Name))
                        {
                            Logger.Debug($"Adding QHY camera {i}: {cam.Id} (as {cam.Name})");
                            Devices.Add(cam);
                        }
                    }
                }
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            /* ToupTek */
            try {
                Logger.Debug("Adding ToupTek Cameras");
                foreach (var instance in ToupTek.ToupCam.EnumV2())
                {
                    var cam = new ToupTekCamera(instance, profileService);
                    Devices.Add(cam);
                }
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            /* Omegon */
            try {
                Logger.Debug("Adding Omegon Cameras");
                foreach (var instance in Omegon.Omegonprocam.EnumV2())
                {
                    var cam = new OmegonCamera(instance, profileService);
                    Devices.Add(cam);
                }
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            /* ASCOM */
            try {
                foreach (ICamera cam in ASCOMInteraction.GetCameras(profileService))
                {
                    Devices.Add(cam);
                }
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            /* CANON */
            try {
                IntPtr cameraList;
                try {
                    EDSDKLocal.Initialize();
                } catch (Exception ex) {
                    Logger.Error(ex);
                    Utility.Notification.Notification.ShowError(ex.Message);
                }

                uint err = EDSDK.EdsGetCameraList(out cameraList);
                if (err == EDSDK.EDS_ERR_OK)
                {
                    int count;
                    err = EDSDK.EdsGetChildCount(cameraList, out count);

                    for (int i = 0; i < count; i++)
                    {
                        IntPtr cam;
                        err = EDSDK.EdsGetChildAtIndex(cameraList, i, out cam);

                        EDSDK.EdsDeviceInfo info;
                        err = EDSDK.EdsGetDeviceInfo(cam, out info);

                        Logger.Trace(string.Format("Adding {0}", info.szDeviceDescription));
                        Devices.Add(new EDCamera(cam, info, profileService));
                    }
                }
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            /* NIKON */
            try {
                Devices.Add(new NikonCamera(profileService, telescopeMediator));
            } catch (Exception ex) {
                Logger.Error(ex);
            }

            Devices.Add(new Model.MyCamera.FileCamera(profileService, telescopeMediator));
            Devices.Add(new Model.MyCamera.Simulator.SimulatorCamera(profileService, telescopeMediator));

            DetermineSelectedDevice(profileService.ActiveProfile.CameraSettings.Id);
        }