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; }
public static DeviceDescription Load(string file) { try { DeviceDescription settings = new DeviceDescription(); XmlSerializer mySerializer = new XmlSerializer(typeof(DeviceDescription)); FileStream myFileStream = new FileStream(file, FileMode.Open); settings = (DeviceDescription)mySerializer.Deserialize(myFileStream); myFileStream.Close(); return settings; } catch (Exception ex) { Log.Error("Error load device description "+file,ex); return null; } }
public void SaveData(string filename) { try { DeviceDescription description = new DeviceDescription(); description.Model = DeviceInfo.Model; description.Manufacturer = DeviceInfo.Manufacturer; foreach (var property in DeviceInfo.AvaiableProperties) { var prop = new DeviceProperty {Code = property.Code}; foreach (var propertyValue in property.Values) { prop.Values.Add(new DevicePropertyValue() {Value = propertyValue.Value}); } description.Properties.Add(prop); } XmlSerializer serializer = new XmlSerializer(typeof (DeviceDescription)); // Create a FileStream to write with. Stream writer = new FileStream(filename, FileMode.Create); // Serialize the object, and close the TextWriter serializer.Serialize(writer, description); writer.Close(); } catch (Exception exception) { MessageBox.Show("Unable to save data " + exception.Message); } }