简体   繁体   English

USB端口的Windows窗体应用程序

[英]Windows form application for USB port

Previously I have work with Windows Form application to establish some RS232 connection. 以前,我使用Windows Form应用程序来建立一些RS232连接。 I used the already provided serial port component (SerialPort), and I was able to establish RS232 communication relatively easy. 我使用了已经提供的串行端口组件(SerialPort),并且能够相对容易地建立RS232通信。

Now, I was wondering if there will be something similar in Winodows Form application to establish a USB communication ? 现在,我想知道Winodows Form应用程序中是否会有类似的东西来建立USB通信?

It seems there is this WinUSB API that provides a very low level interfacing with the device. 似乎有此WinUSB API提供了与设备的非常低级别的接口。 However, I am not sure how easy will that be? 但是,我不确定那有多容易? Also, not sure how easy will it be to integrate into Windows Form application ?! 另外,不确定将其集成到Windows Form应用程序中会多么容易吗?

Will there be a simpler version of such USB interface API? 这样的USB接口API是否会有更简单的版本?

I don't have to stick to Visual Studio. 我不必坚持使用Visual Studio。 Is there other c++ USB API, besides WinUSB, that is more standard that people use? 除了WinUSB以外,还有其他c ++ USB API是人们使用的更标准的吗? I would like to develop a GUI API that does some communication over USB. 我想开发一个GUI API,它通过USB进行一些通信。 If need be, I can use Python or some other tools if it facilitates the process? 如果需要,我可以使用Python或其他一些工具来简化此过程吗?

Thanks in advance. 提前致谢。

Although USB is a serial protocol, you can't treat USB like a serial port: 尽管USB是串行协议,但是您不能将USB视为串行端口:

It's dependant on what the actual device is. 这取决于实际设备是什么。 For example a mobile phone, may provide several "endpoints" for USB, one being a serial port to use the phone as a modem, one as a storage device allowing you to transfer photos and music files to/from the phones storage, and as a camera device that you can take photos with. 例如,一部手机可能会为USB提供多个“端点”,一个是将手机用作调制解调器的串行端口,一个是允许您将照片和音乐文件传输到手机存储或从手机存储传输的存储设备,以及您可以用来拍照的相机设备。 All of these have different behaviour and need a USB driver-plugin to make it behave correctly - these are typically shipped with Windows, and your phone will appear as COM5:, the E: or "Samsung Galaxy S3 Mini" drives and as a camera under the "cameras and scanners". 所有这些都具有不同的行为,并且需要USB驱动程序插件才能使其正常运行-这些通常随Windows一起提供,并且您的手机将显示为COM5:,E:或“三星Galaxy S3 Mini”驱动器以及相机在“相机和扫描仪”下。

Of course, you can programmatically open all these devices, but it is done as the device-type that they present as on the inside of windows (so you use serial port functions or file functions or camera functions). 当然,您可以通过编程方式打开所有这些设备,但是可以按照它们在窗口内部显示的设备类型来完成(因此您可以使用串行端口功能,文件功能或摄像头功能)。

You CAN also write a device driver for a device, if you have sufficient details of how it works. 如果您有足够的运行方式详细信息,您还可以为该设备编写设备驱动程序。

But there's no real way to "open the port". 但是没有“打开端口”的真正方法。 The USB API is a driver API, not a user-mode API. USB API是驱动程序API,而不是用户模式API。 Here's a page to start from to understand USB drivers: http://msdn.microsoft.com/en-gb/library/windows/hardware/ff540215%28v=vs.85%29.aspx 这是开始了解USB驱动程序的页面: http : //msdn.microsoft.com/zh-cn/library/windows/hardware/ff540215%28v=vs.85%29.aspx

There is a WinUSB driver, which allows a single application to access a single device, assuming you know how to operate that device. 有一个WinUSB驱动程序,假设您知道如何操作该设备,该驱动程序允许单个应用程序访问单个设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM