示例#1
0
        private void PopulateProperties()
        {
            foreach (XmlPropertyDescriptor xmlPropertyDescriptor in DeviceInfo.AvaiableProperties)
            {
                try
                {
                    int             index  = 0;
                    MTPDataResponse result = MTPCamera.ExecuteReadDataEx(BaseMTPCamera.CONST_CMD_GetDevicePropDesc,
                                                                         xmlPropertyDescriptor.Code);
                    ErrorCodes.GetException(result.ErrorCode);
                    uint dataType = BitConverter.ToUInt16(result.Data, 2);
                    xmlPropertyDescriptor.DataType = dataType;
                    int dataLength = StaticHelper.GetDataLength(dataType);
                    if (dataLength < 1)
                    {
                        continue;
                    }
                    index += 4;
                    byte datareadonly = result.Data[index];
                    index += 1;
                    //factory def
                    index += dataLength;
                    // current value
                    index += dataLength;

                    byte formFlag = result.Data[index];
                    index += 1;
                    xmlPropertyDescriptor.DataForm = formFlag;
                    //UInt16 defval = BitConverter.ToUInt16(result.Data, 7);
                    if (formFlag == 2)
                    {
                        int length = BitConverter.ToInt16(result.Data, index);
                        index += 2;
                        for (int i = 0; i < length; i++)
                        {
                            long val = StaticHelper.GetValue(result, index, dataLength);
                            ;
                            xmlPropertyDescriptor.Values.Add(new XmlPropertyValue()
                            {
                                Value = val
                            });
                            index += dataLength;
                        }
                    }
                    if (formFlag == 1)
                    {
                        xmlPropertyDescriptor.MinVal = StaticHelper.GetValue(result, index, dataLength);
                        index += dataLength;
                        xmlPropertyDescriptor.MaxVal = StaticHelper.GetValue(result, index, dataLength);
                        index += dataLength;
                        xmlPropertyDescriptor.Inc = StaticHelper.GetValue(result, index, dataLength);
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Error process property " + exception.Message);
                }
            }
        }
示例#2
0
 private void btn_get_value_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (MTPCamera == null || MTPCamera.IsConnected == false)
         {
             DeviceInfo = new XmlDeviceData();
             SelectDevice wnd = new SelectDevice();
             wnd.ShowDialog();
             if (wnd.DialogResult == true && wnd.SelectedDevice != null)
             {
                 SelectedDevice = wnd.SelectedDevice;
                 DeviceDescriptor descriptor = new DeviceDescriptor {
                     WpdId = SelectedDevice.DeviceId
                 };
                 MTPCamera = new BaseMTPCamera();
                 MTPCamera.Init(descriptor);
             }
             else
             {
                 return;
             }
         }
         XmlPropertyDescriptor propertyDescriptor = lst_prop.SelectedItem as XmlPropertyDescriptor;
         MTPDataResponse       resp = MTPCamera.ExecuteReadDataEx(BaseMTPCamera.CONST_CMD_GetDevicePropValue,
                                                                  propertyDescriptor.Code);
         long             val      = StaticHelper.GetValue(resp, 0, StaticHelper.GetDataLength(propertyDescriptor.DataType));
         XmlPropertyValue selected = null;
         foreach (XmlPropertyValue xmlPropertyValue in propertyDescriptor.Values)
         {
             if (xmlPropertyValue.Value == val)
             {
                 selected = xmlPropertyValue;
             }
         }
         if (selected != null)
         {
             lst_values.BeginInit();
             lst_values.SelectedItem = selected;
             lst_values.EndInit();
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show("Error to get value " + exception.Message);
     }
 }
示例#3
0
        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);
        }