public MainWindow()
 {
     InitializeComponent();
     if (File.Exists("baseMtpDevice.xml"))
     {
         DefaultDeviceInfo = XmlDeviceData.Load("baseMtpDevice.xml");
     }
 }
 public static XmlDeviceData Load(string filename)
 {
     XmlDeviceData photoSession = new XmlDeviceData();
     if (File.Exists(filename))
     {
         XmlSerializer mySerializer =
             new XmlSerializer(typeof (XmlDeviceData));
         FileStream myFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
         photoSession = (XmlDeviceData) mySerializer.Deserialize(myFileStream);
         myFileStream.Close();
     }
     return photoSession;
 }
        public static XmlDeviceData Load(string filename)
        {
            XmlDeviceData photoSession = new XmlDeviceData();

            if (File.Exists(filename))
            {
                XmlSerializer mySerializer =
                    new XmlSerializer(typeof(XmlDeviceData));
                FileStream myFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
                photoSession = (XmlDeviceData)mySerializer.Deserialize(myFileStream);
                myFileStream.Close();
            }
            return(photoSession);
        }
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            DeviceInfo = new XmlDeviceData();
            SelectDevice wnd = new SelectDevice();
            wnd.ShowDialog();
            if (wnd.DialogResult == true && wnd.SelectedDevice != null)
            {
                try
                {
                    SelectedDevice = wnd.SelectedDevice;
                    DeviceDescriptor descriptor = new DeviceDescriptor {WpdId = SelectedDevice.DeviceId};
                    MtpProtocol device = new MtpProtocol(descriptor.WpdId);
                    device.ConnectToDevice("MTPTester", 1, 0);
                    descriptor.StillImageDevice = device;
                    MTPCamera = new BaseMTPCamera();
                    MTPCamera.Init(descriptor);
                    LoadDeviceData(MTPCamera.ExecuteReadDataEx(0x1001));
                    //LoadDeviceData(MTPCamera.ExecuteReadDataEx(0x9108));
     
                    PopulateProperties();
                }
                catch (DeviceException exception)
                {
                    MessageBox.Show("Error getting device information" + exception.Message);
                }
                catch (Exception exception)
                {
                    MessageBox.Show("General error" + exception.Message);
                }
                if (DefaultDeviceInfo != null)
                {
                    foreach (XmlCommandDescriptor command in DeviceInfo.AvaiableCommands)
                    {
                        command.Name = DefaultDeviceInfo.GetCommandName(command.Code);
                    }
                    foreach (XmlEventDescriptor avaiableEvent in DeviceInfo.AvaiableEvents)
                    {
                        avaiableEvent.Name = DefaultDeviceInfo.GetEventName(avaiableEvent.Code);
                    }
                    foreach (XmlPropertyDescriptor property in DeviceInfo.AvaiableProperties)
                    {
                        property.Name = DefaultDeviceInfo.GetPropName(property.Code);
                    }
                }
                InitUi();
            }

        }
示例#5
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 = GetValue(resp, 0, 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);
     }
 }
 private void Button_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;
             }
         }
         XmlPropertyValue property = lst_values.SelectedItem as XmlPropertyValue;
         XmlPropertyDescriptor propertyDescriptor = lst_prop.SelectedItem as XmlPropertyDescriptor;
         if (property != null)
         {
             MTPCamera.SetProperty(BaseMTPCamera.CONST_CMD_SetDevicePropValue,
                                   BitConverter.GetBytes(property.Value), propertyDescriptor.Code);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show("Error set property " + exception.Message);
     }
 }
 private void MenuItem_Click_2(object sender, RoutedEventArgs e)
 {
     try
     {
         OpenFileDialog dialog = new OpenFileDialog();
         dialog.Filter = "Xml file (*.xml)|*.xml";
         if (dialog.ShowDialog() == true)
         {
             DeviceInfo = XmlDeviceData.Load(dialog.FileName);
         }
         InitUi();
     }
     catch (Exception exception)
     {
         MessageBox.Show("Error loading file " + exception.Message);
     }
 }
示例#8
0
 protected XmlDeviceData LoadDeviceData(MTPDataResponse res)
 {
     XmlDeviceData deviceInfo = new XmlDeviceData();
     ErrorCodes.GetException(res.ErrorCode);
     deviceInfo.Manufacturer = Manufacturer;
     int index = 2 + 4 + 2;
     int vendorDescCount = res.Data[index];
     index += vendorDescCount * 2;
     index += 3;
     int comandsCount = res.Data[index];
     index += 2;
     // load commands
     for (int i = 0; i < comandsCount; i++)
     {
         index += 2;
         deviceInfo.AvaiableCommands.Add(new XmlCommandDescriptor() { Code = BitConverter.ToUInt16(res.Data, index) });
     }
     index += 2;
     int eventcount = res.Data[index];
     index += 2;
     // load events
     for (int i = 0; i < eventcount; i++)
     {
         index += 2;
         deviceInfo.AvaiableEvents.Add(new XmlEventDescriptor() { Code = BitConverter.ToUInt16(res.Data, index) });
     }
     index += 2;
     int propertycount = res.Data[index];
     index += 2;
     // load properties codes
     for (int i = 0; i < propertycount; i++)
     {
         index += 2;
         deviceInfo.AvaiableProperties.Add(new XmlPropertyDescriptor() { Code = BitConverter.ToUInt16(res.Data, index) });
     }
     try
     {
         MTPDataResponse vendor_res = ExecuteReadDataEx(0x90CA);
         if (vendor_res.Data.Length > 0)
         {
             index = 0;
             propertycount = vendor_res.Data[index];
             index += 2;
             for (int i = 0; i < propertycount; i++)
             {
                 index += 2;
                 deviceInfo.AvaiableProperties.Add(new XmlPropertyDescriptor() { Code = BitConverter.ToUInt16(vendor_res.Data, index) });
             }
         }
     }
     catch (Exception)
     {
     }
     return deviceInfo;
 }