none
UWP CreateOutputReport创建report ID失败 RRS feed

  • Soru

  • //HIDConfigura.cs namespace HIDGamepade { class HIDConfigura { public class Xbox360//360xbox { public class Device { public const UInt16 Vid = 0x045E; public const UInt16 Pid = 0x028E; public const UInt16 UsagePage = 0x01; public const UInt16 UsageId = 0x05; } } //Package.appxmanifest <Capabilities> <DeviceCapability Name="humaninterfacedevice"> <!--xbox one device--> <Device Id="vidpid:045E 028E"> <Function Type="usage:0001 0005" /> </Device> <Device Id="vidpid:054C 0268"> <Function Type="usage:0001 0004" /> </Device> </DeviceCapability> </Capabilities> //HIDDevice.cs public async Task<Boolean> OpenDevice() { Boolean connectdevice = await ConnectDevice(); //打开手柄设备是否成功 Boolean OpenSuccess = false; if (connectdevice) { //打开 deviceId 参数标识的设备句柄。 访问类型由 accessMode 参数指定 hiddevice = await HidDevice.FromIdAsync(device.Id, Windows.Storage.FileAccessMode.ReadWrite); //var controlDataList = hiddevice.GetNumericControlDescriptions(HidReportType.Feature,0,usageId) if (hiddevice != null) { OpenSuccess = true; //打开手柄设备成功 return OpenSuccess; } } //没有找到设备 return OpenSuccess; }

    public async Task WriteByte(Byte[] buffers)
            {
                if (hiddevice != null)
                {
                    //创建主机发送到设备的唯一输出报表
                    //var outputReport = hidDevice.CreateOutputReport(HIDConfigura.Xbox360.ReadWriteBufferControlInformation.ReportId);
                    var outputReport = hiddevice.CreateOutputReport(0);
                    //以多少bit发送一次
                    //Byte dataByte = (byte)(buffer << 64);
                    //实例化写入设备
                    var dataWrite = new DataWriter();
                    //第一个字节始终是报告id
                    dataWrite.WriteByte((Byte)outputReport.Id);
                    for (int i = 0; i < 1024; i++)
                    {
                        dataWrite.WriteByte(buffers[i]);
                    }
                    //分离与数据编译器关联的缓冲区,返回分离的缓冲区
                    outputReport.Data = dataWrite.DetachBuffer();
                    //主机向设备异步发送一个输出报告
                    uint bytesWritten = await hiddevice.SendOutputReportAsync(outputReport);
                }
            }

    在下面这一行是出现错误,System.Exception:“数据无效。 The specified report type is not present,这是因为什么呢?

    var outputReport = hiddevice.CreateOutputReport(0);

    12 Ocak 2023 Perşembe 09:35