我最近为 Windows 实现了 USB 控制传输。它运作良好。我的框架 Device.Net 也支持 Android 和 UWP,所以我映射了 Android 和 UWP 的 API。这是 UWP 的 docs。此 integration test 向 STM DFU 固件模式 MCU 板发送控制传输。 UWP 的相同集成测试失败。问题是它只是给出了一个非描述性的错误。
这是code。
private static async Task<TransferResult> PerformControlTransferAsync(windowsUsbDevice ConnectedDevice, SetupPacket setupPacket, byte[] buffer, CancellationToken cancellationToken = default)
{
var uwpSetupPacket = new usbSetupPacket
{
Index = setupPacket.Index,
Length = setupPacket.Length,
Request = setupPacket.Request,
RequestType = new usbControlRequestType
{
ControlTransferType = setupPacket.RequestType.Type switch
{
RequestType.Standard => usbControlTransferType.Standard,
RequestType.Class => usbControlTransferType.Class,
RequestType.Vendor => usbControlTransferType.Vendor,
_ => throw new NotImplementedException()
}
},
Value = setupPacket.Value
};
if (setupPacket.RequestType.Direction == RequestDirection.In)
{
//Read
var readBuffer = await ConnectedDevice.SendControlInTransferAsync(uwpSetupPacket);
return new TransferResult(readBuffer.ToArray(), readBuffer.Length);
}
else
{
//Write
var bytesWritten = await ConnectedDevice.SendControlOutTransferAsync(uwpSetupPacket);
return new TransferResult(buffer, bytesWritten);
}
}
我得到的错误是这样的:
<块引用>调用 COM 组件时返回了错误 HRESULT E_FAIL
任何可以帮助我的东西都会有所帮助。