/// <summary> /// "getConfig DEVICE-ID fileName" /// </summary> public Hashtable GetConfigObject(String deviceId, String fileName) { Hashtable ret = new Hashtable(); ret["status"] = "FAILED"; Connect(deviceId, () => { MtpResponse res = command.Execute((UInt16)ConfigObject.Get, DataPhase.DataReadPhase, new uint[1] { (uint)ConfigObjectType.Config }); if (res.ResponseCode == WpdMtpLib.MtpResponseCode.OK) { FileStream fs = new FileStream(fileName, FileMode.Create); fs.Write(res.Data, 0, res.Data.Length); fs.Close(); ret["status"] = "OK"; } else { ret["status"] = String.Format("FAILED({0:X4})", (UInt16)res.ResponseCode); } }); return(ret); }
/// <summary> /// "set DEVICE-ID propName value" /// </summary> public Hashtable SetDeviceProp(String deviceId, String propName, String propValue) { Hashtable ret = new Hashtable(); ret["status"] = "FAILED"; DataType type = DataType.UNDEF; MtpDevicePropCode code = KeyToPropCode(propName, ref type); byte[] val = MtpHelperUtils.StringToBytes(propValue, type); Connect(deviceId, () => { MtpResponse res = command.Execute(MtpOperationCode.SetDevicePropValue, new uint[1] { (uint)code }, val); if (res.ResponseCode == WpdMtpLib.MtpResponseCode.OK) { ret["status"] = "OK"; } else { ret["status"] = String.Format("FAILED({0:X4})", (UInt16)res.ResponseCode); } }); return(ret); }
/// <summary> /// "deviceInfo DEVICE-ID" /// </summary> public Hashtable GetDeviceInfo(String deviceId) { Hashtable ret = new Hashtable(); ret["status"] = "FAILED"; Connect(deviceId, () => { MtpResponse res = command.Execute(MtpOperationCode.GetDeviceInfo, null, null); if (res.ResponseCode == WpdMtpLib.MtpResponseCode.OK) { DeviceInfo deviceInfo = new DeviceInfo(res.Data); ret["VenderExtensionId"] = deviceInfo.MtpVenderExtensionID; ret["VenderExtensionVersion"] = deviceInfo.MtpVersion; ret["DeviceVersion"] = deviceInfo.DeviceVersion; ret["SerialNumber"] = deviceInfo.SerialNumber; ret["FunctionalMode"] = deviceInfo.FunctionalMode; ret["Manufacturer"] = deviceInfo.Manufacturer; ret["Model"] = deviceInfo.Model; ret["StandardVersion"] = deviceInfo.StandardVersion; ret["status"] = "OK"; } else { ret["status"] = String.Format("FAILED({0:X4})", (UInt16)res.ResponseCode); } }); return(ret); }
/// <summary> /// レリーズ押下 /// </summary> /// <returns></returns> public bool Release() { if (IsConnected) { StillCaptureMode mode = CaptureMode; if (mode == StillCaptureMode.Single) { mtp.Execute(MtpOperationCode.InitiateCapture, new uint[2] { 0, 0 }, null); } else { MtpResponse res = mtp.Execute(MtpOperationCode.GetDevicePropValue, new uint[1] { (uint)MtpDevicePropCode.CaptureStatus }, null); ushort status = BitConverter.ToUInt16(res.Data, 0); if (status == 0x00) { // 待機中 mtp.Execute(MtpOperationCode.InitiateOpenCapture, new uint[2] { 0, 0 }, null); } else { // 撮影中 mtp.Execute(MtpOperationCode.TerminateOpenCapture, new uint[1] { 0xFFFFFFFF }, null); } } } return(true); }
public override MtpResponse Execute(MtpOperationCode code, uint[] param, byte[] data = null) { switch (code) { case MtpOperationCode.GetDeviceInfo: byte[] gdiRes = { 100, 0, 6, 0, 0, 0, 110, 0, 0, 1, 128, 26, 0, 0, 0, 1, 16, 2, 16, 3, 16, 4, 16, 5, 16, 6, 16, 7, 16, 8, 16, 9, 16, 10, 16, 11, 16, 20, 16, 21, 16, 27, 16, 1, 144, 145, 153, 153, 153, 154, 153, 155, 153, 156, 153, 157, 153, 14, 16, 22, 16, 28, 16, 24, 16, 162, 153, 6, 0, 0, 0, 2, 64, 6, 64, 8, 64, 10, 64, 12, 64, 13, 64, 34, 0, 0, 0, 1, 80, 2, 80, 3, 80, 17, 80, 18, 80, 7, 212, 5, 80, 14, 80, 15, 80, 16, 80, 19, 80, 26, 80, 27, 80, 44, 80, 6, 208, 15, 208, 1, 216, 2, 216, 3, 216, 5, 216, 6, 216, 7, 216, 8, 216, 9, 216, 10, 216, 11, 216, 12, 216, 13, 216, 14, 216, 15, 216, 16, 216, 17, 216, 18, 216, 19, 216, 0, 0, 0, 0, 4, 0, 0, 0, 1, 48, 1, 56, 2, 184, 130, 185, 20, 82, 0, 105, 0, 99, 0, 111, 0, 104, 0, 32, 0, 67, 0, 111, 0, 109, 0, 112, 0, 97, 0, 110, 0, 121, 0, 44, 0, 32, 0, 76, 0, 116, 0, 100, 0, 46, 0, 0, 0, 14, 82, 0, 73, 0, 67, 0, 79, 0, 72, 0, 32, 0, 84, 0, 72, 0, 69, 0, 84, 0, 65, 0, 32, 0, 83, 0, 0, 0, 6, 48, 0, 49, 0, 46, 0, 56, 0, 50, 0, 0, 0, 9, 48, 0, 48, 0, 48, 0, 48, 0, 49, 0, 50, 0, 50, 0, 51, 0, 0, 0 }; return(new MtpResponse((ushort)MtpResponseCode.OK, null, gdiRes)); case MtpOperationCode.GetDevicePropDesc: return(ExecuteGetDevicePropDesc(param, data)); case MtpOperationCode.GetDevicePropValue: return(ExecuteGetDevicePropValue(param, data)); case MtpOperationCode.GetStorageIDs: byte[] gsidRes = { 1, 0, 0, 0, 1, 0, 1, 0 }; return(new MtpResponse((ushort)MtpResponseCode.OK, null, gsidRes)); case MtpOperationCode.GetStorageInfo: byte[] gsiRes = { 3, 0, 3, 0, 0, 0, 0, 0, 112, 224, 1, 0, 0, 0, 0, 148, 240, 35, 1, 0, 0, 0, 215, 3, 0, 0, 0, 0 }; return(new MtpResponse((ushort)MtpResponseCode.OK, null, gsiRes)); case MtpOperationCode.GetNumObjects: uint[] num = { 11 }; return(new MtpResponse((ushort)MtpResponseCode.OK, num, null)); case MtpOperationCode.GetObjectHandles: byte[] gohRes = { 11, 0, 0, 0, 0, 0, 0, 128, 0, 0, 100, 0, 2, 3, 100, 0, 3, 3, 100, 0, 4, 3, 100, 0, 5, 3, 100, 0, 45, 3, 100, 0, 46, 3, 100, 0, 47, 3, 100, 0, 48, 3, 100, 0, 49, 3, 100, 0 }; return(new MtpResponse((ushort)MtpResponseCode.OK, null, gohRes)); case MtpOperationCode.GetObjectInfo: byte[] goiRes = { 1, 0, 1, 0, 1, 56, 0, 0, 113, 221, 57, 0, 8, 56, 108, 13, 0, 0, 160, 0, 0, 0, 120, 0, 0, 0, 0, 21, 0, 0, 128, 10, 0, 0, 8, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 82, 0, 48, 0, 48, 0, 49, 0, 48, 0, 55, 0, 55, 0, 48, 0, 46, 0, 74, 0, 80, 0, 71, 0, 0, 0, 16, 50, 0, 48, 0, 49, 0, 54, 0, 49, 0, 50, 0, 49, 0, 53, 0, 84, 0, 49, 0, 49, 0, 48, 0, 55, 0, 53, 0, 51, 0, 0, 0, 16, 50, 0, 48, 0, 49, 0, 54, 0, 49, 0, 50, 0, 49, 0, 53, 0, 84, 0, 49, 0, 49, 0, 48, 0, 55, 0, 53, 0, 51, 0, 0, 0, 1, 0, 0 }; return(new MtpResponse((ushort)MtpResponseCode.OK, null, goiRes)); case MtpOperationCode.GetObject: MtpResponse res; var assm = Assembly.GetExecutingAssembly(); using (var stream = assm.GetManifestResourceStream("WpdMtpLib.Stub.dummy.JPG")) { byte[] goRes = new byte[stream.Length]; stream.Read(goRes, 0, goRes.Length); res = new MtpResponse((ushort)MtpResponseCode.OK, null, goRes); } return(res); case MtpOperationCode.InitiateCapture: Task.Factory.StartNew(() => { Thread.Sleep(1000); Object objectId = (uint)6554430; MtpEvent(WpdMtpLib.MtpEvent.ObjectAdded, objectId); Thread.Sleep(500); MtpEvent(WpdMtpLib.MtpEvent.CaptureComplete, null); }); return(new MtpResponse((ushort)MtpResponseCode.OK, null, null)); case MtpOperationCode.SetDevicePropValue: default: return(new MtpResponse((ushort)MtpResponseCode.OK, null, null)); } }
/// <summary> /// "desc DEVICE-ID propName" /// </summary> public Hashtable GetDevicePropDesc(String deviceId, String propName) { Hashtable ret = new Hashtable(); ret["status"] = "FAILED"; DataType type = DataType.UNDEF; MtpDevicePropCode code = KeyToPropCode(propName, ref type); Connect(deviceId, () => { MtpResponse res = command.Execute(MtpOperationCode.GetDevicePropDesc, new uint[1] { (uint)code }, null); if (res.ResponseCode == WpdMtpLib.MtpResponseCode.OK) { DevicePropDesc dpd = new DevicePropDesc(res.Data); ret["current"] = dpd.CurrentValue; ret["factory_default_value"] = dpd.FactoryDefaultValue; ret["get_set"] = dpd.GetSet; if (dpd.FormFlag == 0x01) { // 範囲 ret["min"] = dpd.Form[0]; ret["max"] = dpd.Form[1]; ret["step"] = dpd.Form[2]; } else if (dpd.FormFlag == 0x02) { // 配列 ret["values"] = dpd.Form; } else { ret["values"] = null; } ret["status"] = "OK"; } else { ret["status"] = String.Format("FAILED({0:X4})", (UInt16)res.ResponseCode); } }); return(ret); }
public Hashtable SendConfigObject(String deviceId, String fileName, bool isFirmware) { Hashtable ret = new Hashtable(); ret["status"] = "FAILED"; ConfigObjectType configType = isFirmware ? ConfigObjectType.Firmware : ConfigObjectType.Config; UInt32 version = 0; if (isFirmware && !checkFileName(fileName, ref version)) { ret["status"] = "Invalid file name"; return(ret); } FileStream fs = new FileStream(fileName, FileMode.Open); byte[] data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length); uint dataLength = (uint)fs.Length; fs.Close(); if (dataLength == 0) { ret["status"] = "Invalid file content"; return(ret); } Connect(deviceId, () => { MtpResponse res = command.Execute((UInt16)ConfigObject.Send, DataPhase.DataWritePhase, new uint[3] { (uint)configType, dataLength, version }, data); if (res.ResponseCode == WpdMtpLib.MtpResponseCode.OK) { ret["status"] = "OK"; } else { ret["status"] = String.Format("FAILED({0:X4})", (UInt16)res.ResponseCode); } }); return(ret); }