procedure TForm1.MSComm1Comm(Sender: TObject);
var
I,J:Integer;
begin
case MsComm1.CommEvent of
1 : //
2 : begin
Recvar:=VarArrayCreate([0,63],varByte); //Reccar为Variant类型,可设为全局变量,这句最好在初始化时完成;
I:=MSComm1.InBufferCount;
MSComm1.InputLen:=I;
Recvar:=MSComm1.Input; //;
for J:=0 to I-1 do
Str:=Str+IntToHex(Recvar[J],2);//Str为全局变量,用于接收字符;
end;
3 : //
......
......
end;{case}
end;