- 论坛徽章:
- 0
|
我在FreeBSD下想做一个串口的接收程序。查阅了相关资料。在FreeBSD8.0下,我用open函数打开/dev/ttyu0 时,就死在open函数了,也没有任何提示。期间也实验过 /dev/cuau0
我将/etc/ttys中 关于ttyu0也做了修改。ttyu0 "/usr/libexec/getty std.9600" unknown on secure
我是用普通的串口线连接的,在Windows主机中就可以正常接收。
关键是程序运行到open时就不再继续了,没有任何提示。
请问我是哪里出了问题?
简化版代码如下:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
int main(void)
{
int fd;
printf("start\n");
fd = open ("/dev/ttyu0",O_RDONLY); // 执行到这就不再往下继续了。
printf("Open\n") ;
if (fd == -1)
{
perror("Error!");
}
else
{
fcntl(fd,F_SETFL,0);
printf("%s",fd);
}
close(fd);
return 0;
} |
|