1

我正在尝试激活 Beaglebone black 上的串行端口并将 TX 连接到 RX。我写了一个测试程序。在其中,根据我在如何从 C 中的串口打开、读取和写入的帮助中找到的帮助,我将我的串口设置为 1152000 波特并且没有奇偶校验。以下是我的主要功能:

int main(void)
{
    char *portname = "/dev/ttyO4";

    int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
    if (fd < 0)
    {
        printf ("error %d opening %s: %s", errno, portname, strerror (errno));
        return 0;
    }

    set_interface_attribs (fd, BAUD_RATE, 0);
    set_blocking (fd, 0);

    while (true)
    {
        write (fd, "Hello!\n", 7);
        char buf [100];
        int n = read (fd, buf, sizeof buf);
        std::cout << buf;
        std::cout.flush();
        sleep(1);
    }

    return 0;
}

当我运行它时,我在串口 RX 上读到了一些东西,但它不是你好,而是“ù¶”。有人可以告诉我为什么会这样吗?

亲切的问候

康奈尔

4

0 回答 0