【发布时间】:2013-06-18 00:30:14
【问题描述】:
我正在编写一些 C 代码来从 arduino 获取消息,我使用的端口是 tty.usbmodem1411,它可以很好地将代码刻录到 arduino 板。 但是,在编写 C 代码时
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
int main(){
int fd = open("/dev/tty.usbmodem1411", O_RDWR);
printf("open\n");
这段代码可以编译,但运行时,连“打开”都无法显示。 程序卡在打开的行上。
我使用命令 chmod 777 和 chown 和 chgrp 来更改文件的权限,但它仍然不起作用。而且我也不能使用命令
cat /dev/tty.usbmodem1411
它只是被阻塞了,什么也没发生。我在网上查了一下,把端口改成cu.usbmodem1411,好像是一样的。
有人有什么想法吗?谢谢。
【问题讨论】:
-
你有没有试过其他的open功能? open 应该进行错误检查。 if(open("file",O_RDWR) == NULL)
-
当您尝试打开该端口时,请确保该端口未被其他应用程序使用。还要在 fd 上添加检查错误。
标签: c macos serial-port arduino tty