0

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?

F_Schmidt
  • 902
  • 1
  • 11
  • 32
  • 2
    `man cu` and `man tty` – Rob Jul 27 '21 at 09:00
  • okay, but why can't I use tty then? – F_Schmidt Jul 27 '21 at 09:01
  • `to a linux computer.` Are you sure it's linux and not macos? `why can't I use tty then?` What do you mean? Why can't you? Note that you asked `What is the meaning of cu and tty?` and __not__ "why I can't use tty" or similar. Is the source code anyhow relevant to your question? Please consider asking a separate question. – KamilCuk Jul 27 '21 at 09:20
  • Related: https://stackoverflow.com/questions/8632586/macos-whats-the-difference-between-dev-tty-and-dev-cu – KamilCuk Jul 27 '21 at 09:27
  • Does this answer your question? [MacOS: what's the difference between /dev/tty.\* and /dev/cu.\*?](https://stackoverflow.com/questions/8632586/macos-whats-the-difference-between-dev-tty-and-dev-cu) – stark Jul 27 '21 at 11:15

1 Answers1

1

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.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111