UWP 上的 USB 控制传输

问题描述

我最近为 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

任何可以帮助我的东西都会有所帮助。

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)