研究了一下,spcomm有个ReadIntervalTimeout属性,是用来设置:两数据相差多少MS 就认为是不同的一帧数据. 它内部,是通过调用SetCommTimeouts 这个API来做的. 内部代码如下:procedure TComm._SetCommTimeout; var commtimeouts: TCommTimeouts; begin GetCommTimeouts( hCommFile, commtimeouts ); // The CommTimeout numbers will very likely change if you are // coding to meet some kind of specification where // you need to reply within a certain amount of time after // recieving the last byte. However, If 1/4th of a second // goes by between recieving two characters, its a good // indication that the transmitting end has finished, even // assuming a 1200 baud modem. commtimeouts.ReadIntervalTimeout := FReadIntervalTimeout; commtimeouts.ReadTotalTimeoutMultiplier := FReadTotalTimeoutMultiplier; commtimeouts.ReadTotalTimeoutConstant := FReadTotalTimeoutConstant; commtimeouts.WriteTotalTimeoutMultiplier := FWriteTotalTimeoutMultiplier; commtimeouts.WriteTotalTimeoutConstant := FWriteTotalTimeoutConstant; SetCommTimeouts( hCommFile, commtimeouts ); end;其中,commtimeouts这个结构体中的ReadIntervalTimeout,就是用来设置你说的这个默认的100MS的间隔的.注意: commtimeouts.ReadIntervalTimeout := FReadIntervalTimeout; 而FReadIntervalTimeout 在 这个类create的时候,就被赋了默认的初值100. 但这个类里面有个published属性: property ReadIntervalTimeout: DWORD read FReadIntervalTimeout write SetReadIntervalTimeout; 所以,你只需要设置: SpComm1.ReadIntervalTimeout := 19; 这样就行了,设置个比20小的值.
修改readintervaltimeout属性的值10
procedure TComm.SetReadIntervalTimeout( v : DWORD ); begin if v = FReadIntervalTimeout then Exit; FReadIntervalTimeout := v; if hCommFile <> 0 then _SetCommTimeout end; FReadIntervalTimeout := v; 这句有什么作用? 是不是我设置成5 也无效了?? FReadIntervalTimeout := 5; INPUTBUFFERSIZE = 512; 还是收到512个才能显示出来
它内部,是通过调用SetCommTimeouts 这个API来做的.
内部代码如下:procedure TComm._SetCommTimeout;
var
commtimeouts: TCommTimeouts;
begin
GetCommTimeouts( hCommFile, commtimeouts ); // The CommTimeout numbers will very likely change if you are
// coding to meet some kind of specification where
// you need to reply within a certain amount of time after
// recieving the last byte. However, If 1/4th of a second
// goes by between recieving two characters, its a good
// indication that the transmitting end has finished, even
// assuming a 1200 baud modem. commtimeouts.ReadIntervalTimeout := FReadIntervalTimeout;
commtimeouts.ReadTotalTimeoutMultiplier := FReadTotalTimeoutMultiplier;
commtimeouts.ReadTotalTimeoutConstant := FReadTotalTimeoutConstant;
commtimeouts.WriteTotalTimeoutMultiplier := FWriteTotalTimeoutMultiplier;
commtimeouts.WriteTotalTimeoutConstant := FWriteTotalTimeoutConstant; SetCommTimeouts( hCommFile, commtimeouts );
end;其中,commtimeouts这个结构体中的ReadIntervalTimeout,就是用来设置你说的这个默认的100MS的间隔的.注意: commtimeouts.ReadIntervalTimeout := FReadIntervalTimeout;
而FReadIntervalTimeout 在 这个类create的时候,就被赋了默认的初值100.
但这个类里面有个published属性:
property ReadIntervalTimeout: DWORD read FReadIntervalTimeout write SetReadIntervalTimeout;
所以,你只需要设置:
SpComm1.ReadIntervalTimeout := 19; 这样就行了,设置个比20小的值.
begin
if v = FReadIntervalTimeout then
Exit; FReadIntervalTimeout := v; if hCommFile <> 0 then
_SetCommTimeout
end; FReadIntervalTimeout := v; 这句有什么作用? 是不是我设置成5 也无效了?? FReadIntervalTimeout := 5; INPUTBUFFERSIZE = 512;
还是收到512个才能显示出来
如果数据多,你可以调整一下INPUTBUFFERSIZE的值这是一段接收的程序,我一直使用的
procedure Tfrmmain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
rbuf:array of byte;
i: integer;
begin
setLength(rbuf, BufferLength);
move(Buffer^, PChar(rbuf)^, BufferLength);
//rbuf[0]..rbuf[bufferlength-1]是你接收的数据
end;