- 论坛徽章:
- 0
|
我想通过读取Modem bits来确定CARRIER位,可是ioctl却出错。
serial.c
#ifndef _SVID3
#define _SVID3
#endif
#include <sys/ioctl.h>;
#include <fcntl.h>;
#include <errno.h>;
#include <sys/termios.h>;
int main(int argc, char *argv[])
{
int fd;
int flags;
if ((fd=open(argv[1],O_RDWR | O_NDELAY))<0)
{
printf("open file failed!\n");
exit(1);
}
for (;;)
{
if (ioctl(fd,TIOCMGET,&flags)<0)
{
perror("ioctl failed");
sleep(2);
continue;
}
flags=flags & TIOCM_CAR;
if (flags == 0)
printf("termio on!\n");
else
printf("termio off!\n");
sleep(2);
}
}
编译后,运行
./serial /dev/tty1a
时出错信息为:
ioctl failed: Invalid argument
这是为什么? |
|