public override LiveViewData GetLiveViewImage() { LiveViewData viewData = new LiveViewData(); viewData.HaveFocusData = true; const int headerSize = 128; var result = StillImageDevice.ExecuteReadData(CONST_CMD_GetLiveViewImage); if (result.ErrorCode == ErrorCodes.MTP_Not_LiveView) { _timer.Start(); viewData.IsLiveViewRunning = false; viewData.ImageData = null; return(viewData); } if (result.Data == null || result.Data.Length <= headerSize) { return(null); } int cbBytesRead = result.Data.Length; GetAdditionalLiveViewData(viewData, result.Data); MemoryStream copy = new MemoryStream(cbBytesRead - headerSize); copy.Write(result.Data, headerSize, cbBytesRead - headerSize); copy.Close(); viewData.ImageData = copy.GetBuffer(); return(viewData); }
public override LiveViewData GetLiveViewImage() { LiveViewData viewData = new LiveViewData(); if (Monitor.TryEnter(Locker, 10)) { try { //DeviceReady(); viewData.HaveFocusData = true; const int headerSize = 384; byte[] result = StillImageDevice.ExecuteReadData(CONST_CMD_GetLiveViewImage); if (result == null || result.Length <= headerSize) { return(null); } GetAditionalLIveViewData(viewData, result); viewData.ImagePosition = headerSize; viewData.ImageData = result; } finally { Monitor.Exit(Locker); } } return(viewData); }
public override void CapturePhotoNoAf() { lock (Locker) { MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_GetDevicePropValue, CONST_PROP_LiveViewStatus); ErrorCodes.GetException(response.ErrorCode); // test if live view is on if (response.Data != null && response.Data.Length > 0 && response.Data[0] > 0) { if (CaptureInSdRam) { DeviceReady(); ErrorCodes.GetException(StillImageDevice.ExecuteWithNoData(CONST_CMD_InitiateCaptureRecInSdram, 0xFFFFFFFF)); return; } StopLiveView(); } DeviceReady(); byte oldval = 0; var val = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_AFModeSelect); if (val.Data != null && val.Data.Length > 0) { oldval = val.Data[0]; } SetProperty(CONST_CMD_SetDevicePropValue, new[] { (byte)4 }, CONST_PROP_AFModeSelect); DeviceReady(); ErrorCodes.GetException(StillImageDevice.ExecuteWithNoData(CONST_CMD_InitiateCapture)); if (val.Data != null && val.Data.Length > 0) { SetProperty(CONST_CMD_SetDevicePropValue, new[] { oldval }, CONST_PROP_AFModeSelect); } } }
override public LiveViewData GetLiveViewImage() { LiveViewData viewData = new LiveViewData(); viewData.HaveFocusData = true; const int headerSize = 128; byte[] result = StillImageDevice.ExecuteReadData(CONST_CMD_GetLiveViewImage); if (result == null || result.Length <= headerSize) { return(null); } int cbBytesRead = result.Length; GetAditionalLIveViewData(viewData, result); MemoryStream copy = new MemoryStream((int)cbBytesRead - headerSize); copy.Write(result, headerSize, (int)cbBytesRead - headerSize); copy.Close(); viewData.ImageData = copy.GetBuffer(); return(viewData); }
public override bool Init(DeviceDescriptor deviceDescriptor) { StillImageDevice = new StillImageDevice(deviceDescriptor.WpdId); StillImageDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber); StillImageDevice.DeviceEvent += StillImageDevice_DeviceEvent; IsConnected = true; return(true); }
public override void EndBulbMode() { lock (Locker) { DeviceReady(); ErrorCodes.GetException(StillImageDevice.ExecuteWithNoData(CONST_CMD_TerminateCapture, 0, 0)); DeviceReady(); StillImageDevice.ExecuteWithNoData(CONST_CMD_ChangeCameraMode, 0); } }
public override bool Init(DeviceDescriptor deviceDescriptor) { StillImageDevice = deviceDescriptor.StillImageDevice; StillImageDevice imageDevice = StillImageDevice as StillImageDevice; if (imageDevice != null) { imageDevice.DeviceEvent += StillImageDevice_DeviceEvent; } IsConnected = true; return(true); }
/// <summary> /// Take picture with no autofocus /// If live view runnig the live view is stoped after done restarted /// </summary> public override void CapturePhotoNoAf() { lock (Locker) { try { IsBusy = true; MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_GetDevicePropValue, CONST_PROP_LiveViewStatus, -1); ErrorCodes.GetException(response.ErrorCode); // test if live view is on if (response.Data != null && response.Data.Length > 0 && response.Data[0] > 0) { if (CaptureInSdRam) { DeviceReady(); ErrorCodes.GetException(ExecuteWithNoData(CONST_CMD_InitiateCaptureRecInSdram, 0xFFFFFFFF)); return; } StopLiveView(); } // the focus mode can be sett only in host mode LockCamera(); byte oldval = 0; byte[] val = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_AFModeSelect, -1); if (val != null && val.Length > 0) { oldval = val[0]; } SetProperty(CONST_CMD_SetDevicePropValue, new[] { (byte)4 }, CONST_PROP_AFModeSelect, -1); ErrorCodes.GetException(CaptureInSdRam ? ExecuteWithNoData(CONST_CMD_InitiateCaptureRecInSdram, 0xFFFFFFFF) : ExecuteWithNoData(CONST_CMD_InitiateCapture)); if (val != null && val.Length > 0) { SetProperty(CONST_CMD_SetDevicePropValue, new[] { oldval }, CONST_PROP_AFModeSelect, -1); } UnLockCamera(); } catch (Exception) { IsBusy = false; throw; } //if (live != null && live.Length > 0 && live[0] == 1) // StartLiveView(); } }
public override void StartBulbMode() { DeviceReady(); StillImageDevice.ExecuteWithNoData(CONST_CMD_ChangeCameraMode, 1); SetProperty(CONST_CMD_SetDevicePropValue, BitConverter.GetBytes((UInt16)0x0001), CONST_PROP_ExposureProgramMode, -1); SetProperty(CONST_CMD_SetDevicePropValue, BitConverter.GetBytes((UInt32)0xFFFFFFFF), CONST_PROP_ExposureTime, -1); ErrorCodes.GetException(CaptureInSdRam ? StillImageDevice.ExecuteWithNoData(CONST_CMD_InitiateCaptureRecInMedia, 0xFFFFFFFF, 0x0001) : StillImageDevice.ExecuteWithNoData(CONST_CMD_InitiateCaptureRecInMedia, 0xFFFFFFFF, 0x0000)); }
public override bool Init(DeviceDescriptor deviceDescriptor) { StillImageDevice = new StillImageDevice(deviceDescriptor.WpdId); StillImageDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber); StillImageDevice.DeviceEvent += _stillImageDevice_DeviceEvent; DeviceName = StillImageDevice.Model; Manufacturer = StillImageDevice.Manufacturer; Capabilities.Add(CapabilityEnum.Bulb); Capabilities.Add(CapabilityEnum.LiveView); InitShutterSpeed(); IsConnected = true; ExecuteWithNoData(CONST_CMD_CANON_EOS_SetRemoteMode, 1); ExecuteWithNoData(CONST_CMD_CANON_EOS_SetEventMode, 1); _timer.Start(); return(true); }
void _stillImageDevice_DeviceEvent(object sender, PortableDeviceEventArgs e) { if (e.EventType.EventGuid == PortableDeviceGuids.WPD_EVENT_DEVICE_REMOVED) { StillImageDevice.Disconnect(); StillImageDevice.IsConnected = false; IsConnected = false; OnCameraDisconnected(this, new DisconnectCameraEventArgs { StillImageDevice = StillImageDevice }); } else { getEvent(); } }
/// <summary> /// Take picture with no autofocus /// If live view runnig the live view is stoped after done restarted /// </summary> public override void CapturePhotoNoAf() { lock (Locker) { byte oldval = 0; byte[] val = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_AFModeSelect, -1); if (val != null && val.Length > 0) oldval = val[0]; ErrorCodes.GetException(StillImageDevice.ExecuteWriteData(CONST_CMD_SetDevicePropValue, new[] { (byte)4 }, CONST_PROP_AFModeSelect, -1)); ErrorCodes.GetException(StillImageDevice.ExecuteWithNoData(CONST_CMD_InitiateCapture)); if (val != null && val.Length > 0) ErrorCodes.GetException(StillImageDevice.ExecuteWriteData(CONST_CMD_SetDevicePropValue, new[] { oldval }, CONST_PROP_AFModeSelect, -1)); } }
public override bool Init(DeviceDescriptor deviceDescriptor) { base.Init(deviceDescriptor); Properties.Add(InitFocalLength()); ExposureCompensation = new PropertyValue <int> { Available = false }; ExposureMeteringMode = new PropertyValue <int> { Available = false }; FNumber = new PropertyValue <int> { Available = false }; IsoNumber = new PropertyValue <int> { Available = false }; CompressionSetting = new PropertyValue <int> { Available = false }; Mode = new PropertyValue <uint>() { Available = false }; ShutterSpeed = new PropertyValue <long>() { Available = false }; WhiteBalance = new PropertyValue <long>() { Available = false }; FocusMode = new PropertyValue <long>() { Available = false }; StillImageDevice imageDevice = StillImageDevice as StillImageDevice; if (imageDevice != null) { imageDevice.DeviceEvent += StillImageDevice_DeviceEvent; } return(true); }
protected override void InitCompressionSetting() { try { byte datasize = 1; CompressionSetting = new PropertyValue <int>(); CompressionSetting.ValueChanged += CompressionSetting_ValueChanged; byte[] result = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropDesc, CONST_PROP_CompressionSetting); byte defval = result[datasize + 5]; for (int i = 0; i < result.Length - ((2 * datasize) + 6 + 2); i += datasize) { byte val = result[((2 * datasize) + 6 + 2) + i]; CompressionSetting.AddValues(_csTable.ContainsKey(val) ? _csTable[val] : val.ToString(), val); } CompressionSetting.SetValue(defval); } catch (Exception) { } }
public override bool Init(DeviceDescriptor deviceDescriptor) { StillImageDevice = deviceDescriptor.StillImageDevice; StillImageDevice imageDevice = StillImageDevice as StillImageDevice; if (imageDevice != null) { imageDevice.DeviceEvent += StillImageDevice_DeviceEvent; } IsConnected = true; DeviceName = StillImageDevice.Model; Manufacturer = StillImageDevice.Manufacturer; var data = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_BatteryLevel); if (data.Data != null && data.Data.Length > 0) { Battery = data.Data[0]; } return(true); }
public bool Init(DeviceDescriptor deviceDescriptor, DeviceDescription description) { base.Init(deviceDescriptor); StillImageDevice imageDevice = StillImageDevice as StillImageDevice; if (imageDevice != null) { imageDevice.DeviceEvent += StillImageDevice_DeviceEvent; } foreach (var property in description.Properties) { if (!string.IsNullOrEmpty(property.Name)) { try { MTPDataResponse result = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropDesc, property.Code); ErrorCodes.GetException(result.ErrorCode); uint dataType = BitConverter.ToUInt16(result.Data, 2); int dataLength = StaticHelper.GetDataLength(dataType); var value = new PropertyValue <long> { Code = property.Code, Name = property.Name }; foreach (var propertyValue in property.Values) { value.AddValues(propertyValue.Name, propertyValue.Value); } value.ValueChanged += value_ValueChanged; AdvancedProperties.Add(value); } catch (Exception ex) { Log.Error("Error ger property ", ex); } } } return(true); }
private void DisconnectCamera(StillImageDevice device) { DeviceDescriptor descriptor = _deviceEnumerator.GetByWpdId(device.DeviceId); if (descriptor != null) { descriptor.CameraDevice.PhotoCaptured -= cameraDevice_PhotoCaptured; descriptor.CameraDevice.CameraDisconnected -= cameraDevice_CameraDisconnected; ConnectedDevices.Remove(descriptor.CameraDevice); StaticHelper.Instance.SystemMessage = "Camera disconnected :" + descriptor.CameraDevice.DeviceName; Log.Debug("===========Camera disconnected=============="); Log.Debug("Name :" + descriptor.CameraDevice.DeviceName); PortableDeviceCollection.Instance.RemoveDevice(device.DeviceId); device.IsConnected = false; if (SelectedCameraDevice == descriptor.CameraDevice) { SelectedCameraDevice = ConnectedDevices.Count > 0 ? ConnectedDevices[0] : new NotConnectedCameraDevice(); } descriptor.CameraDevice.Close(); _deviceEnumerator.Remove(descriptor); _deviceEnumerator.RemoveDisconnected(); } RemoveDisconnected(); }
public override LiveViewData GetLiveViewImage() { LiveViewData viewData = new LiveViewData(); if (Monitor.TryEnter(Locker, 10)) { try { //DeviceReady(); viewData.HaveFocusData = true; const int headerSize = 384; var result = StillImageDevice.ExecuteReadData(CONST_CMD_GetLiveViewImage); if (result.ErrorCode == ErrorCodes.MTP_Not_LiveView) { _timer.Start(); viewData.IsLiveViewRunning = false; viewData.ImageData = null; return(viewData); } if (result.Data == null || result.Data.Length <= headerSize) { return(null); } GetAdditionalLiveViewData(viewData, result.Data); viewData.ImageDataPosition = headerSize; viewData.ImageData = result.Data; } finally { Monitor.Exit(Locker); } } return(viewData); }
protected virtual PropertyValue <long> InitFocalLength() { PropertyValue <long> res = new PropertyValue <long>() { Name = "Focal Length", IsEnabled = true, Code = 0x5008, SubType = typeof(UInt32) }; res.AddValues("3500", 0x0DAC); res.AddValues("4600", 0x11F8); res.AddValues("5300", 0x14B4); res.AddValues("6100", 0x17D4); res.AddValues("7300", 0x1C84); res.AddValues("8600", 0x2198); res.AddValues("10500", 0x2904); res.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, res.Code), false); res.ReloadValues(); res.ValueChanged += (sender, key, val) => SetProperty(CONST_CMD_SetDevicePropValue, BitConverter.GetBytes(val), res.Code); return(res); }
public override void UnLockCamera() { StillImageDevice.ExecuteWithNoData(CONST_CMD_ChangeCameraMode, 0); }
public override void ReadDeviceProperties(uint prop) { //lock (Locker) //{ try { HaveLiveView = true; switch (prop) { case CONST_PROP_Fnumber: //FNumber.SetValue(_stillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_Fnumber)); ReInitFNumber(false); break; case CONST_PROP_MovieFnumber: //FNumber.SetValue(_stillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_Fnumber)); ReInitFNumber(false); break; case CONST_PROP_ExposureIndex: NormalIsoNumber.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_ExposureIndex), false); break; //case CONST_PROP_ExposureIndexEx: // NormalIsoNumber.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, // CONST_PROP_ExposureIndexEx), false); // break; case CONST_PROP_MovieExposureIndex: MovieFNumber.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_MovieExposureIndex), false); break; //case CONST_PROP_ExposureTime: // NormalShutterSpeed.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, // CONST_PROP_ExposureTime), false); // break; case CONST_PROP_ShutterSpeed: NormalShutterSpeed.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_ShutterSpeed), false); break; case CONST_PROP_MovieShutterSpeed: MovieShutterSpeed.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_MovieShutterSpeed), false); break; case CONST_PROP_WhiteBalance: WhiteBalance.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_WhiteBalance), false); break; case CONST_PROP_ExposureProgramMode: Mode.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_ExposureProgramMode), true); break; case CONST_PROP_ExposureBiasCompensation: NormalExposureCompensation.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_ExposureBiasCompensation), false); break; case CONST_PROP_MovieExposureBiasCompensation: MovieExposureCompensation.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_MovieExposureBiasCompensation), false); break; case CONST_PROP_CompressionSetting: CompressionSetting.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_CompressionSetting), false); break; case CONST_PROP_ExposureMeteringMode: ExposureMeteringMode.SetValue(StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_ExposureMeteringMode), false); break; case CONST_PROP_AFModeSelect: NormalFocusMode.SetValue( StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_AFModeSelect), false); NormalFocusMode.IsEnabled = NormalFocusMode.NumericValue != 3; break; case CONST_PROP_AfModeAtLiveView: LiveViewFocusMode.SetValue( StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_AfModeAtLiveView), false); LiveViewFocusMode.IsEnabled = LiveViewFocusMode.NumericValue != 3; break; case CONST_PROP_BatteryLevel: { var data = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_BatteryLevel); if (data.Data != null && data.Data.Length > 0) { Battery = data.Data[0]; } } break; case CONST_PROP_ExposureIndicateStatus: { var data = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_ExposureIndicateStatus); if (data.Data != null && data.Data.Length > 0) { sbyte i = unchecked ( (sbyte)data.Data[0]); ExposureStatus = Convert.ToInt32(i); } } break; case CONST_PROP_LiveViewStatus: { MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_GetDevicePropValue, CONST_PROP_LiveViewStatus); if (response.Data != null && response.Data.Length > 0) { LiveViewOn = response.Data[0] == 1; } else { LiveViewOn = false; } break; } case CONST_PROP_LiveViewSelector: { MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_GetDevicePropValue, CONST_PROP_LiveViewSelector); if (response.Data != null && response.Data.Length > 0) { LiveViewMovieOn = response.Data[0] == 1; } else { LiveViewMovieOn = false; } break; } default: // imrovements from: http://digicamcontrol.com/forum/testingbug-reports/buglet-nikonbasecs foreach (PropertyValue <long> advancedProperty in AdvancedProperties.Where(advancedProperty => advancedProperty.Code == prop)) { if (advancedProperty.Name == "Image Size") { var val = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, advancedProperty.Code); if (val.Data != null && val.Data.Length > 0) { advancedProperty.SetValue( Encoding.Unicode.GetString(val.Data, 1, 20), false); } } else { advancedProperty.SetValue( StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, advancedProperty.Code), false); } } break; } } catch (Exception ex) { Log.Error("ReadDeviceProperties error", ex); } //} }
protected override void ReInitShutterSpeed() { lock (Locker) { DeviceReady(); try { byte datasize = 4; var result = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropDesc, CONST_PROP_ShutterSpeed); if (result.Data == null) { return; } NormalShutterSpeed.Clear(); int type = BitConverter.ToInt16(result.Data, 2); byte formFlag = result.Data[(2 * datasize) + 5]; UInt32 defval = BitConverter.ToUInt32(result.Data, datasize + 5); for (int i = 0; i < result.Data.Length - ((2 * datasize) + 6 + 2); i += datasize) { UInt32 val = BitConverter.ToUInt32(result.Data, ((2 * datasize) + 6 + 2) + i); NormalShutterSpeed.AddValues(_shutterTable.ContainsKey(val) ? _shutterTable[val] : val.ToString(), val); } // force to add Bulb mode for some cameras which not support it if (Mode != null && (Mode.Value == "S" || Mode.Value == "M") && !NormalShutterSpeed.Values.Contains("Bulb")) { NormalShutterSpeed.AddValues("Bulb", 0xFFFFFFFF); } NormalShutterSpeed.ReloadValues(); NormalShutterSpeed.SetValue(defval, false); ShutterSpeed = NormalShutterSpeed; } catch (Exception) { } try { byte datasize = 4; var result = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropDesc, CONST_PROP_MovieShutterSpeed); if (result.Data == null || result.Data.Length == 0) { return; } MovieShutterSpeed.Clear(); int type = BitConverter.ToInt16(result.Data, 2); byte formFlag = result.Data[(2 * datasize) + 5]; UInt32 defval = BitConverter.ToUInt32(result.Data, datasize + 5); for (int i = 0; i < result.Data.Length - ((2 * datasize) + 6 + 2); i += datasize) { UInt32 val = BitConverter.ToUInt32(result.Data, ((2 * datasize) + 6 + 2) + i); MovieShutterSpeed.AddValues("1/" + (val - 0x10000), val); } // force to add Bulb mode for some cameras which not support it if (Mode != null && (Mode.Value == "S" || Mode.Value == "M") && !MovieShutterSpeed.Values.Contains("Bulb")) { MovieShutterSpeed.AddValues("Bulb", 0xFFFFFFFF); } MovieShutterSpeed.SetValue(defval, false); } catch (Exception) { } } }