Exemple #1
0
        /// <summary>
        /// Gets the property pointer.
        /// </summary>
        /// <param name="propertyId">The property id.</param>
        /// <param name="bufferSize">Size of the buffer.</param>
        /// <param name="additionalInformation">Additional information of property.
        /// We use this parameter in order to specify an index.</param>
        /// <returns>pointer to the property value buffer</returns>
        /// <remarks></remarks>
        private IntPtr GetProperty(PropertyId propertyId, int bufferSize, int additionalInformation = 0)
        {
            IntPtr allocatedBufferPointer = Marshal.AllocHGlobal(bufferSize);

            try
            {
                UInt32 returnValue = EDSDKInvokes.GetPropertyData(this.Handle, (UInt32)propertyId, additionalInformation, bufferSize, allocatedBufferPointer);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);
            }
            // If Caught any exception during the native call
            catch
            {
                // If buffer was allocated
                if (allocatedBufferPointer != IntPtr.Zero)
                {
                    // Release him
                    Marshal.FreeHGlobal(allocatedBufferPointer);
                    allocatedBufferPointer = IntPtr.Zero;
                }

                // Eventually, throw the caught exception
                throw;
            }

            // Return the allocated buffer
            return(allocatedBufferPointer);
        }
        public IEnumerable <Camera> GetCameras()
        {
            UInt32 returnValue;

            IntPtr cameraListPointer;

            returnValue = EDSDKInvokes.GetCameraList(out cameraListPointer);
            ReturnValueManager.HandleFunctionReturnValue(returnValue);

            try
            {
                Int32 cameraListCount;
                returnValue = EDSDKInvokes.GetChildCount(cameraListPointer, out cameraListCount);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);

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

                    Camera camera = new Camera(cameraPointer);

                    yield return(camera);
                }
            }
            finally
            {
                // Release Camera List Pointer
                if (cameraListPointer != IntPtr.Zero)
                {
                    EDSDKInvokes.Release(cameraListPointer);
                }
            }
        }
Exemple #3
0
        public virtual void Dispose()
        {
            if (this.Handle != IntPtr.Zero)
            {
                UInt32 returnValue = EDSDKInvokes.Release(this.Handle);

                this.Handle = IntPtr.Zero;
            }
        }
Exemple #4
0
        private void RegisterEventHandlers()
        {
            //  Register OBJECT events
            m_edsObjectEventHandler = new EDSDKInvokes.EdsObjectEventHandler(objectEventHandler);
            uint result = EDSDKInvokes.SetObjectEventHandler(
                this.Handle,
                (uint)ObjectEvent.All,
                m_edsObjectEventHandler,
                IntPtr.Zero);

            ReturnValueManager.HandleFunctionReturnValue(result);
        }
Exemple #5
0
        /// <summary>
        /// </summary>
        /// <param name="propertyId">The property id.</param>
        /// <returns>property values</returns>
        /// <remarks></remarks>
        protected IEnumerable <UInt32> GetSupportedProperties(PropertyId propertyId)
        {
            PropertyDescription propertyDescription;

            UInt32 returnValue = EDSDKInvokes.GetPropertyDescription(this.Handle, (UInt32)propertyId, out propertyDescription);

            ReturnValueManager.HandleFunctionReturnValue(returnValue);

            for (int i = 0; i < propertyDescription.Elements.Length; i++)
            {
                yield return((UInt32)propertyDescription.Elements[i]);
            }
        }
Exemple #6
0
        public Stream GetLiveViewImage()
        {
            IntPtr streamPointer = IntPtr.Zero;
            IntPtr imagePointer  = IntPtr.Zero;

            UInt32 returnValue = EDSDKInvokes.CreateMemoryStream(0, out streamPointer);

            ReturnValueManager.HandleFunctionReturnValue(returnValue);

            try
            {
                returnValue = EDSDKInvokes.CreateEvfImageRef(streamPointer, out imagePointer);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);
                try
                {
                    returnValue = EDSDKInvokes.DownloadEvfImage(this.Handle, imagePointer);
                    ReturnValueManager.HandleFunctionReturnValue(returnValue);

                    IntPtr imageBlob;
                    returnValue = EDSDKInvokes.GetPointer(streamPointer, out imageBlob);
                    ReturnValueManager.HandleFunctionReturnValue(returnValue);

                    try
                    {
                        uint imageBlobLength;
                        returnValue = EDSDKInvokes.GetLength(streamPointer, out imageBlobLength);
                        ReturnValueManager.HandleFunctionReturnValue(returnValue);

                        byte[] buffer = new byte[imageBlobLength];
                        Marshal.Copy(imageBlob, buffer, 0, (int)imageBlobLength);

                        Stream stream = new MemoryStream(buffer);
                        return(stream);
                    }
                    finally
                    {
                        EDSDKInvokes.Release(imageBlob);
                    }
                }
                finally
                {
                    EDSDKInvokes.Release(imagePointer);
                }
            }
            finally
            {
                EDSDKInvokes.Release(streamPointer);
            }
        }
Exemple #7
0
        /// <summary>
        /// Download image to disk.
        /// </summary>
        /// <param name="dirRef">A reference to objects created by the event</param>
        private void DownloadImage(IntPtr dirRef)
        {
            IntPtr stream = IntPtr.Zero;
            IntPtr data   = IntPtr.Zero;
            DirectoryItemInformation dirItemInfo;

            try
            {
                UInt32 returnValue = EDSDKInvokes.GetDirectoryItemInformation(dirRef, out dirItemInfo);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);

                string fullpath = String.Empty;
                if (!String.IsNullOrEmpty(ImageSaveDirectory))
                {
                    fullpath = System.IO.Path.Combine(ImageSaveDirectory, dirItemInfo.FileName);
                }
                else
                {
                    fullpath = System.IO.Path.Combine(Environment.CurrentDirectory, dirItemInfo.FileName);
                }
                returnValue = EDSDKInvokes.CreateFileStream(fullpath, FileCreateDisposition.CreateAlways, Access.ReadWrite, out stream);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);

                returnValue = EDSDKInvokes.Download(dirRef, dirItemInfo.Size, stream);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);

                if (returnValue == (uint )ReturnValue.Ok)
                {
                    returnValue = EDSDKInvokes.DownloadComplete(dirRef);
                }
                else
                {
                    returnValue = EDSDKInvokes.DownloadCancel(dirRef);
                }

                returnValue = EDSDKInvokes.GetPointer(stream, out data);
                ReturnValueManager.HandleFunctionReturnValue(returnValue);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.Message);
            }
            finally
            {
                EDSDKInvokes.Release(stream);
                EDSDKInvokes.Release(data);
            }
        }
Exemple #8
0
        public void ShutterPressed(int state)
        {
            UInt32 returnValue = EDSDKInvokes.SendCommand(this.Handle, (uint)CameraCommand.PressShutterButton, state);

            ReturnValueManager.HandleFunctionReturnValue(returnValue);
        }
Exemple #9
0
        /// <summary>
        /// Take a single photo
        /// </summary>
        public void TakePhoto()
        {
            UInt32 returnValue = EDSDKInvokes.SendCommand(this.Handle, (uint)CameraCommand.TakePicture, 0);

            ReturnValueManager.HandleFunctionReturnValue(returnValue);
        }
Exemple #10
0
        /// <summary>
        /// Closes the session.
        /// </summary>
        /// <remarks></remarks>
        protected void CloseSession()
        {
            UInt32 returnValue = EDSDKInvokes.CloseSession(this.Handle);

            ReturnValueManager.HandleFunctionReturnValue(returnValue);
        }
        /// <summary>
        /// Terminates the SDK.
        /// </summary>
        /// <remarks></remarks>
        private void terminateSDK()
        {
            UInt32 returnValue = EDSDKInvokes.TerminateSDK();

            ReturnValueManager.HandleFunctionReturnValue(returnValue);
        }
        /// <summary>
        /// Initializes the SDK.
        /// </summary>
        /// <remarks></remarks>
        private void initializeSDK()
        {
            UInt32 returnValue = EDSDKInvokes.InitializeSDK();

            ReturnValueManager.HandleFunctionReturnValue(returnValue);
        }
Exemple #13
0
        /// <summary>
        /// Sets the property value.
        /// </summary>
        /// <param name="propertyId">The property id.</param>
        /// <param name="propertySize">Size of the property.</param>
        /// <param name="propertyValue">The property value.</param>
        /// <param name="additionalInformation">The additional information.</param>
        /// <remarks></remarks>
        private void SetProperty(PropertyId propertyId, int propertySize, object propertyValue, int additionalInformation = 0)
        {
            UInt32 returnValue = EDSDKInvokes.SetPropertyData(this.Handle, (UInt32)propertyId, additionalInformation, propertySize, propertyValue);

            ReturnValueManager.HandleFunctionReturnValue(returnValue);
        }