MacOS:/dev/tty.* 和 /dev/cu.* 之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8632586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MacOS: what's the difference between /dev/tty.* and /dev/cu.*?
提问by Mark Harrison
Each serial device shows up twice in /dev
, once as a tty.*
and once as a cu.*
.
每个串行设备在 中出现两次/dev
,一次作为 a tty.*
,一次作为 a cu.*
。
What is the cu.*
device? How does it differ from the tty.*
device?
cu.*
设备是什么?它与tty.*
设备有何不同?
mh@maru ~ --> ls -l /dev/*.usbmodem621
crw-rw-rw- 1 root wheel 11, 5 Dec 25 18:00 /dev/cu.usbmodem621
crw-rw-rw- 1 root wheel 11, 4 Dec 25 18:00 /dev/tty.usbmodem621
回答by Tom van der Woerdt
http://lists.berlios.de/pipermail/gpsd-dev/2005-April/001288.html:
http://lists.berlios.de/pipermail/gpsd-dev/2005-April/001288.html:
The idea is to supplement software in sharing a line between incoming and outgoing calls. The callin device (typically /dev/tty*) is used for incoming traffic. Any process trying to open it blocks within the open() call as long as DCD is not asserted by hardware (i.e. as long as the modem doesn't have a carrier). During this, the callout device (typically /dev/cu* -- cu stands for "calling unit") can be freely used. Opening /dev/cu* doesn't require DCD to be asserted and succeeds immediately. Once succeeded, the blocked open() on the callin device will be suspended, and cannot even complete when DCD is raised, until the cu device is closed again.
That way, you can have a getty listening on /dev/tty*, and can still use /dev/cu* without restrictions.
这个想法是补充软件在来电和去电之间共享一条线路。callin 设备(通常是 /dev/tty*)用于传入流量。只要硬件未声明 DCD(即,只要调制解调器没有载波),任何尝试打开它的进程都会在 open() 调用中阻塞。在此期间,可以自由使用调用设备(通常为 /dev/cu* -- cu 代表“调用单元”)。打开 /dev/cu* 不需要断言 DCD 并立即成功。一旦成功,callin 设备上被阻塞的 open() 将被挂起,甚至在 DCD 被引发时也无法完成,直到再次关闭 cu 设备。
这样,您就可以让 getty 监听 /dev/tty*,并且仍然可以不受限制地使用 /dev/cu*。