C#中的USB HID编程 [英] USB HID Programming in C#

查看:879
本文介绍了C#中的USB HID编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,

Hello Everyone,

我们的设备符合USB HID类规范,该规范还有五个端点可与主机交换数据。

We are having a device which complies with USB HID class specification, which also has five endpoints to exchange datas with host.

坦率地说,我们正在使用florian C#hid lib来构建主机应用程序。

http://www.florian-leitner.de/index.php/2007/08/03/hid-usb-driver-library/
功能我们在枚举和设备连接方面取得了成功,但通信中发生了数据丢失。

To be frank, we are using florian C# hid lib for building the host application. http://www.florian-leitner.de/index.php/2007/08/03/hid-usb-driver-library/.  We are successful in enumeration and device connection but data loss is happening in the communication.

让我向您解释一下这个场景,设备的编程方式是它必须发送数据包长度为64字节,数据包的第一个字节包含有关包号[0-255]的信息,其余63个字节用于通信
有效载荷。设备执行在数据包中添加数据包编号并以串行方式将其存储到端点的过程。

Let me explain you the scenario, device is programmed in such a way that it has to send the data packets of length 64 in bytes and the 1st byte of data packet contains information about the packet number[0-255] and the rest 63 bytes used for communication payload. The device does the process of adding the packet number in the data packet and store them in to endpoints in serial fashion.

现在必须在主机端读取相同的信息。我们正在调用kerner32.dll的Readfile API,以便从设备中收集数据。这就是挑战。当设备连接到PC时,它开始将数据
数据包发送到PC。因此,当我们调用Readfile API时,会出现数据包混乱。

Now the same information has to be read in the host side. We are calling the Readfile API of kerner32.dll inorder to collect the data from the device. Here comes the challenges. The moment device connected to the PC it starts transmitting the data packets to the PC. So, when we call the Readfile API there comes the packet shuffling.

让我们说,我们正在读取Endpoint0 [EP0],数据包编号可能是160,下一次是从EP1读取,数据包编号为161,EP2的数据为162,EP3的数据包数为163,但EP4的读数让我们感到惊讶。
它读取第174个数据包。

Lets say we are reading from the Endpoint0 [EP0], the packet number may be 160 and next reading from EP1, the packet number was 161, from EP2 the paket number was 162, from EP3 the packet number was 163 but the EP4th reading gave us surprise. It read 174th packet.

它像160,161,162,163, 174 ,下一个序列可以是165,166,167,168 ,179

Its like 160,161,162,163,174 and next sequence can be 165,166,167,168,179.

但是相同的代码没有修改,顺序读取。像0,1,2,3,4和下一个序列是5,6,7,8,9。

But the same code without modification, reads sequentialy. Like 0,1,2,3,4 and next sequence was 5,6,7,8,9.

任何人都可以告诉我们为什么这种不确定性和可能是近似的根本原因没有按顺序读取数据包号码?

Can anyone tell us why this uncertainty and what could be approximate root cause for not getting read the packet number sequentialy?

谢谢和问候,

Yashath

推荐答案


但是相同的代码没有修改,读取顺序。像0,1,2,3,4和下一个序列是5,6,7,8,9。

But the same code without modification, reads sequentialy. Like 0,1,2,3,4 and next sequence was 5,6,7,8,9.

 


"修改"是什么意思?您在代码中修改了什么?

What does it mean 'modification' ?? What did you modify in code ?


这篇关于C#中的USB HID编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆