向串口发送命令数据,仅供参考:
procedure TmainF.SendTXT(Mode :Char; texts: string);
var
ll: dword;
Len,ci,i: dword;
begin
Len:=Length(texts);
if Len = 0 then
begin
StatusBar1.Panels[0].text:='Command Error';
exit;
end;
SendC[0]:=#2;
if (Mode ='S') then
begin
if SetupF.OperateObject.ItemIndex < 0 then exit;
case SetupF.OperateObject.ItemIndex of
0:
begin
SendC[2]:=#$F0;
ci:=3;
end;
1:
begin
SendC[2]:=#$F2;
ci:=3;
end;
2:
begin
SendC[2]:=#$a0;
ci:=3;
end;
3:
begin
SendC[2]:=#$a0;
SendC[3]:=#$0A;
SendC[4]:=char(STRtoINT(SetupF.CIDText.text));
ci:=5;
end;
end;
end else if (Mode = 'T') then
begin
SendC[2]:=#$AA;
ci:=3;
end;
ll:=ci;
ChangeTXT(texts,len,ci);
// if (SendC[ll]=#$ff) then
// SendC[2]:=#$ff;
SendC[1]:=char(ci-1);
ll:=0;
for i:=0 to ci-1 do
begin
ll:=ll+word(SendC);
end;
SendC[ci]:=char(ll);
SendC[ci+1]:=#0;
ll:=Ci+1;
writefile(hFileRs232,SendC,ll,ll,bb);
if disp = 0 then CMDWindow.Lines.Insert
(0,ChgOutTxt2Cahr('S:'+ByteToString(@SendC[0],ll),SetupF.OperateObject.ItemIndex));
end;