spcomm串口通信为什么会丢数据?
procedure TForm1.SendHex(S: String);var
s2:string;
buf1:array[0..50000] of char;
i:integer;
begin
s2:='';
for i:=1 to length(s) do
begin
if ((copy(s,i,1)>='0') and (copy(s,i,1)<='9'))or((copy(s,i,1)>='a') and (copy(s,i,1)<='f'))
or((copy(s,i,1)>='A') and (copy(s,i,1)<='F')) then
begin
s2:=s2+copy(s,i,1);
end;
// edit2.Text:=s2;
end;
for i:=0 to (length(s2) div 2-1) do
buf1[i]:=char(strtoint('$'+copy(s2,i*2+1,2)));
Comm1.WriteCommData(buf1,(length(s2) div 2));
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
year,month,day,hour,minute,second,millisecond:word;
str1:string;
begin
timer1.Interval:=Trunc(StrToFloat(edit1.Text)*60*1000);
label1.Caption:=datetimetostr(now());
decodedatetime(now(),year,month,day,hour,minute,second,millisecond);
str1:=inttohex((second*1000+millisecond),4)+inttohex(minute,2)+inttohex
(hour,2);
T:=('6853ff670101ff0000'+str1+'8116');
// T:=('6853ff670101ff'+str1+'8116');
SendHex(T);
edit3.text:=T;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Comm1.StopComm;
end;
//测试接收程序
procedure (Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
tmpArray:array[0..4096] of Byte;
ArraySize,i: DWORD;
Count:DWORD;
tmpStr,s:string;
pStr:PChar;
begin
pStr:=Buffer;
tmpStr:=string(pStr);
Dec(PStr);
s:='';
for i:=0 to Length(tmpStr)-1 do
begin
inc(PStr);
tmpArray[i]:=Byte(PSTR^);
s:=s+IntToHEX(Ord(tmpArray[i]),2);
end;
Memo1.Lines.Add(s);
exit;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Comm1.StartComm;
end;
end.
这个是串口通信的主要代码,现在的问题在于接收到的只有6853ff670101ff这么多,后面的都收不到。请高手指教一下,到底是哪里的问题?是接收程序还是发送程序呢?谢谢啦……