internal unsafe bool GetInfo()
{
IntPtr udev = NativeMethods.udev_new();
if (IntPtr.Zero != udev)
{
try
{
IntPtr device = NativeMethods.udev_device_new_from_syspath(udev, _path);
if (device != IntPtr.Zero)
{
try
{
IntPtr parent = NativeMethods.udev_device_get_parent_with_subsystem_devtype(device, "usb", "usb_device");
if (IntPtr.Zero != parent)
{
string manufacturer = NativeMethods.udev_device_get_sysattr_value(parent, "manufacturer") ?? "";
string productName = NativeMethods.udev_device_get_sysattr_value(parent, "product") ?? "";
string serialNumber = NativeMethods.udev_device_get_sysattr_value(parent, "serial") ?? "";
string idVendor = NativeMethods.udev_device_get_sysattr_value(parent, "idVendor");
string idProduct = NativeMethods.udev_device_get_sysattr_value(parent, "idProduct");
string version = NativeMethods.udev_device_get_sysattr_value(parent, "version");
int vid, pid, verMajor, verMinor;
if (NativeMethods.TryParseHex(idVendor, out vid) &&
NativeMethods.TryParseHex(idProduct, out pid) &&
NativeMethods.TryParseVersion(version, out verMajor, out verMinor))
{
_vid = vid;
_pid = pid;
_version = verMajor << 8 | verMinor;
_manufacturer = manufacturer;
_productName = productName;
_serialNumber = serialNumber;
ReportDescriptors.Parser.ReportDescriptorParser parser;
if (TryParseReportDescriptor(device, out parser, out _reportDescriptor))
{
// Follow the Windows convention: No Report ID? Report ID is 0.
// So, it's always one byte above the parser's result.
_maxInput = parser.InputReportMaxLength; if (_maxInput > 0) { _maxInput++; }
_maxOutput = parser.OutputReportMaxLength; if (_maxOutput > 0) { _maxOutput++; }
_maxFeature = parser.FeatureReportMaxLength; if (_maxFeature > 0) { _maxFeature++; }
_reportsUseID = parser.ReportsUseID;
return true;
}
}
}
}
finally
{
NativeMethods.udev_device_unref(device);
}
}
}
finally
{
NativeMethods.udev_unref(udev);
}
}
return false;
}