如何在紧凑框架中检测插件 USB
我想连接一个带有串行端口的跟踪盒,并通过串行转 USB 线连接到 Windows Mobile。 当我通过USB连接Windows Mobile设备与跟踪盒时,是否有办法检测USB插件?
I want to attach a tracking box that has a serial port, with a serial to USB lead to a windows mobile. Is there anyway to detect USB plugin when I connect windows mobile device with tracking box through USB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个名为 NOTIFICATION_EVENT_DEVICE_CHANGE 的系统事件
在某些系统更改期间触发。 我不知道连接 USB 设备是否会生成该事件,但这是一个起点。 该事件是通过本机函数 CeRunAppAtEvent 访问的。 不要让它的名字欺骗了您,CeRunAppAtEvent 可用于启动程序并通知正在运行的程序事件。
您问题上的标签表明您正在使用紧凑框架。 由于 CeRunAppAtEvent 是本机函数,您将无法直接访问它。 您将需要执行一些 P/Invoke。 为了加快速度,我将向您推荐另一个资源。
以下代码使用 CeRunAppAtEvent 在某些事件期间启动程序。 我会以此为起点,看看当您连接 USB 设备时是否可以启动程序。
http://www.codeproject.com/KB/mobile/WiMoAutostart.aspx
There is a system event called NOTIFICATION_EVENT_DEVICE_CHANGE
that is triggered during certain system changes. I don't know whether or not connecting your USB device generates that event, but that's a place to start. The event is accessed through the native function CeRunAppAtEvent. Don't let it's name fool you, CeRunAppAtEvent can be used to both start programs and notify running programs of events.
The tag on your question indicates you are using the compact framework. With CeRunAppAtEvent being a native function you won't have direct access to it. You will need to do some P/Invokes. To speed things up I will refer you to another resource.
The following code was using CeRunAppAtEvent to start programs during certain events. I would use this as a starting point to see if you can get a program to start when you connect your USB device.
http://www.codeproject.com/KB/mobile/WiMoAutostart.aspx
调用 RequestDeviceNotifications。 它会就像这篇博客文章一样工作,除了你’ d 寻找通用设备而不是专门针对文件系统。
Call RequestDeviceNotifications. It would work just like this blog post, except you'd look for a generic device instead of specifically for a file system.