简体   繁体   English

windows 中的“/dev/ttyUSB0”等效项

[英]“/dev/ttyUSB0” equivalent in windows

In Linux I can write and read data from an USB device by calling C's fopen('/dev/ttyUSB0', 'rw')在 Linux 中,我可以通过调用 C 的fopen('/dev/ttyUSB0', 'rw')从 USB 设备写入和读取数据

Specifically what is the equivalent of the directory "/dev/ttyUSB0" in windows I'd like to do the same in windows for COM3.具体来说,windows 中目录“/dev/ttyUSB0”的等效项是什么?

If you are using a runtime environment like Cygwin or msys-2.0.dll which provides a POSIX compatibility, you can run ls /dev/tty* in the shell provided by the environment to see what kind of entries you get.如果您使用的是提供 POSIX 兼容性的 Cygwin 或 msys-2.0.dll 等运行时环境,您可以在环境提供的 shell 中运行ls /dev/tty*以查看您获得的条目类型。 It looks like COM3 would correspond to /dev/ttyS2 , at least with msys-2.0.dll.看起来 COM3 将对应于/dev/ttyS2 ,至少与 msys-2.0.dll 对应。

If you are writing a native Windows program, you should be able to open "COM3" with fopen or CreateFile .如果您正在编写本机 Windows 程序,您应该能够使用fopenCreateFile打开“COM3”。 Using CreateFile is probably better than fopen because it returns a native Windows handle which allows you to use the SetCommTimeouts and SetCommState API functions.使用CreateFile可能比fopen更好,因为它返回一个本机 Windows 句柄,它允许您使用SetCommTimeoutsSetCommState API 函数。 COM ports higher than COM9 need a prefix of \\.\ , which is written as "\\\\.\\" in C because we need to escape the backslashes. COM 端口高于 COM9 需要前缀\\.\ ,在 C 中写为"\\\\.\\" ,因为我们需要转义反斜杠。

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

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