【问题标题】:What are these device connection names? [closed]这些设备连接名称是什么? [关闭]
【发布时间】:2021-07-27 08:54:42
【问题描述】:

我想将 Arduino 连接到 linux 计算机。所有设备都列在/dev/*。例如,当我连接一个原始的 Arduino mega 时,我会得到这些额外的设备:

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

现在当我想使用这个 C 函数从串口读取数据时:

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);
}

我需要连接/dev/cu...而不是/dev/tty... cu和tty是什么意思?

【问题讨论】:

  • man cuman tty
  • 好的,但是为什么我不能使用 tty 呢?
  • to a linux computer. 你确定是linux而不是macos? why can't I use tty then? 什么意思?为什么你不能?请注意,您问过 What is the meaning of cu and tty?not“为什么我不能使用 tty”或类似的问题。源代码是否与您的问题相关?请考虑提出一个单独的问题。

标签: c linux tty


【解决方案1】:

这些设备连接名称是什么?

cu和tty是什么意思?

tty 代表“TeleTYpewriter”,来自https://en.wikipedia.org/wiki/Tty_(unix)

cu 代表“Call-Up”设备,用于从https://pbxbook.com/other/mac-tty.html 调用它们的设备,如调制解调器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多