当前位置: 技术问答>linux和unix
请教操作IO的高手,IO口设置出问题啦
来源: 互联网 发布时间:2015-02-10
本文导语: fd是串口的设备ID,msec是想等待超时的毫秒,flag是否要阻塞 int waiting(int fd, int msec, int flag) { int ret; fd_set fds; struct timeval tv; for (;;) { FD_ZERO(&fds); FD_SET(fd, &fds); ...
fd是串口的设备ID,msec是想等待超时的毫秒,flag是否要阻塞
int waiting(int fd, int msec, int flag)
{
int ret;
fd_set fds;
struct timeval tv;
for (;;) {
FD_ZERO(&fds);
FD_SET(fd, &fds);
tv.tv_sec = (int)((msec * 1.0) / 1000.0);
tv.tv_usec = (msec % 1000) * 1000;
if (!flag)
ret = select(fd + 1, &fds, NULL, NULL, &tv);
else
ret = select(fd + 1, NULL, &fds, NULL, &tv);
if (ret
int waiting(int fd, int msec, int flag)
{
int ret;
fd_set fds;
struct timeval tv;
for (;;) {
FD_ZERO(&fds);
FD_SET(fd, &fds);
tv.tv_sec = (int)((msec * 1.0) / 1000.0);
tv.tv_usec = (msec % 1000) * 1000;
if (!flag)
ret = select(fd + 1, &fds, NULL, NULL, &tv);
else
ret = select(fd + 1, NULL, &fds, NULL, &tv);
if (ret