这是我接收水深仪的程序,如果数据量大的话可以增大缓冲区,如下。波特率为9600,处理没有一点问题。
procedure TMainForm.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
s2,s1:string;
i,j:integer;
NMEA_BUF:array[1..32] of byte;//可以增大1024..2048
Deepth,NMEA_DATA:string;
begin
Deepth:='';
try
move(buffer^,pchar(@NMEA_BUF)^,bufferlength);
for i:=1 to bufferlength do
begin
NMEA_DATA:=NMEA_DATA+chr(NMEA_BUF)+'';
end;
NMEA_DATA:=trim(NMEA_DATA);
if memo1.Lines.Count>=200 then
memo1.Clear;
memo1.lines.add(NMEA_DATA);
//数据处理
s1:=RegulateStr(NMEA_DATA,Space);
if NMEA_I=l1 then
begin
for j:=0 to 3 do
begin
s2:=GetSubStr(s1,Space);
case j of
3eepth:=s2;
0,1,2eepth:='';
end;
end;
if Deepth<>'' then
begin
nmea_data_flag:=true;
if checknumber(deepth) then
ValueListEditor1.cells[1,ta1[1]]:=s2
else
ValueListEditor1.cells[1,ta1[1]]:='0';
end
else
nmea_data_flag:=false;
end;
except
ValueListEditor1.cells[1,ta1[1]]:='0';
end;
end;