/// <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); }
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); }
/// <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]); } }
/// <summary> /// </summary> /// <param name="propertyId">The property id.</param> /// <returns>property values</returns> /// <remarks></remarks> protected IEnumerable <UInt32> GetSupportedProperties(PropertyId propertyId) { EDSDK.EdsPropertyDesc propertyDescription; UInt32 returnValue = EDSDK.EdsGetPropertyDesc(this.Handle, (UInt32)propertyId, out propertyDescription); ReturnValueManager.HandleFunctionReturnValue(returnValue); for (int i = 0; i < propertyDescription.PropDesc.Length; i++) { yield return((UInt32)propertyDescription.PropDesc[i]); } }
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); } }
/// <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); } }
/// <summary> /// Tells the camera that there is enough space on the HDD if SaveTo is set to Host /// This method does not use the actual free space! /// </summary> public void SetCapacity() { //create new capacity struct Capacity capacity = new Capacity(); //set big enough values capacity.Reset = 1; capacity.BytesPerSector = 0x1000; capacity.NumberOfFreeClusters = 0x7FFFFFFF; //set the values to camera SendSDKCommand(() => { _returnValueManager.HandleFunctionReturnValue(EdsdkInvokes.SetCapacity(this.Ref, capacity)); //DequeueItem(); }); }
public void ShutterPressed(int state) { UInt32 returnValue = EDSDKInvokes.SendCommand(this.Handle, (uint)CameraCommand.PressShutterButton, state); ReturnValueManager.HandleFunctionReturnValue(returnValue); }
/// <summary> /// Take a single photo /// </summary> public void TakePhoto() { UInt32 returnValue = EDSDKInvokes.SendCommand(this.Handle, (uint)CameraCommand.TakePicture, 0); ReturnValueManager.HandleFunctionReturnValue(returnValue); }
/// <summary> /// Closes the session. /// </summary> /// <remarks></remarks> protected void CloseSession() { UInt32 returnValue = EDSDKInvokes.CloseSession(this.Handle); ReturnValueManager.HandleFunctionReturnValue(returnValue); }
/// <summary> /// Opens the session. /// </summary> /// <remarks></remarks> protected void OpenSession() { UInt32 returnValue = EDSDK.EdsOpenSession(this.Handle); ReturnValueManager.HandleFunctionReturnValue(returnValue); }
/// <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); }