VTIME和VMIN串行端口选项是否适用于select?

时间:2012-01-31 12:59:23

标签: c linux serial-port termios

我有Linux程序,使用select()read()读取串行端口。 它工作正常,但存在性能问题:

程序每个read()调用仅接收1-4个字节的数据。 这会导致不必要的开销。

我将VTIME设置为20(2秒),将VMIN设置为9,以避免出现问题。

tcgetattr( fd, &termiosv );

termiosv.c_cc[VMIN]  = 9;
termiosv.c_cc[VTIME] = 20;

tcsetattr( fd, TCSANOW, &termiosv );

但是当只有1-4个字节可用时,select()仍会立即返回。 追踪该计划:

2012.03.31 14:31:34  Data from serial:
0000: 7E A0                           

2012.03.31 14:31:34  Data from serial:
0000: 07 21 03 71                     

2012.03.31 14:31:34  Data from serial:
0000: 13 63 7E  

我的问题是:

VTIME和VMIN串口选项是否适用于select

如果它应该有用,为什么select太早返回?

使用非规范模式。串口配置为:

~ # stty -F /dev/ttySC0 -a
speed 9600 baud; rows 24; columns 80;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O;
min = 9; time = 20;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke
~ #

0 个答案:

没有答案