Search code examples
clinuxtty

What are these device connection names?


I want to connect an Arduino to a linux computer. All devices are listed at /dev/*. When I connect for example an original Arduino mega, I get these additional devices:

/dev/tty.usbmodem...
/dev/cu.usbmodem...

Now when I want to read from the serial port using this C-function:

void read_from_serial() {
    int fd = open("/dev/cu.usbmodem14101", O_RDWR | O_NOCTTY | O_SYNC);
    if(fd < 0) {
        printf("Failed to open connection to device.\n");
        return;
    }

    struct termios tty;
    if (tcgetattr(fd, &tty) < 0) {
        printf("Error: %s\n", strerror(errno));
        return;
    }

    cfsetospeed(&tty, (speed_t)B115200);
    cfsetispeed(&tty, (speed_t)B115200);

    if (tcsetattr(fd, TCSANOW, &tty) != 0) {
        printf("Error: %s\n", strerror(errno));
        return;
    }

    tcflush(fd, TCIOFLUSH);

    char c;
    while (read(fd, &c, 1) == 1) {
        putchar(c);
    }

    close(fd);
}

I need to connect to /dev/cu... and not to /dev/tty... What is the meaning of cu and tty?


Solution

  • What are these device connection names?

    What is the meaning of cu and tty?

    tty stands for "TeleTYpewriter", from https://en.wikipedia.org/wiki/Tty_(unix) .

    cu stands for "Call-Up" device, devices used for calling them up, like modems, from https://pbxbook.com/other/mac-tty.html.