Esempio n. 1
0
        private uint DownloadImage(uint inEvent, IntPtr inRef, IntPtr inContext)
        {
            _cameraNotifications.Log(string.Format("Camera event: {0}", SDKHelper.DecodeEvent(inEvent)));

            lock (_synchronizationObject)
            {
                try
                {
                    if (inEvent == EDSDK.ObjectEvent_DirItemRequestTransfer)
                    {
                        if (_imageHandler != null)
                        {
                            _imageHandler.Handle(GetImageFile(inRef, _folder));
                        }
                        _cameraNotifications.CameraDone();
                    }
                    if (inEvent == EDSDK.ObjectEvent_DirItemCreated)
                    {
                        _cameraNotifications.CameraDone();
                    }
                }
                finally
                {
                    if (inRef != IntPtr.Zero)
                    {
                        SDKHelper.CheckError(EDSDK.EdsRelease(inRef));
                    }
                }
                return(0);
            }
        }
Esempio n. 2
0
        public void DownloadLiveViewImage(Action <MemoryStream, uint> onImageRecieved)
        {
            IntPtr stream  = IntPtr.Zero;
            IntPtr image   = IntPtr.Zero;
            IntPtr pointer = IntPtr.Zero;
            uint   size    = 0;

            try
            {
                SDKHelper.CheckError(EDSDK.EdsCreateMemoryStream(BUFFER_SIZE, out stream));
                SDKHelper.CheckError(EDSDK.EdsCreateEvfImageRef(stream, out image));
                SDKHelper.CheckError(EDSDK.EdsDownloadEvfImage(_pointer, image));

                SDKHelper.CheckError(EDSDK.EdsGetPointer(stream, out pointer));
                SDKHelper.CheckError(EDSDK.EdsGetLength(stream, out size));

                onImageRecieved(CopyToMemoryStream(pointer, size), size);

                SDKHelper.CheckError(EDSDK.EdsRelease(image));
                SDKHelper.CheckError(EDSDK.EdsRelease(stream));
            }
            catch (SDKComeBackLaterException)
            {
            }
        }
Esempio n. 3
0
        private void LoadCamerasList(IntPtr aCameraListPointer)
        {
            int cameraCount;

            SDKHelper.CheckError(EDSDK.EdsGetChildCount(aCameraListPointer, out cameraCount));

            IntPtr[] pointers = GetCameraPointers(aCameraListPointer, cameraCount);

            Dictionary <IntPtr, ICameraProcessor> temporary = new Dictionary <IntPtr, ICameraProcessor>();

            for (int i = 0; i < pointers.Length; ++i)
            {
                IntPtr pointer = pointers[i];
                if (_processors.ContainsKey(pointer))
                {
                    temporary.Add(pointer, _processors[pointer]);
                    _processors.Remove(pointer);
                }
                else
                {
                    temporary.Add(pointer, new CameraProcessor(pointer, _cameraNotifications));
                }
            }

            Array.ForEach(_processors.Values.ToArray(), cameraProcessor => cameraProcessor.Dispose());
            _processors = temporary;
        }
Esempio n. 4
0
        private void Initialize()
        {
            SDKHelper.CheckError(EDSDK.EdsInitializeSDK());
            SDKHelper.CheckError(EDSDK.EdsGetCameraList(out _cameraListPointer));

            LoadCamerasList(_cameraListPointer);
        }
Esempio n. 5
0
        private static IntPtr GetFileStream(string filename)
        {
            IntPtr stream;

            SDKHelper.CheckError(EDSDK.EdsCreateFileStream(filename, EDSDK.EdsFileCreateDisposition.CreateAlways,
                                                           EDSDK.EdsAccess.ReadWrite, out stream));
            return(stream);
        }
Esempio n. 6
0
        private string GetStringProperty(uint aPropertyId)
        {
            CameraAlreadyDisposedException.ThrowIf(_disposed);
            string result;

            SDKHelper.CheckError(EDSDK.EdsGetPropertyData(_pointer, aPropertyId, 0, out result));
            return(result);
        }
Esempio n. 7
0
 private void SendShootCommand(IImageHandler imageHandler, uint command, int value)
 {
     CameraAlreadyDisposedException.ThrowIf(_disposed);
     lock (_synchronizationObject)
     {
         SDKHelper.CheckError(EDSDK.EdsSendCommand(_pointer, command, value));
         _imageHandler = imageHandler;
     }
 }
Esempio n. 8
0
 public void PressShutterButton(IImageHandler imageHandler)
 {
     CameraAlreadyDisposedException.ThrowIf(_disposed);
     lock (_synchronizationObject)
     {
         SDKHelper.CheckError(EDSDK.EdsSendCommand(_pointer, EDSDK.CameraCommand_PressShutterButton, (int)EDSDK.EdsShutterButton.CameraCommand_ShutterButton_Completely_NonAF));
         SDKHelper.CheckError(EDSDK.EdsSendCommand(_pointer, EDSDK.CameraCommand_PressShutterButton, (int)EDSDK.EdsShutterButton.CameraCommand_ShutterButton_OFF));
         _imageHandler = imageHandler;
     }
 }
Esempio n. 9
0
 public void Dispose()
 {
     _folder.Dispose();
     if (_shouldRelease)
     {
         SDKHelper.CheckError(EDSDK.EdsCloseSession(_pointer));
         SDKHelper.CheckError(EDSDK.EdsRelease(_pointer));
     }
     _disposed = true;
 }
Esempio n. 10
0
        public void Shoot(IImageHandler imageHandler)
        {
            EDSDK.EdsCapacity capacity = new EDSDK.EdsCapacity();
            capacity.BytesPerSector       = 1000;
            capacity.NumberOfFreeClusters = (int)UInt16.MaxValue;
            capacity.Reset = 1;

            SDKHelper.CheckError(EDSDK.EdsSetCapacity(_pointer, capacity));

            SendShootCommand(imageHandler, EDSDK.CameraCommand_TakePicture, (int)0);
        }
Esempio n. 11
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);
 }
Esempio n. 12
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));
        }
Esempio n. 13
0
 public uint[] GetAvailableValues(uint aPropertyType)
 {
     CameraAlreadyDisposedException.ThrowIf(_disposed);
     EDSDK.EdsPropertyDesc propertyDesc;
     try
     {
         SDKHelper.CheckError(EDSDK.EdsGetPropertyDesc(_pointer, aPropertyType, out propertyDesc));
         int[] result = new int[propertyDesc.NumElements];
         Array.Copy(propertyDesc.PropDesc, result, result.Length);
         return(Array.ConvertAll(result, new Converter <int, uint>(int32 => Convert.ToUInt32(int32))));
     }
     catch (SDKInvalidParameterExeption)
     {
         return(new uint[0]);
     }
 }
Esempio n. 14
0
        private ImageFile GetImageFile(IntPtr inRef, Folder aFolder)
        {
            EDSDK.EdsDirectoryItemInfo directoryItemInfo = GetDirectoryItemInfo(inRef);
            string filename = aFolder.ComposeFilename(directoryItemInfo.szFileName);
            IntPtr stream   = GetFileStream(filename);

            try
            {
                SDKHelper.CheckError(EDSDK.EdsDownload(inRef, directoryItemInfo.Size, stream));
                SDKHelper.CheckError(EDSDK.EdsDownloadComplete(inRef));
            }
            catch
            {
                SDKHelper.CheckError(EDSDK.EdsDownloadCancel(inRef));
                throw;
            }
            finally
            {
                SDKHelper.CheckError(EDSDK.EdsRelease(stream));
            }
            return(new ImageFile(File.ReadAllBytes(filename), directoryItemInfo.szFileName));
        }
Esempio n. 15
0
 private void UnInitialize()
 {
     Array.ForEach(_processors.Values.ToArray(), cameraProcessor => cameraProcessor.Dispose());
     SDKHelper.CheckError(EDSDK.EdsRelease(_cameraListPointer));
     SDKHelper.CheckError(EDSDK.EdsTerminateSDK());
 }
Esempio n. 16
0
 public void MoveFocus(uint value)
 {
     SDKHelper.CheckError(EDSDK.EdsSendCommand(_pointer, EDSDK.CameraCommand_DriveLensEvf, (int)value));
 }
Esempio n. 17
0
 public void KeepALive()
 {
     CameraAlreadyDisposedException.ThrowIf(_disposed);
     SDKHelper.CheckError(EDSDK.EdsSendCommand(_pointer, EDSDK.CameraCommand_ExtendShutDownTimer, 0));
 }
Esempio n. 18
0
 public void SetProperty <T>(uint propertyId, T value)
 {
     CameraAlreadyDisposedException.ThrowIf(_disposed);
     SDKHelper.CheckError(EDSDK.EdsSetPropertyData(_pointer, propertyId, 0, sizeof(int), value));
 }
Esempio n. 19
0
 public void LockUI()
 {
     CameraAlreadyDisposedException.ThrowIf(_disposed);
     SDKHelper.CheckError(EDSDK.EdsSendStatusCommand(_pointer, EDSDK.CameraState_UILock, 0));
 }
Esempio n. 20
0
 private static EDSDK.EdsDirectoryItemInfo GetDirectoryItemInfo(IntPtr inRef)
 {
     EDSDK.EdsDirectoryItemInfo directoryItemInfo;
     SDKHelper.CheckError(EDSDK.EdsGetDirectoryItemInfo(inRef, out directoryItemInfo));
     return(directoryItemInfo);
 }