【发布时间】:2020-07-28 15:06:41
【问题描述】:
我想通过 hid 向设备发送输出报告。
var device = await HidDevice.FromIdAsync(deviceDescriptor.Id, Windows.Storage.FileAccessMode.ReadWrite);
HidOutputReport outReport = device.CreateOutputReport();
byte[] buffer = new byte[] { 10, 20, 30, 40 };
DataWriter dataWriter = new DataWriter();
dataWriter.WriteBytes(buffer);
outReport.Data = dataWriter.DetachBuffer();
但它异常失败。
Message:
System.ArgumentException : Value does not fall within the expected range.
Stack Trace:
HidOutputReport.put_Data(IBuffer value)
它有什么问题?代码是从文档中的示例复制而来的。
如果新的缓冲区长度与旧的 outReport.Data.Length 匹配,那么我在
处遇到异常await device.SendOutputReportAsync(outReport);
// System.ArgumentException: 'Value does not fall within the expected range.'
StackTrace:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MyMethod()
我正在尝试在 xunit 测试中运行此方法。
【问题讨论】:
-
{ 10, 20, 30, 40 } 对设备意味着什么?注意不要盲目复制示例代码。
-
@HansPassant 我的设备接受一切。