109

Each serial device shows up twice in /dev, once as a tty.* and once as a cu.*.

What is the cu.* device? How does it differ from the tty.* device?

ls -l /dev/*.usbmodem621

Output:

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465

1 Answers1

123

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.

Community
  • 1
  • 1
Tom van der Woerdt
  • 29,532
  • 7
  • 72
  • 105
  • Thanks Tom, that's just what I needed to know. – Mark Harrison Dec 26 '11 at 05:57
  • Correct, one case where this matter is if you want to use (in Unix and friends) 'cat' to capture serial port data to a file like 'cat /dev/cu.xxxx >file.txt' which does not work with 'tty.' because of the blocking. At least not on MacOs. – nyholku Mar 15 '18 at 10:14
  • 1
    I was able to send stuff out through tty. Why is that? – JobHunter69 Apr 14 '20 at 16:52
  • @MarkHarrison and Tom: so, in most cases, if I'm writing a non-fancy program to talk to a serial port I assume I should use the /dev/tty* device, correct? – ptdecker Nov 14 '20 at 17:59
  • 1
    It is not possible to open the two ports whatever is the order of opening the second opened result in a resource busy [Errno 16] on the second opening. I tried first in Python using pyserial library then in C as in C I can tell that I open one in O_RDONLY and the other O_WRONLY, respectively tty.* and cu.* The only difference is that a cat on /dev/cu.* will return immediately, while cat on /dev/tty* will block. Programmatically, I don't see what advantage could be taken from this when dealing with serial devices. – Stephane Gasparini Jan 08 '22 at 16:00
  • 3
    Wonder what DCD is? – Weihang Jian Apr 17 '22 at 07:16
  • 1
    The link is broken. It redirects to a page in German, https://www.berlios.de/software/gpsd/ (*"gpsd ist ein Service-Daemon, der einen oder mehrere GPS- oder AIS-Empfänger überwacht..."*). It has nothing to do with the original (it is *only* about GPSd). – Peter Mortensen Sep 15 '22 at 15:35
  • 1
    @WeihangJian Data Carrier Detect, or usually just Carrier Detect for short. Traditionally, it is used by a modem to indicate communications have been established with the remote party. Programs like 'getty' listen for it, and transmit a login prompt when it is seen – p10ben Feb 23 '23 at 07:59