本文整理汇总了C#中IDevice.ResolveUsbPortInfo方法的典型用法代码示例。如果您正苦于以下问题:C# IDevice.ResolveUsbPortInfo方法的具体用法?C# IDevice.ResolveUsbPortInfo怎么用?C# IDevice.ResolveUsbPortInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDevice
的用法示例。
在下文中一共展示了IDevice.ResolveUsbPortInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeviceInitialize
public override void DeviceInitialize (IDevice device)
{
base.DeviceInitialize (device);
var portInfo = device.ResolveUsbPortInfo ();
if (portInfo == null || portInfo.DeviceNumber == 0) {
throw new InvalidDeviceException ();
}
//int busnum = portInfo.BusNumber;
int devnum = portInfo.DeviceNumber;
List<RawMtpDevice> devices = null;
try {
devices = MtpDevice.Detect ();
} catch (TypeInitializationException e) {
Log.Exception (e);
Log.Error (
Catalog.GetString ("Error Initializing MTP Device Support"),
Catalog.GetString ("There was an error initializing MTP device support."), true
);
throw new InvalidDeviceException ();
} catch (Exception e) {
Log.Exception (e);
//ShowGeneralExceptionDialog (e);
throw new InvalidDeviceException ();
}
IVolume volume = device as IVolume;
foreach (var v in devices) {
// Using the HAL hardware backend, HAL says the busnum is 2, but libmtp says it's 0, so disabling that check
//if (v.BusNumber == busnum && v.DeviceNumber == devnum) {
if (v.DeviceNumber == devnum) {
// If gvfs-gphoto has it mounted, unmount it
if (volume != null && volume.IsMounted) {
volume.Unmount ();
}
for (int i = 5; i > 0 && mtp_device == null; i--) {
try {
mtp_device = MtpDevice.Connect (v);
} catch (Exception) {}
if (mtp_device == null) {
Log.DebugFormat ("Failed to connect to mtp device. Trying {0} more times...", i - 1);
Thread.Sleep (2000);
}
}
}
}
if (mtp_device == null) {
throw new InvalidDeviceException ();
}
// libmtp sometimes returns '?????'. I assume this is if the device does
// not supply a friendly name. In this case show the model name.
if (string.IsNullOrEmpty (mtp_device.Name) || mtp_device.Name == "?????")
Name = mtp_device.ModelName;
else
Name = mtp_device.Name;
Initialize ();
List<string> mimetypes = new List<string> ();
foreach (FileType format in mtp_device.GetFileTypes ()) {
if (format == FileType.JPEG) {
supports_jpegs = true;
} else {
string mimetype = MtpDevice.GetMimeTypeFor (format);
if (mimetype != null) {
mimetypes.Add (mimetype);
}
}
}
AcceptableMimeTypes = mimetypes.ToArray ();
AddDapProperty (Catalog.GetString ("Serial number"), mtp_device.SerialNumber);
AddDapProperty (Catalog.GetString ("Version"), mtp_device.Version);
try {
AddDapProperty (Catalog.GetString ("Battery level"), String.Format ("{0:0%}", mtp_device.BatteryLevel/100.0));
} catch (Exception e) {
Log.Exception ("Unable to get battery level from MTP device", e);
}
}