![](/img/trans.png)
[英]C# UWP Windows 10 Inter Process Communication with MemoryMappedFiles missing
[英]Windows 10: HID Communication in C#
我试图在Windows 10上使用C#通过Arduino Leonardo通过USB HID建立通信。我已经能够枚举和检索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发送消息的设置间隔触发,这使我相信这是正确的数据包/消息/数据。 一个问题是,尽管我已验证正在发送实际的非零消息,但该数据始终为空。
我终于弄清楚了这一点,并且有一些怪癖。 我设法使它起作用的方法就是上面的方法,但是我的数据并没有达到我最初的预期。 找到我的设备后,我附加了一个InputReceived事件,它看起来像这样:
private void ControlDevice_InputReportReceived(HidDevice sender, HidInputReportReceivedEventArgs args)
{
HidInputReport inputReport = args.Report;
IBuffer buffer = inputReport.Data;
DataReader dr = DataReader.FromBuffer(buffer);
byte[] bytes = new byte[inputReport.Data.Length];
dr.ReadBytes(bytes);
String receivedMessage = System.Text.Encoding.ASCII.GetString(bytes);
handleRead_HID(receivedMessage);
}
这应该使您从设备获得一条人类可读的字符串消息。
截至2015年9月22日的另外一点是,将通用应用程序部署到商店后,您的appxmanifest文件将覆盖其内容,这意味着您部署的应用程序将无法访问您的设备。 我已经报告了该错误,Microsoft已确认该错误,并且应该在Visual Studio 2015的下一个更新中予以修复。
编辑:优质视频深入细节-https: //channel9.msdn.com/Events/Build/2013/2-924b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.