public override void CapturePhotoNoAf() { lock (Locker) { MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_GetDevicePropValue, CONST_PROP_LiveViewStatus); ErrorCodes.GetException(response.ErrorCode); // test if live view is on if (response.Data != null && response.Data.Length > 0 && response.Data[0] > 0) { if (CaptureInSdRam) { DeviceReady(); ErrorCodes.GetException(StillImageDevice.ExecuteWithNoData(CONST_CMD_InitiateCaptureRecInSdram, 0xFFFFFFFF)); return; } StopLiveView(); } DeviceReady(); byte oldval = 0; var val = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_AFModeSelect); if (val.Data != null && val.Data.Length > 0) { oldval = val.Data[0]; } SetProperty(CONST_CMD_SetDevicePropValue, new[] { (byte)4 }, CONST_PROP_AFModeSelect); DeviceReady(); ErrorCodes.GetException(StillImageDevice.ExecuteWithNoData(CONST_CMD_InitiateCapture)); if (val.Data != null && val.Data.Length > 0) { SetProperty(CONST_CMD_SetDevicePropValue, new[] { oldval }, CONST_PROP_AFModeSelect); } } }
public override void TransferFile(object o, string filename) { int retryes = 10; lock (Locker) { _timer.Stop(); MTPDataResponse result = new MTPDataResponse(); //=================== managed file write do { try { result = StillImageDevice.ExecuteReadBigData(CONST_CMD_GetObject, Convert.ToInt32(o), -1, (total, current) => { double i = (double)current / total; TransferProgress = Convert.ToUInt32(i * 100); }); } // if not enough memory for transfer catch it and wait and try again catch (OutOfMemoryException) { } catch (COMException) { } if (result != null && result.Data != null) { BinaryWriter writer = new BinaryWriter(File.Open(filename, FileMode.Create)); writer.Write(result.Data); writer.Flush(); writer.Close(); } else { Log.Error("Transfer error code retrying " + result.ErrorCode.ToString("X")); Thread.Sleep(200); retryes--; } } while (result.Data == null && retryes > 0); //================================================================== //=================== direct file write //StillImageDevice.ExecuteReadBigDataWriteToFile(CONST_CMD_GetObject, // Convert.ToInt32(o), -1, // (total, current) => // { // double i = (double)current / total; // TransferProgress = // Convert.ToUInt32(i * 100); // }, filename); //================================================================== _timer.Start(); TransferProgress = 0; } }
public MTPDataResponse ExecuteReadData(uint code, params uint[] parameters) { lock (_syncRoot) { ReconnectIfNeeded(); DataBlockContainer data; var res = new MTPDataResponse(); _client.Write(new CommandBlockContainer((int)code, parameters)); int len = _client.ReadInt(); Container resp = _client.ReadContainer(); if (resp.Header.Length >= len - 4) { return(new MTPDataResponse() { ErrorCode = (uint)resp.Header.Code }); } data = (DataBlockContainer)resp; resp = _client.ReadContainer(); return(new MTPDataResponse() { Data = data.Payload, ErrorCode = (uint)data.Header.Code }); } }
public override LiveViewData GetLiveViewImage() { _timer.Stop(); LiveViewData viewData = new LiveViewData(); if (Monitor.TryEnter(Locker, 10)) { try { //DeviceReady(); viewData.HaveFocusData = false; MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_CANON_EOS_GetViewFinderData, 0x00100000); ErrorCodes.GetException(response.ErrorCode); if (response.Data == null) { _timer.Start(); return(null); } viewData.ImageDataPosition = 0; viewData.ImageData = response.Data; } catch (Exception e) { Log.Error("Error get live view image ", e); } finally { Monitor.Exit(Locker); } } _timer.Start(); return(viewData); }
public override void CapturePhotoNoAf() { lock (Locker) { try { IsBusy = true; MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_GetDevicePropValue, CONST_PROP_LiveViewStatus, -1); ErrorCodes.GetException(response.ErrorCode); // test if live view is on if (response.Data != null && response.Data.Length > 0 && response.Data[0] > 0) { if (CaptureInSdRam) { DeviceReady(); ErrorCodes.GetException(ExecuteWithNoData(CONST_CMD_InitiateCaptureRecInSdram, 0xFFFFFFFF)); return; } StopLiveView(); } DeviceReady(); ErrorCodes.GetException(ExecuteWithNoData(CONST_CMD_InitiateCapture)); } catch { IsBusy = false; throw; } } }
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 = 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 = GetValue(result, index, dataLength); ; xmlPropertyDescriptor.Values.Add(new XmlPropertyValue() { Value = val }); index += dataLength; } } if (formFlag == 1) { xmlPropertyDescriptor.MinVal = GetValue(result, index, dataLength); index += dataLength; xmlPropertyDescriptor.MaxVal = GetValue(result, index, dataLength); index += dataLength; xmlPropertyDescriptor.Inc = GetValue(result, index, dataLength); } } catch (Exception exception) { MessageBox.Show("Error process property " + exception.Message); } } }
protected override void InitIso() { lock (Locker) { NormalIsoNumber = new PropertyValue <long>(); NormalIsoNumber.Name = "IsoNumber"; NormalIsoNumber.SubType = typeof(int); NormalIsoNumber.ValueChanged += IsoNumber_ValueChanged; NormalIsoNumber.Clear(); try { DeviceReady(); MTPDataResponse result = ExecuteReadDataEx(CONST_CMD_GetDevicePropDesc, CONST_PROP_ExposureIndex); //IsoNumber.IsEnabled = result.Data[4] == 1; //From the D600 documentation this is a uint16 not uint32. //Oddly the MovieExposureIndex DOES use uint32 UInt16 defval = BitConverter.ToUInt16(result.Data, 7); for (int i = 0; i < result.Data.Length - 12; i += 2) { UInt16 val = BitConverter.ToUInt16(result.Data, 12 + i); NormalIsoNumber.AddValues(_isoTable.ContainsKey(val) ? _isoTable[val] : val.ToString(), val); } NormalIsoNumber.ReloadValues(); NormalIsoNumber.SetValue(defval, false); IsoNumber = NormalIsoNumber; } catch (Exception) { NormalIsoNumber.IsEnabled = false; } MovieIsoNumber = new PropertyValue <long>(); MovieIsoNumber.Name = "IsoNumber"; MovieIsoNumber.SubType = typeof(int); MovieIsoNumber.ValueChanged += MovieIsoNumber_ValueChanged; MovieIsoNumber.Clear(); try { MTPDataResponse result = ExecuteReadDataEx(CONST_CMD_GetDevicePropDesc, CONST_PROP_MovieExposureIndex); //IsoNumber.IsEnabled = result.Data[4] == 1; //Uses uint32 but exposureIndex use uint16 UInt32 defval = BitConverter.ToUInt32(result.Data, 9); for (int i = 0; i < result.Data.Length - 16; i += 4) { UInt32 val = BitConverter.ToUInt32(result.Data, 16 + i); MovieIsoNumber.AddValues(_isoTable.ContainsKey(val) ? _isoTable[val] : val.ToString(CultureInfo.InvariantCulture), val); } MovieIsoNumber.ReloadValues(); MovieIsoNumber.SetValue(defval, false); } catch (Exception) { MovieIsoNumber.IsEnabled = false; } } }
private static void ParseDeviceInfo(MTPDataResponse rep) { int offset = 0; int readlen; int StandardVersion = 0; readlen = GetUWord(rep.Data, offset, ref StandardVersion); offset += readlen; }
public override AsyncObservableCollection <DeviceObject> GetObjects(object storageId, bool loadThumbs) { AsyncObservableCollection <DeviceObject> res = new AsyncObservableCollection <DeviceObject>(); MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_GetObjectHandles, 0xFFFFFFFF); if (response.Data == null) { Log.Debug("Get object error :" + response.ErrorCode.ToString("X")); ErrorCodes.GetException(response.ErrorCode); return(res); } int objCount = BitConverter.ToInt32(response.Data, 0); for (int i = 0; i < objCount; i++) { DeviceObject deviceObject = new DeviceObject(); uint handle = BitConverter.ToUInt32(response.Data, 4 * i + 4); deviceObject.Handle = handle; MTPDataResponse objectdata = ExecuteReadDataEx(CONST_CMD_GetObjectInfo, handle); if (objectdata.Data != null) { uint objFormat = BitConverter.ToUInt16(objectdata.Data, 4); if (objFormat == 0x3000 || objFormat == 0x3801 || objFormat == 0x3800) { deviceObject.FileName = Encoding.Unicode.GetString(objectdata.Data, 53, 12 * 2); if (deviceObject.FileName.Contains("\0")) { deviceObject.FileName = deviceObject.FileName.Split('\0')[0]; } try { string datesrt = Encoding.Unicode.GetString(objectdata.Data, 53 + (12 * 2) + 3, 30); //datesrt = datesrt.Replace("T", ""); DateTime date = DateTime.MinValue; if (DateTime.TryParseExact(datesrt, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { deviceObject.FileDate = date; } } catch (Exception) { } if (loadThumbs) { MTPDataResponse thumbdata = ExecuteReadDataEx(CONST_CMD_GetThumb, handle); deviceObject.ThumbData = thumbdata.Data; } res.Add(deviceObject); } } } return(res); }
/// <summary> /// Take picture with no autofocus /// If live view runnig the live view is stoped after done restarted /// </summary> public override void CapturePhotoNoAf() { lock (Locker) { try { IsBusy = true; MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_GetDevicePropValue, CONST_PROP_LiveViewStatus, -1); ErrorCodes.GetException(response.ErrorCode); // test if live view is on if (response.Data != null && response.Data.Length > 0 && response.Data[0] > 0) { if (CaptureInSdRam) { DeviceReady(); ErrorCodes.GetException(ExecuteWithNoData(CONST_CMD_InitiateCaptureRecInSdram, 0xFFFFFFFF)); return; } StopLiveView(); } // the focus mode can be sett only in host mode LockCamera(); byte oldval = 0; byte[] val = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue, CONST_PROP_AFModeSelect, -1); if (val != null && val.Length > 0) { oldval = val[0]; } SetProperty(CONST_CMD_SetDevicePropValue, new[] { (byte)4 }, CONST_PROP_AFModeSelect, -1); ErrorCodes.GetException(CaptureInSdRam ? ExecuteWithNoData(CONST_CMD_InitiateCaptureRecInSdram, 0xFFFFFFFF) : ExecuteWithNoData(CONST_CMD_InitiateCapture)); if (val != null && val.Length > 0) { SetProperty(CONST_CMD_SetDevicePropValue, new[] { oldval }, CONST_PROP_AFModeSelect, -1); } UnLockCamera(); } catch (Exception) { IsBusy = false; throw; } //if (live != null && live.Length > 0 && live[0] == 1) // StartLiveView(); } }
public override void FormatStorage(object storageId) { MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_GetStorageIDs); if (response.Data.Length > 4) { int objCount = BitConverter.ToInt32(response.Data, 0); for (int i = 0; i < objCount; i++) { uint handle = BitConverter.ToUInt32(response.Data, 4 * i + 4); ErrorCodes.GetException(ExecuteWithNoData(CONST_CMD_FormatStore, handle)); } } }
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, (int)propertyDescriptor.Code, -1); 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); } }
public MTPDataResponse ExecuteReadDataEx(uint code, uint param1, uint param2, uint param3, int loop, int counter) { DeviceIsBusy = true; MTPDataResponse res = new MTPDataResponse(); bool allok; do { allok = true; res = StillImageDevice.ExecuteReadData(code, param1, param2, param3); if ((res.ErrorCode == ErrorCodes.MTP_Device_Busy || res.ErrorCode == PortableDeviceErrorCodes.ERROR_BUSY) && counter < loop) { Thread.Sleep(CONST_READY_TIME); counter++; allok = false; } } while (!allok); DeviceIsBusy = false; return(res); }
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 MTPDataResponse ExecuteReadDataEx(uint code) { int counter = 0; DeviceIsBusy = true; MTPDataResponse res = new MTPDataResponse(); bool allok; do { res = StillImageDevice.ExecuteReadData(code); allok = true; if ((res.ErrorCode == ErrorCodes.MTP_Device_Busy || res.ErrorCode == PortableDeviceErrorCodes.ERROR_BUSY) && counter < CONST_LOOP_TIME) { Thread.Sleep(CONST_READY_TIME); counter++; allok = false; } } while (!allok); DeviceIsBusy = false; return(res); }
public static long GetValue(MTPDataResponse result, int index, int dataLength) { long val = 0; switch (dataLength) { case 1: val = result.Data[index]; break; case 2: val = BitConverter.ToUInt16(result.Data, index); break; case 4: val = BitConverter.ToUInt32(result.Data, index); break; default: val = (long)BitConverter.ToUInt64(result.Data, index); break; } return(val); }
private void getEvent() { try { if (_eventIsbusy) { return; } _eventIsbusy = true; //DeviceReady(); MTPDataResponse response = ExecuteReadDataEx(CONST_CMD_CANON_EOS_GetEvent); if (response.Data == null) { Log.Debug("Get event error :" + response.ErrorCode.ToString("X")); return; } int eventCount = BitConverter.ToInt16(response.Data, 0); Log.Debug("Number of events " + eventCount); if (eventCount > 0) { Console.WriteLine("Event queue length " + eventCount); for (int i = 0; i < eventCount; i++) { try { uint eventCode = BitConverter.ToUInt16(response.Data, 6 * i + 2); ushort eventParam = BitConverter.ToUInt16(response.Data, 6 * i + 4); int longeventParam = BitConverter.ToInt32(response.Data, 6 * i + 4); switch (eventCode) { case CONST_Event_CANON_EOS_PropValueChanged: Log.Debug("EOS property changed " + eventParam.ToString("X")); //ReadDeviceProperties(eventParam); break; case CONST_Event_CANON_EOS_ObjectAddedEx: case CONST_Event_ObjectAddedInSdram: case CONST_Event_ObjectAdded: { try { MTPDataResponse objectdata = ExecuteReadDataEx(CONST_CMD_CANON_EOS_GetObjectInfo, (uint)longeventParam); string filename = "DSC_0000.JPG"; if (objectdata.Data != null) { filename = Encoding.Unicode.GetString(objectdata.Data, 53, 12 * 2); if (filename.Contains("\0")) { filename = filename.Split('\0')[0]; } } else { Log.Error("Error getting file name"); } Log.Debug("File transfer " + filename); PhotoCapturedEventArgs args = new PhotoCapturedEventArgs { WiaImageItem = null, EventArgs = new PortableDeviceEventArgs(new PortableDeviceEventType() { ObjectHandle = (uint)longeventParam }), CameraDevice = this, FileName = filename, Handle = (uint)longeventParam }; OnPhotoCapture(this, args); } catch (Exception exception) { Log.Error("Object added error", exception); } } break; //case CONST_Event_CaptureComplete: //case CONST_Event_CaptureCompleteRecInSdram: // { // OnCaptureCompleted(this, new EventArgs()); // } // break; //case CONST_Event_ObsoleteEvent: // break; default: //Console.WriteLine("Unknown event code " + eventCode.ToString("X")); Log.Debug("Unknown event code :" + eventCode.ToString("X") + "|" + longeventParam.ToString("X")); break; } } catch (Exception exception) { Log.Error("Event queue processing error ", exception); } } } } catch (InvalidComObjectException) { return; } catch (Exception) { //Log.Error("Event exception ", exception); } _eventIsbusy = false; _timer.Start(); }
public void SetValue(MTPDataResponse data, bool notifyValuChange) { _notifyValuChange = notifyValuChange; SetValue(data.Data); _notifyValuChange = true; }
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); } //} }
/// <summary> /// Transfers the file and writes it to the specified stream. /// </summary> /// <param name="o">The object handle.</param> /// <param name="stream">The stream.</param> public override void TransferFile(object o, Stream stream) { // Sanity checks. if (!stream.CanWrite) { throw new ArgumentException("Specified stream is not writable.", "stream"); } int retryes = TransferRetries; lock (Locker) { _timer.Stop(); MTPDataResponse result = new MTPDataResponse(); //=================== managed file write do { try { result = StillImageDevice.ExecuteReadBigData(CONST_CMD_GetObject, (total, current) => { double i = (double)current / total; TransferProgress = Convert.ToUInt32(i * 100); }, Convert.ToUInt32(o)); } // if not enough memory for transfer catch it and wait and try again catch (OutOfMemoryException) { } catch (COMException) { } if (result != null && result.Data != null) { stream.Write(result.Data, 0, result.Data.Length); } else { Log.Error("Transfer error code retrying " + result.ErrorCode.ToString("X")); Thread.Sleep(200); retryes--; } } while (result.Data == null && retryes > 0); //================================================================== //=================== direct file write //StillImageDevice.ExecuteReadBigDataWriteToFile(CONST_CMD_GetObject, // Convert.ToInt32(o), -1, // (total, current) => // { // double i = (double)current / total; // TransferProgress = // Convert.ToUInt32(i * 100); // }, filename); //================================================================== _timer.Start(); TransferProgress = 0; } }
private void LoadDeviceData(MTPDataResponse res) { ErrorCodes.GetException(res.ErrorCode); DeviceInfo.Manufacturer = SelectedDevice.Manufacturer; DeviceInfo.Model = SelectedDevice.Model; 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) }); } MTPDataResponse vendor_res = MTPCamera.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) }); } } }
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); }
/// <summary> /// Transfers the file and writes it to the specified stream. /// </summary> /// <param name="o">The object handle.</param> /// <param name="stream">The stream.</param> public override void TransferFile(object o, Stream stream) { // Sanity checks. if (!stream.CanWrite) { throw new ArgumentException("Specified stream is not writable.", "stream"); } lock (Locker) { string s = o as string; if (s != null) { ((StillImageDevice)StillImageDevice).SaveFile(s, stream); return; } int retryes = TransferRetries; _timer.Stop(); MTPDataResponse result = new MTPDataResponse(); //=================== managed file write do { try { //using (MemoryStream mStream = new MemoryStream()) //{ result = StillImageDevice.ExecuteReadBigData(CONST_CMD_GetObject, stream, (total, current) => { double i = (double)current / total; TransferProgress = Convert.ToUInt32(i * 100); }, Convert.ToUInt32(o)); //if (result != null && result.Data != null) //{ // stream.Write(result.Data, 0, result.Data.Length); //} //stream.Write(mStream.ToArray(), 0, (int)mStream.Length); break; //} } catch (COMException) { Log.Error("Transfer error code retrying " + result.ErrorCode.ToString("X")); Thread.Sleep(200); retryes--; } } while (retryes > 0); //================================================================== //=================== direct file write //StillImageDevice.ExecuteReadBigDataWriteToFile(CONST_CMD_GetObject, // Convert.ToInt32(o), -1, // (total, current) => // { // double i = (double)current / total; // TransferProgress = // Convert.ToUInt32(i * 100); // }, filename); //================================================================== _timer.Start(); TransferProgress = 0; } }