中国开发网: 论坛: 程序员情感CBD: 贴子 278384
haitao
返回有时还是被分成2部分了。。。如果把循环里的sleep加大,好像不太好,仅仅在repeat前,加上sleep(较大的ms)。。。
相当于2个参数:
首次返回后的sleep量(50ms)
然后的循环里的sleep量(10ms)

var
oldcount:Integer=0;
procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
Str: String;
begin
// if not bcmdend then
// exit;
if oldcount=0 then
sleep(50);
repeat
oldcount:=(sender as Tcomport).InputCount;
sleep(10);
until oldcount=(sender as Tcomport).InputCount;

ComPort.ReadStr(Str, oldCount);
oldcount:=0;
Memo.Text := Memo.Text + Str + '#' ;
//Memo.Lines.Add(str);

scrollmemo(memo);
end;


看帮助,好像它的超时可以设到这么细的,但是我试了多次,没效果。。。
要搞一个表格:
ReadInterval | -1 | -1 | -1 | ...
ReadTotalConstant | -1 | -1 | 0 | ...
ReadTotalMultiplier | -1 | 0 | 0 | ...
效果 | ?? | ??? | ? | ...


Specifies read interval timeout.

property ReadInterval: Integer;

Description
Specifies the maximum time, in milliseconds,
allowed to elapse between the arrival of two characters on the communications line.
During a read operation, the time period begins when the first character is received.
If the interval between the arrival of any two characters exceeds this amount,
the read operation is completed and any buffered data is returned.
A value of zero indicates that interval time-outs are not used.

Note
A value of -1, combined with zero values for both the ReadTotalConstant
and ReadTotalMultiplier properties,
specifies that the read operation is to return immediately with
the characters that have already been received,
even if no characters have been received.



Specifies constant for read total timeout.

property ReadTotalConstant: Integer;

Description
Specifies the constant, in milliseconds,
used to calculate the total time-out period for read operations.
For each read operation, this value is added to the product of
the ReadTotalMultiplier property and the requested number of bytes.

Note
A value of zero for both the ReadTotalMultiplier and ReadTotalConstant
properties indicates that total time-outs are not used for read operations.

If an application sets ReadInterval and ReadTotalMultiplier to -1 and
sets ReadTotalConstant to a value greater than zero,
one of the following occurs when the read function is called:


?If there are any characters in the input buffer,
read function returns immediately with the characters in the buffer.
?If there are no characters in the input buffer,
read function waits until a character arrives and then returns immediately.
?If no character arrives within the time specified by ReadTotalConstant,
read function times out.


Specifies multiplier for read total timeout.

property ReadTotalMultiplier: Integer;

Description
Specifies the multiplier, in milliseconds, used to calculate
the total time-out period for read operations.
For each read operation, this value is multiplied by
the requested number of bytes to be read.

Note
A value of zero for both ReadTotalTimeout the and
ReadTotalConstant properties indicates that total time-outs
are not used for read operations.



Specifies constant for write total timeout.

property WriteTotalConstant: Integer;

Description
Specifies the constant, in milliseconds, used to calculate
the total time-out period for write operations. For each write operation,
this value is added to the product of the WriteTotalMultiplier properties
and the number of bytes to be written.

Note
A value of zero for both the WriteTotalMultiplier and WriteTotalConstant
properties indicates that total time-outs are not used for write operations.



Specifies multiplier for write total timeout.

property WriteTotalMultiplier: Integer;

Description
Specifies the multiplier, in milliseconds, used to calculate
the total time-out period for write operations.
For each write operation,
this value is multiplied by the number of bytes to be written.

Note
A value of zero for both the WriteTotalMultiplier and WriteTotalConstant
properties indicates that total time-outs are not used for write operations.
我的blog:http://szhaitao.blog.hexun.com & http://www.hoolee.com/user/haitao
--以上均为泛泛之谈--
不尽牛人滚滚来,无边硬伤纷纷现 人在江湖(出来的),哪能不挨刀(总归是要的)
网络对话,歧义纷生;你以为明白了对方的话,其实呢?

您所在的IP暂时不能使用低版本的QQ,请到:http://im.qq.com/下载安装最新版的QQ,感谢您对QQ的支持和使用

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录