简体   繁体   English

如何在Windows,Linux,OS X上打开和写入/读取USB CDC“串行”设备?

[英]How to open and write/read to a USB CDC “serial” device on Windows, Linux, OS X?

I've got an Atmel AVR A90USBxxxx device that I have configured to "talk USB" via CDC. 我有一个Atmel AVR A90USBxxxx设备,该设备已配置为通过CDC“通话USB”。 It's designed to take input from a Host computer, running Windows, Linux, or OS X. 它旨在从运行Windows,Linux或OS X的主机上获取输入。

I'm under the impression that Linux and OS X will immediately recognize this CDC device, and with a simple .inf a Windows machine can be told my VID/PID should be opened as a CDC device using usbser.sys. 我的印象是Linux和OS X会立即识别此CDC设备,并通过简单的.inf可以告诉Windows计算机使用usbser.sys作为CDC设备打开我的VID / PID。

My question is once the OS has opened this USB device as a serial device, how can I programmatically read and write to that port (for each of the 3 OS's listed but most detail is needed for Windows as I'm completely unfamiliar there) 我的问题是,一旦操作系统将此USB设备作为串行设备打开,我如何以编程方式读取和写入该端口(对于列出的3个操作系统中的每一个,但Windows仍需要最详细的信息,因为我对此并不完全了解)

Thanks 谢谢

The answer really depends on what programming language you intend to use. 答案实际上取决于您打算使用哪种编程语言。 Without knowing what language you intend to use, I can't tell you exactly how to do it, but I can point you in the right direction. 在不知道您打算使用哪种语言的情况下,我无法确切告诉您如何使用它,但是我可以为您指明正确的方向。

For prototyping, I recommend using Python with the PySerial module. 对于原型,我建议将PythonPySerial模块一起使用。 It's very easy to set up and quickly write a functional prototype. 设置并快速编写功能原型非常容易。 Python will run on Windows, Linux, and OS X. That way you only need to write the serial communication code once and you can test on all of your platforms. Python将在Windows,Linux和OS X上运行。这样,您只需编写一次串行通信代码,就可以在所有平台上进行测试。

The PySerial documentation contains some examples for how to read and write to the port. PySerial文档包含一些有关如何读取和写入端口的示例。

If Python doesn't work for you in production, I would still recommend sticking with a programming language that has a cross-platform serial port library if possible. 如果Python在生产中不适合您,我仍然建议您尽可能使用具有跨平台串行端口库的编程语言。

Here's a question that was asked already about a cross-platform serial port library for C: C: cross-platform RS-232 serial library? 这是一个有关C的跨平台串行端口库的问题: C:跨平台RS-232串行库?

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

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