相当于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.