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); } //} }
public override bool Init(DeviceDescriptor deviceDescriptor) { IsBusy = false; //the device not connected try { ConnectToWiaDevice(deviceDescriptor); } catch (Exception exception) { Log.Error("Unable to connect camera using wia driver", exception); return(false); } DeviceManager = new DeviceManager(); DeviceManager.RegisterEvent(Conts.wiaEventItemCreated, deviceDescriptor.WiaId); DeviceManager.OnEvent += DeviceManager_OnEvent; try { Device = deviceDescriptor.WiaDevice; DeviceName = Device.Properties["Description"].get_Value(); Manufacturer = Device.Properties["Manufacturer"].get_Value(); SerialNumber = StaticHelper.GetSerial(Device.Properties["PnP ID String"].get_Value()); } catch (Exception ex) { Log.Debug("Init error", ex); } IsConnected = true; try { try { Property apertureProperty = Device.Properties[Conts.CONST_PROP_F_Number]; if (apertureProperty != null) { foreach (var subTypeValue in apertureProperty.SubTypeValues) { double d = (int)subTypeValue; string s = (d / 100).ToString("0.0"); FNumber.AddValues(s, (int)d); FNumber.ReloadValues(); if ((int)subTypeValue == (int)apertureProperty.get_Value()) { FNumber.SetValue((int)d); } } } } catch (COMException) { FNumber.IsEnabled = false; } try { Property isoProperty = Device.Properties[Conts.CONST_PROP_ISO_Number]; if (isoProperty != null) { foreach (var subTypeValue in isoProperty.SubTypeValues) { IsoNumber.AddValues(subTypeValue.ToString(), (int)subTypeValue); IsoNumber.ReloadValues(); if ((int)subTypeValue == (int)isoProperty.get_Value()) { IsoNumber.SetValue((int)subTypeValue); } } } } catch (COMException) { IsoNumber.IsEnabled = false; } try { Property shutterProperty = Device.Properties[Conts.CONST_PROP_Exposure_Time]; if (shutterProperty != null) { foreach (int subTypeValue in shutterProperty.SubTypeValues) { if (ShutterTable.ContainsKey((int)subTypeValue)) { ShutterSpeed.AddValues(ShutterTable[(int)subTypeValue], (int)subTypeValue); } } ShutterSpeed.ReloadValues(); ShutterSpeed.SetValue(shutterProperty.get_Value()); } } catch (COMException) { ShutterSpeed.IsEnabled = false; } try { Property wbProperty = Device.Properties[Conts.CONST_PROP_WhiteBalance]; if (wbProperty != null) { foreach (var subTypeValue in wbProperty.SubTypeValues) { if (WbTable.ContainsKey((int)subTypeValue)) { WhiteBalance.AddValues(WbTable[(int)subTypeValue], (int)subTypeValue); } } WhiteBalance.ReloadValues(); WhiteBalance.SetValue(wbProperty.get_Value()); } } catch (COMException) { WhiteBalance.IsEnabled = false; } try { Property modeProperty = Device.Properties[Conts.CONST_PROP_ExposureMode]; if (modeProperty != null) { foreach (var subTypeValue in modeProperty.SubTypeValues) { if (ExposureModeTable.ContainsKey((int)subTypeValue)) { Mode.AddValues(ExposureModeTable[(int)subTypeValue], Convert.ToUInt32(subTypeValue)); } } Mode.ReloadValues(); Mode.SetValue(Convert.ToUInt32(modeProperty.get_Value())); } Mode.IsEnabled = false; } catch (COMException) { Mode.IsEnabled = false; } try { Property ecProperty = Device.Properties[Conts.CONST_PROP_ExposureCompensation]; if (ecProperty != null) { foreach (var subTypeValue in ecProperty.SubTypeValues) { decimal d = (int)subTypeValue; string s = decimal.Round(d / 1000, 1).ToString(); if (d > 0) { s = "+" + s; } ExposureCompensation.AddValues(s, (int)subTypeValue); } ExposureCompensation.ReloadValues(); ExposureCompensation.SetValue(ecProperty.get_Value()); } } catch (COMException) { ExposureCompensation.IsEnabled = false; } try { Property csProperty = Device.Properties[Conts.CONST_PROP_CompressionSetting]; if (csProperty != null) { foreach (var subTypeValue in csProperty.SubTypeValues) { if (CSTable.ContainsKey((int)subTypeValue)) { CompressionSetting.AddValues(CSTable[(int)subTypeValue], (int)subTypeValue); } } CompressionSetting.ReloadValues(); CompressionSetting.SetValue(csProperty.get_Value()); } } catch (COMException) { CompressionSetting.IsEnabled = false; } try { Property emmProperty = Device.Properties[Conts.CONST_PROP_ExposureMeteringMode]; if (emmProperty != null) { foreach (var subTypeValue in emmProperty.SubTypeValues) { if (EMMTable.ContainsKey((int)subTypeValue)) { ExposureMeteringMode.AddValues(EMMTable[(int)subTypeValue], (int)subTypeValue); } } ExposureMeteringMode.ReloadValues(); ExposureMeteringMode.SetValue(emmProperty.get_Value()); } } catch (COMException) { CompressionSetting.IsEnabled = false; } try { Property fmProperty = Device.Properties[Conts.CONST_PROP_FocusMode]; if (fmProperty != null) { foreach (int subTypeValue in fmProperty.SubTypeValues) { uint subval = Convert.ToUInt16(subTypeValue); if (FMTable.ContainsKey(subval)) { FocusMode.AddValues(FMTable[subval], subval); } } FocusMode.ReloadValues(); FocusMode.SetValue(Convert.ToUInt16((int)fmProperty.get_Value())); } } catch (COMException) { FocusMode.IsEnabled = false; } try { Battery = Device.Properties[Conts.CONST_PROP_BatteryStatus].get_Value(); } catch (COMException) { Battery = 0; } IsConnected = true; } catch (Exception exception) { Log.Error(exception); IsConnected = false; } HaveLiveView = true; //Capabilities.Add(CapabilityEnum.LiveView); return(true); }
private void SetValues(string data) { List <string> values = new List <string>(); dynamic a = JsonConvert.DeserializeObject(data); foreach (string o in a.options) { values.Add(o); } string param = (string)a.param; switch (param) { case "photo_quality": CompressionSetting.Clear(); for (int i = 0; i < values.Count; i++) { CompressionSetting.AddValues(values[i], i); } CompressionSetting.IsEnabled = a.permission == "settable"; CompressionSetting.ReloadValues(); CompressionSetting.Value = GetValue(param); break; case "meter_mode": ExposureMeteringMode.Clear(); for (int i = 0; i < values.Count; i++) { ExposureMeteringMode.AddValues(values[i], i); } ExposureMeteringMode.ReloadValues(); ExposureMeteringMode.IsEnabled = a.permission == "settable"; ExposureMeteringMode.Value = GetValue(param); break; default: foreach (var property in Properties) { if (property.Tag == param) { property.Clear(); for (int i = 0; i < values.Count; i++) { property.AddValues(values[i], i); } property.IsEnabled = a.permission == "settable"; property.ReloadValues(); property.Value = GetValue(param); } } foreach (var property in AdvancedProperties) { if (property.Tag == param) { property.Clear(); for (int i = 0; i < values.Count; i++) { property.AddValues(values[i], i); } property.IsEnabled = a.permission == "settable"; property.ReloadValues(); property.Value = GetValue(param); } } break; } }