求助高手解答串口程序
大侠们,能不梦帮我解答一下这个程序是什么意思啊,最好是一步一步的说明他的作用和目的,小弟刚开始学习,许多地方不懂,请多多指教function read_dm_com1(startAddress:string):string;
var
outstring,keyorder,fcd,instring,z,zz,resu:string;
i,s:integer;
j,jj,y,time_out:integer;
//error_com:boolean;
begin
j:=ord('@');
mainform.MSComm1.InBufferCount :=0;
keyorder:=startaddress;
outstring:='@'+'00'+'RD'+keyorder+'0001';
for i:=2 to length(outstring) do
begin
zz:=copy(outstring,i,1);
jj:=ord(zz[1]);
y:=j xor jj;
j:=y;
end;
z:=inttohex(y,1);
fcd:=z;
outstring:=outstring+fcd+'*'+chr(13);
MainForm.MSComm1.Output :=outstring;
time_out:=1;
repeat
time_out:=time_out+1;
// delay(1);
sleep(1)
until ((time_out=50)or(mainform.MSComm1.InBufferCount>= 15));
if time_out=50 then
result:='0'
else
begin
instring:=MainForm.MSComm1.Input;
result:=copy(instring,8,4);
end;
end;