USB端口的DataRecevied事件 [英] DataRecevied Event for USB Port

查看:152
本文介绍了USB端口的DataRecevied事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Bulk USB驱动程序(来自MS WinDDK的示例).我们在Win32中开发了应用程序软件,该软件通过USB端口(PC端的USB主机和硬件端的USB设备)与我们的设备进行通讯.在应用程序软件中,我们使用CreateFile,WriteFile和ReadFile API与USB设备通信.现在,我们正在调用ReadFile函数以从USB端口接收数据,但是现在我们想在事件发生时接收数据(而不是强制调用ReadFile).在串行通信中,有EV_RXCHAR事件,当端口上的数据可用时,该事件会生成事件.在C#串行类中,"DataReceived"事件用于此目的.但是对于USB,我找不到用于接收事件数据的任何合适的方法/体系结构.

请提出一些解决方案.

I am using Bulk USB driver (sample from MS WinDDK). We have application software developed in Win32 which communicates our device through USB port (USB host at PC side and USB device at hardware side). In Application software, we are using CreateFile, WriteFile and ReadFile API to communicate with USB device. Right now we are calling ReadFile function to receive data from USB port But now we want to receive data on event (not forcefully calling ReadFile). In Serial Communication there is EV_RXCHAR event which generates event when data is available on port. In C# Serial class, ''DataReceived'' event is used for this purpose. But For USB, i could not find any suitable method/architecture which is used to receive data on event.

Please kindly suggest some solution.

推荐答案

您正在谈论的是异步数据处理.

要实现此目的,您需要在异步(OVERLAPPED)模式下使用ReadFile.

1.创建一个事件.
2.创建一个包含此事件的句柄的OVERLAPPED结构
3.将此传递给您的ReadFile函数
4.在单独的线程中等待事件句柄.通知事件后,处理已到达的数据.
5.使用GetOverlappedResult()找出已到达多少字节. http://msdn.microsoft.com/zh-CN /library/windows/desktop/ms683209(v=vs.85).aspx [ http://msdn.microsoft.com/zh-CN /library/windows/desktop/aa365683(v=vs.85).aspx [
What you are talking about is asynchronous data processing.

To implement this you need to use ReadFile in asynchronous (OVERLAPPED) mode.

1. Create an event.
2. Create an OVERLAPPED structure containing a handle to this event
3. Pass this to your ReadFile function
4. In a separate thread wait on the event handle. When the event is signaled process the data that has arrived.
5. Use GetOverlappedResult() to find out how many bytes have arrived. http://msdn.microsoft.com/en-us/library/windows/desktop/ms683209(v=vs.85).aspx[^]



This may be helpful
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365683(v=vs.85).aspx[^]


这篇关于USB端口的DataRecevied事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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