本文整理汇总了C#中LibUsbDotNet.UsbDevice.GetDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C# UsbDevice.GetDescriptor方法的具体用法?C# UsbDevice.GetDescriptor怎么用?C# UsbDevice.GetDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LibUsbDotNet.UsbDevice
的用法示例。
在下文中一共展示了UsbDevice.GetDescriptor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDeviceConfigs
internal static List<UsbConfigInfo> GetDeviceConfigs(UsbDevice usbDevice)
{
List<UsbConfigInfo> rtnConfigs = new List<UsbConfigInfo>();
byte[] cfgBuffer = new byte[UsbConstants.MAX_CONFIG_SIZE];
int iConfigs = usbDevice.Info.Descriptor.ConfigurationCount;
for (int iConfig = 0; iConfig < iConfigs; iConfig++)
{
int iBytesTransmitted;
bool bSuccess = usbDevice.GetDescriptor((byte) DescriptorType.Configuration, 0, 0, cfgBuffer, cfgBuffer.Length, out iBytesTransmitted);
if (bSuccess)
{
if (iBytesTransmitted >= UsbConfigDescriptor.Size && cfgBuffer[1] == (byte) DescriptorType.Configuration)
{
UsbConfigDescriptor configDescriptor = new UsbConfigDescriptor();
Helper.BytesToObject(cfgBuffer, 0, Math.Min(UsbConfigDescriptor.Size, cfgBuffer[0]), configDescriptor);
if (configDescriptor.TotalLength == iBytesTransmitted)
{
List<byte[]> rawDescriptorList = new List<byte[]>();
int iRawLengthPosition = configDescriptor.Length;
while (iRawLengthPosition < configDescriptor.TotalLength)
{
byte[] rawDescriptor = new byte[cfgBuffer[iRawLengthPosition]];
if (iRawLengthPosition + rawDescriptor.Length > iBytesTransmitted)
throw new UsbException(usbDevice, "Descriptor length is out of range.");
Array.Copy(cfgBuffer, iRawLengthPosition, rawDescriptor, 0, rawDescriptor.Length);
rawDescriptorList.Add(rawDescriptor);
iRawLengthPosition += rawDescriptor.Length;
}
rtnConfigs.Add(new UsbConfigInfo(usbDevice, configDescriptor, ref rawDescriptorList));
}
else
UsbError.Error(ErrorCode.InvalidConfig,
0,
"GetDeviceConfigs: USB config descriptor length doesn't match the length received.",
usbDevice);
}
else
UsbError.Error(ErrorCode.InvalidConfig, 0, "GetDeviceConfigs: USB config descriptor is invalid.", usbDevice);
}
else
UsbError.Error(ErrorCode.InvalidConfig, 0, "GetDeviceConfigs", usbDevice);
}
return rtnConfigs;
}