【发布时间】:2015-08-25 17:54:54
【问题描述】:
我正在尝试在 Windows 10 上使用 C# 通过 USB HID 与 Arduino Leonardo 建立通信。我已经能够枚举和检索 HidDevice 对象,但我无法接收任何数据。
Package.appxmanifest:
<DeviceCapability Name="humaninterfacedevice">
<Device Id="vidpid:16C0 0486">
<Function Type="usage:FFAB 0200"/>
</Device>
</DeviceCapability>
MainPage.xaml.cs
HidInputReport testReport = await device.GetInputReportAsync();
DataReader dataReader = DataReader.FromBuffer(testReport.Data);
byte[] fileContent = new byte[dataReader.UnconsumedBufferLength];
dataReader.ReadBytes(fileContent);
textBlock.Text += System.Text.Encoding.UTF8.GetString(fileContent);
这种阅读方法也是 MSDN 文章使用的方法,但它并没有为我提供任何结果。如果有人了解我可以做些什么不同或做错了什么,将不胜感激!
编辑: 只需在此处添加更多信息,我已经设置了一个事件以在接收到 InputReport 时触发,并且该事件以我从 Arduino 发送消息的设定间隔触发,从而导致我相信这是正确的数据包/消息/数据。一个问题是这个数据总是空的,尽管我已经验证了一个实际的非零消息正在发送。
【问题讨论】:
标签: c# arduino usb win-universal-app hid