Example #1
0
        private void InitFocusMode()
        {
            var vals = AsPrimitiveList <string>(Post(CreateJson("getSupportedFocusMode")));

            FocusMode = new PropertyValue <long>();
            int i = 0;

            foreach (string val in vals)
            {
                FNumber.AddValues(val, i++);
            }
            FNumber.Value = AsPrimitive <string>(Post(CreateJson("getFocusMode")));
            FNumber.ReloadValues();
            FNumber.ValueChanged += (sender, key, val) => CheckError(Post(CreateJson("setFocusMode", "1.0", key)));
        }
        private void ReInitFNumber(bool trigervaluchange)
        {
            try
            {
                var  data       = Camera.GetPropertyDescription(Edsdk.PropID_Av);
                long value      = Camera.GetProperty(Edsdk.PropID_Av);
                bool shouldinit = FNumber.Values.Count == 0;

                if (data.NumElements > 0)
                {
                    FNumber.Clear();
                }

                if (shouldinit && data.NumElements == 0)
                {
                    foreach (KeyValuePair <int, string> keyValuePair in _apertureTable)
                    {
                        FNumber.AddValues(keyValuePair.Value, keyValuePair.Key);
                    }
                }
                else
                {
                    foreach (KeyValuePair <int, string> keyValuePair in _apertureTable.Where(keyValuePair => data.NumElements > 0).Where(keyValuePair => ArrayContainValue(data.PropDesc, keyValuePair.Key)))
                    {
                        FNumber.AddValues(keyValuePair.Value, keyValuePair.Key);
                    }
                }

                if (value == 0)
                {
                    FNumber.IsEnabled = false;
                }
                else
                {
                    FNumber.SetValue((int)value, false);
                    FNumber.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Error set aperture ", ex);
            }
        }
Example #3
0
        /// <summary>
        /// Returns the sub item item text corresponding to the specified column type.
        /// </summary>
        /// <param name="type">The type of information to return.</param>
        /// <returns>Formatted text for the given column type.</returns>
        public string GetSubItemText(ColumnType type)
        {
            switch (type)
            {
            case ColumnType.DateAccessed:
                if (DateAccessed == DateTime.MinValue)
                {
                    return("");
                }
                else
                {
                    return(DateAccessed.ToString("g"));
                }

            case ColumnType.DateCreated:
                if (DateCreated == DateTime.MinValue)
                {
                    return("");
                }
                else
                {
                    return(DateCreated.ToString("g"));
                }

            case ColumnType.DateModified:
                if (DateModified == DateTime.MinValue)
                {
                    return("");
                }
                else
                {
                    return(DateModified.ToString("g"));
                }

            case ColumnType.FileName:
                return(FileName);

            case ColumnType.Name:
                return(Text);

            case ColumnType.FilePath:
                return(FilePath);

            case ColumnType.FileSize:
                if (FileSize == 0)
                {
                    return("");
                }
                else
                {
                    return(Utility.FormatSize(FileSize));
                }

            case ColumnType.FileType:
                return(FileType);

            case ColumnType.Dimensions:
                if (Dimensions == Size.Empty)
                {
                    return("");
                }
                else
                {
                    return(string.Format("{0} x {1}", Dimensions.Width, Dimensions.Height));
                }

            case ColumnType.Resolution:
                if (Resolution == SizeF.Empty)
                {
                    return("");
                }
                else
                {
                    return(string.Format("{0} x {1}", Resolution.Width, Resolution.Height));
                }

            case ColumnType.ImageDescription:
                return(ImageDescription);

            case ColumnType.EquipmentModel:
                return(EquipmentModel);

            case ColumnType.DateTaken:
                if (DateTaken == DateTime.MinValue)
                {
                    return("");
                }
                else
                {
                    return(DateTaken.ToString("g"));
                }

            case ColumnType.Artist:
                return(Artist);

            case ColumnType.Copyright:
                return(Copyright);

            case ColumnType.ExposureTime:
                return(ExposureTime);

            case ColumnType.FNumber:
                if (FNumber == 0.0f)
                {
                    return("");
                }
                else
                {
                    return(FNumber.ToString("f2"));
                }

            case ColumnType.ISOSpeed:
                if (ISOSpeed == 0)
                {
                    return("");
                }
                else
                {
                    return(ISOSpeed.ToString());
                }

            case ColumnType.ShutterSpeed:
                return(ShutterSpeed);

            case ColumnType.Aperture:
                return(Aperture);

            case ColumnType.UserComment:
                return(UserComment);

            default:
                throw new ArgumentException("Unknown column type", "type");
            }
        }
Example #4
0
        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);
        }