发新话题
打印

LINUX下的串口编程的超时函数是什么

LINUX下的串口编程的超时函数是什么

请问LINUX下的串口编程的超时函数是什么,是不是SELECT();如何使用      

TOP

我的一段代码, 看看。。

int0 }2 v0 m, C9 N' r) J, ^
Serial::select(struct timeval *timeout) const& J. [) t+ x7 b  Q! P
{! b. [0 }' L# b! R! Q" M3 h# H% e
ASSERT(fd >= 0, "specified serial port doesn't open");
1 H- F! f/ B" R5 m0 u
6 V. F' N. y- W; a! V int nselect;
" Y6 j# e1 o) K, @" W+ s fd_set rfds;
! B! C0 ~# K; ^6 ^0 e1 X FD_ZERO(&rfds);1 H0 g; a: V3 [9 u$ g8 Q
for(;;) {( L7 B  v. e0 ?6 }2 j  O
  FD_SET(fd, &rfds);  ^9 g) C' X; s
  nselect = ::select(fd + 1, &rfds, NULL, NULL, timeout);
8 }7 r6 U" }* R  if (nselect < 0) {
) h% `1 Q4 m# o4 T) [0 H% r3 ^5 O/ ?( e   if (errno == EINTR ) continue;+ w+ c; g4 u& j( Q" ^- X
   // throw std::runtime_error(std::string("error occured while listen on serial: ").append(device));
1 Z' x& U9 V" k7 p   throw std::runtime_error(std::string(strerror(errno)).append(device));. W5 I# w) Q- a! B2 g0 I( e' X
  } else if (nselect == 0) {$ V* [" U6 H8 l
   throw SerialTimeout(std::string("select timeout on serial: ").append(device));( R9 R8 X2 V4 T0 C
  } else if (FD_ISSET(fd, &rfds)) {( c. [4 k9 K  G, F, a
   return nselect;) E7 G" f5 L8 K6 e5 x
  }   
4 O% ]6 N$ V6 k7 u3 K% } }
3 `6 M2 @; p1 H- v* F. s4 Z return nselect;
- u* N( y- x8 B  H! k}      

TOP

发新话题