mainform.pas
资源名称:st800.rar [点击查看]
上传用户:jitai139
上传日期:2013-04-11
资源大小:1244k
文件大小:122k
源码类别:
防火墙与安全工具
开发平台:
Delphi
- unit mainform;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls, ExtCtrls, ComCtrls,math;
- type
- TForm1 = class(TForm)
- Panel1: TPanel;
- GroupBox1: TGroupBox;
- Edit1: TEdit;
- GroupBox2: TGroupBox;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Edit2: TEdit;
- Edit3: TEdit;
- Edit4: TEdit;
- Edit5: TEdit;
- Edit6: TEdit;
- Edit7: TEdit;
- Edit8: TEdit;
- Edit9: TEdit;
- Edit10: TEdit;
- Edit11: TEdit;
- Edit12: TEdit;
- Edit13: TEdit;
- Edit14: TEdit;
- Edit15: TEdit;
- Edit16: TEdit;
- Edit17: TEdit;
- Edit18: TEdit;
- Edit19: TEdit;
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- Button4: TButton;
- Button5: TButton;
- Button6: TButton;
- Button7: TButton;
- Button8: TButton;
- Button9: TButton;
- Button10: TButton;
- Button11: TButton;
- Button12: TButton;
- Button13: TButton;
- Button14: TButton;
- Button15: TButton;
- Button16: TButton;
- Button17: TButton;
- Button18: TButton;
- Edit20: TEdit;
- Edit21: TEdit;
- Edit22: TEdit;
- Edit23: TEdit;
- Edit24: TEdit;
- Edit25: TEdit;
- Button19: TButton;
- Button20: TButton;
- Button21: TButton;
- GroupBox3: TGroupBox;
- ComboBox1: TComboBox;
- Button22: TButton;
- GroupBox4: TGroupBox;
- Edit26: TEdit;
- Label7: TLabel;
- Button24: TButton;
- GroupBox5: TGroupBox;
- ComboBox2: TComboBox;
- Edit27: TEdit;
- Edit28: TEdit;
- Button25: TButton;
- MSComm1: TMSComm;
- StatusBar1: TStatusBar;
- Timer1: TTimer;
- Button26: TButton;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- Button27: TButton;
- Timer2: TTimer;
- Timer3: TTimer;
- Timer4: TTimer;
- Timer5: TTimer;
- Timer6: TTimer;
- Timer7: TTimer;
- Timer8: TTimer;
- Timer9: TTimer;
- Timer10: TTimer;
- Timer11: TTimer;
- Timer12: TTimer;
- Timer13: TTimer;
- Timer14: TTimer;
- Button28: TButton;
- SaveDialog2: TSaveDialog;
- Shape1: TShape;
- Timer15: TTimer;
- Timer16: TTimer;
- Label8: TLabel;
- Label9: TLabel;
- Label10: TLabel;
- Memo1: TMemo;
- CheckBox1: TCheckBox;
- CheckBox2: TCheckBox;
- CheckBox3: TCheckBox;
- CheckBox4: TCheckBox;
- CheckBox5: TCheckBox;
- CheckBox6: TCheckBox;
- Label12: TLabel;
- Edit29: TEdit;
- Label13: TLabel;
- Label14: TLabel;
- Edit30: TEdit;
- Label15: TLabel;
- Edit31: TEdit;
- Label16: TLabel;
- ComboBox3: TComboBox;
- ComboBox4: TComboBox;
- ComboBox5: TComboBox;
- ComboBox6: TComboBox;
- ComboBox7: TComboBox;
- ComboBox8: TComboBox;
- Label17: TLabel;
- Label18: TLabel;
- Label19: TLabel;
- Label20: TLabel;
- Label21: TLabel;
- Label22: TLabel;
- Button23: TButton;
- Label11: TLabel;
- procedure Button22Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure Button6Click(Sender: TObject);
- procedure Button9Click(Sender: TObject);
- procedure Button12Click(Sender: TObject);
- procedure Button15Click(Sender: TObject);
- procedure Button18Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Button26Click(Sender: TObject);
- procedure Button27Click(Sender: TObject);
- procedure Button5Click(Sender: TObject);
- procedure Button8Click(Sender: TObject);
- procedure Button11Click(Sender: TObject);
- procedure Button14Click(Sender: TObject);
- procedure Button17Click(Sender: TObject);
- procedure Timer2Timer(Sender: TObject);
- procedure Timer3Timer(Sender: TObject);
- procedure Timer4Timer(Sender: TObject);
- procedure Timer5Timer(Sender: TObject);
- procedure Timer6Timer(Sender: TObject);
- procedure Button21Click(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Timer7Timer(Sender: TObject);
- procedure Button4Click(Sender: TObject);
- procedure Button7Click(Sender: TObject);
- procedure Button10Click(Sender: TObject);
- procedure Button13Click(Sender: TObject);
- procedure Button16Click(Sender: TObject);
- procedure Timer8Timer(Sender: TObject);
- procedure Timer9Timer(Sender: TObject);
- procedure Timer10Timer(Sender: TObject);
- procedure Timer11Timer(Sender: TObject);
- procedure Timer12Timer(Sender: TObject);
- procedure Button24Click(Sender: TObject);
- procedure Timer13Timer(Sender: TObject);
- procedure Button25Click(Sender: TObject);
- procedure Timer14Timer(Sender: TObject);
- procedure Button28Click(Sender: TObject);
- procedure Button19Click(Sender: TObject);
- procedure Timer15Timer(Sender: TObject);
- procedure Button20Click(Sender: TObject);
- procedure Timer16Timer(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure ComboBox1Change(Sender: TObject);
- procedure ComboBox2Change(Sender: TObject);
- procedure Button23Click(Sender: TObject);
- // function setvar(tag:boolean;btn:tbutton):integer;
- private
- { Private declarations }
- function TsInputVal(staStr:string):boolean;
- public
- { Public declarations }
- timesum,tag,success,p,tagc,pc:integer;
- flag:boolean;
- zuhao:integer;
- tindexnum:integer;
- end;
- var
- Form1: TForm1;
- implementation
- //uses sysutils;
- {$R *.dfm}
- {function setvar(tag:boolean;btn:tbutton):integer;
- var
- i:integer;
- begin
- i:=-1;
- while tag<>true do begin
- if (edit2.)or()or()or()or()or()
- btn.Click;
- end;
- i:=1 ;
- tag:=false;
- result:= i;
- end; }
- //function senddata(cid:integer) :boolean;
- function TForm1.TsInputVal(staStr:string):boolean;
- var
- flag1,flag2:boolean ;
- f:real;
- begin
- f:=strToFloat(staStr);
- if f>=0.0000 then
- flag1:=true
- else
- flag1:=false;
- if f>9.999001 then
- flag2:=false
- else
- flag2:=true;
- if flag1 and flag2 then
- begin
- result:=true;
- exit;
- end
- else
- begin
- showmessage('输入或所得的设定值非法!!--范围在:0.000~9.999 之间。');
- result:=false;
- end;
- end;
- PROCEDURE TIMEDELAY(DT:DWORD); //延时程序 timedelay(sencond)
- VAR
- TT:DWORD;
- begin
- //取得现在的TICK值
- TT:=GetTickCount();
- //计算TICK差值是否超过设置之
- while GetTickCount()-TT<DT do
- APPLICATION.ProcessMessages;//释放控制权
- end;
- function hex(c:char):integer; //16进制转换
- var
- x:integer;
- begin
- if c='' then
- x:=0
- else if (ord(c)>=ord('0'))and(ord(c)<=ord('9')) then
- x:=ord(c)-ord('0')
- else if (ord(c)>=ord('a'))and(ord(c)<=ord('f')) then
- x:=ord(c)-ord('a')+10
- else if (ord(c)>=ord('A'))and(ord(c)<=ord('F')) then
- x:=ord(c)-ord('A')+10
- else
- x:=-1;
- result:=x;
- end;
- function hextoint(s:string):integer ; //16进制toINT
- var
- tmpstr1,tmpstr2:integer;
- begin
- if length(s)=1 then
- begin
- result:=hex(s[1]);
- end
- else if length(s)=2 then
- begin
- tmpstr1:=hex(s[1]) ;
- tmpstr2:=hex(s[2]);
- if(tmpstr1=-1)and(tmpstr2=-1) then
- result:=-1
- else
- result:=tmpstr1*16+tmpstr2;
- end
- else
- result:=-1;
- end;
- procedure TForm1.Button22Click(Sender: TObject); //open the serial port
- begin
- if not mscomm1.PortOpen then
- begin
- mscomm1.CommPort:=combobox1.ItemIndex+1;
- tindexnum:= combobox1.ItemIndex;
- mscomm1.Settings:='2400,n,8,1';
- mscomm1.PortOpen:=true;
- statusbar1.Panels[0].Text:='串口com'+inttostr(combobox1.ItemIndex+1)+'已打开';
- shape1.Brush.Color:=clgreen;
- button22.Caption:='断开';
- end else
- begin
- mscomm1.PortOpen:=false;
- shape1.Brush.Color:=clred;
- tindexnum:= combobox1.ItemIndex;
- statusbar1.Panels[0].Text:='串口com'+inttostr(combobox1.ItemIndex+1)+'已关闭';
- button22.Caption:='连接';
- edit4.Text:='';
- edit7.Text:='';
- edit10.Text:='';
- edit13.Text:='';
- edit16.Text:='';
- edit19.Text:='';
- combobox2.ItemIndex:=0;
- label8.Visible:=false;
- label9.Visible:=false;
- label10.Visible:=false;
- label11.Visible:=false;
- label12.Visible:=false;
- label13.Visible:=false;
- label14.Visible:=false;
- label15.Visible:=false;
- label16.Visible:=false;
- edit27.Visible:=false;
- edit28.Visible:=false;
- edit29.Visible:=false;
- edit30.Visible:=false;
- edit31.Visible:=false;
- end;
- // mscomm1.CommPort:=combobox1.ItemIndex+1;
- //mscomm1.Settings:='2400,n,8,1';
- // mscomm1.PortOpen:=true;
- //statusbar1.Panels[0].Text:='serial was open';
- //shape1.Brush.Color:=clgreen;
- //edit3.Text:='';
- edit4.Text:='';
- // edit6.Text:='';
- edit7.Text:='';
- // edit9.Text:='';
- edit10.Text:='';
- // edit12.Text:='';
- edit13.Text:='';
- //edit15.Text:='';
- edit16.Text:='';
- // edit18.Text:='';
- edit19.Text:='';
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- var
- a,b:real;
- c: real;
- m,n:variant;
- str1:string;
- ll:integer;
- begin
- c:=0.00;
- if (edit3.Text<>'') and (edit4.Text<>'') then
- begin
- {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
- begin
- showmessage('数值超出合理范围(-45.00~+25.00)'); /////////////////////////////////
- edit3.Text:='';
- end else begin }
- str1:=label17.Caption;
- if str1='dBm' then begin
- a:=strtofloat(edit4.Text);
- n:=a;
- a:=power(10,a/10.0); //dbm to mw
- a:=a*1000.0; //mw to uw
- b:=strtofloat(edit3.Text);
- ll:=combobox3.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0 ;
- end;
- c:= b/ a;
- edit2.Text:=formatfloat('0.000',c);
- end;
- if str1='uw' then begin
- a:=strtofloat(edit4.Text);
- n:=a;
- // m:=m;
- b:=strtofloat(edit3.Text);
- ll:=combobox3.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0;
- end;
- c:= b/ a;
- edit2.Text:=formatfloat('0.000',c);
- end;
- if str1='nw' then begin
- a:=strtofloat(edit4.Text);
- n:=a;
- a:=a/1000.0;
- b:=strtofloat(edit3.Text);
- ll:=combobox3.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0;
- end;
- c:= b/ a;
- edit2.Text:=formatfloat('0.000',c);
- end;
- if str1='mw' then begin
- a:=strtofloat(edit4.Text);
- n:=a;
- a:=a*1000.0;
- b:=strtofloat(edit3.Text);
- ll:=combobox3.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0;
- end;
- c:=b/a;
- edit2.Text:=formatfloat('0.000',c);
- end;
- // end;
- end
- else
- begin
- showmessage('请先输入正确的值!');
- edit2.SetFocus;
- end;
- end;
- procedure TForm1.Button9Click(Sender: TObject);
- var
- a,b:real;
- c: real;
- m,n:variant;
- str1:string;
- ll:integer;
- begin
- c:=0.00;
- if (edit9.Text<>'') and (edit10.Text<>'') then
- begin {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
- begin
- showmessage('数值超出合理范围(-45.00~+25.00)'); /////////////////////////////////
- edit3.Text:='';
- end else begin }
- str1:=label19.Caption;
- if str1='dBm' then begin
- a:=strtofloat(edit10.Text);
- n:=a;
- a:=power(10,a/10.0); //dbm to mw
- a:=a*1000.0; //mw to uw
- b:=strtofloat(edit9.Text);
- ll:=combobox5.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit8.Text:=formatfloat('0.000',c);
- end;
- if str1='uw' then begin
- a:=strtofloat(edit10.Text);
- n:=a;
- // m:=m;
- b:=strtofloat(edit9.Text);
- ll:=combobox5.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit8.Text:=formatfloat('0.000',c);
- end;
- if str1='nw' then begin
- a:=strtofloat(edit10.Text);
- n:=a;
- a:=a/1000.0;
- b:=strtofloat(edit9.Text);
- ll:=combobox5.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit8.Text:=formatfloat('0.000',c);
- end;
- if str1='mw' then begin
- a:=strtofloat(edit10.Text);
- n:=a;
- a:=a*1000;
- b:=strtofloat(edit9.Text);
- ll:=combobox5.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:=b/a;
- edit8.Text:=formatfloat('0.000',c);
- end;
- // end;
- end
- else
- begin
- showmessage('请先输入正确的值!');
- edit8.setfocus;
- end;
- end;
- procedure TForm1.Button6Click(Sender: TObject);
- var
- a,b:real;
- c: real;
- m,n:variant;
- str1:string;
- ll:integer;
- begin
- c:=0.00;
- if (edit6.Text<>'') and (edit7.Text<>'') then
- begin {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
- begin
- showmessage('数值超出合理范围(-45.00~+25.00'); /////////////////////////////////
- edit3.Text:='';
- end else begin }
- str1:=label18.Caption;
- if str1='dBm' then begin
- a:=strtofloat(edit7.Text);
- n:=a;
- a:=power(10,a/10.0); //dbm to mw
- a:=a*1000.0; //mw to uw
- b:=strtofloat(edit6.Text);
- ll:=combobox4.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit5.Text:=formatfloat('0.000',c);
- end;
- if str1='uw' then begin
- a:=strtofloat(edit7.Text);
- n:=a;
- // m:=m;
- b:=strtofloat(edit6.Text);
- ll:=combobox4.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit5.Text:=formatfloat('0.000',c);
- end;
- if str1='nw' then begin
- a:=strtofloat(edit7.Text);
- n:=a;
- a:=a/1000.0;
- b:=strtofloat(edit6.Text);
- ll:=combobox4.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/a;
- edit5.Text:=formatfloat('0.000',c);
- end;
- if str1='mw' then begin
- a:=strtofloat(edit7.Text);
- n:=a;
- a:=a*1000;
- b:=strtofloat(edit6.Text);
- ll:=combobox4.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:=b/a;
- edit5.Text:=formatfloat('0.000',c);
- end;
- // end;
- end
- else
- begin
- showmessage('请先输入正确的值!');
- edit5.SetFocus;
- end;
- end;
- procedure TForm1.Button12Click(Sender: TObject);
- var
- a,b:real;
- c: real;
- m,n:variant;
- str1:string;
- ll:integer;
- begin
- c:=0.00;
- if (edit12.Text<>'') and (edit13.Text<>'') then
- begin {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
- begin
- showmessage('数值超出合理范围(-45.00~+25.00'); /////////////////////////////////
- edit3.Text:='';
- end else begin }
- str1:=label20.Caption;
- if str1='dBm' then begin
- a:=strtofloat(edit13.Text);
- n:=a;
- a:=power(10,a/10.0); //dbm to mw
- a:=a*1000.0; //mw to uw
- b:=strtofloat(edit12.Text);
- ll:=combobox6.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit11.Text:=formatfloat('0.000',c);
- end;
- if str1='uw' then begin
- a:=strtofloat(edit13.Text);
- n:=a;
- // m:=m;
- b:=strtofloat(edit12.Text);
- ll:=combobox6.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit11.Text:=formatfloat('0.000',c);
- end;
- if str1='nw' then begin
- a:=strtofloat(edit13.Text);
- n:=a;
- a:=a/1000.0;
- b:=strtofloat(edit12.Text);
- ll:=combobox6.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit11.Text:=formatfloat('0.000',c);
- end;
- if str1='mw' then begin
- a:=strtofloat(edit13.Text);
- n:=a;
- a:=a*1000;
- b:=strtofloat(edit12.Text);
- ll:=combobox6.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:=b/a;
- edit11.Text:=formatfloat('0.000',c);
- end;
- // end;
- end
- else
- begin
- showmessage('请先输入正确的值!');
- edit11.SetFocus;
- end;
- end;
- procedure TForm1.Button15Click(Sender: TObject);
- var
- a,b:real;
- c: real;
- m,n:variant;
- str1:string;
- ll:integer;
- begin
- c:=0.00;
- if (edit15.Text<>'') and (edit16.Text<>'') then
- begin {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
- begin
- showmessage('数值超出合理范围(-45.00~+25.00');
- edit3.Text:='';
- end else begin }
- str1:=label21.Caption;
- if str1='dBm' then begin
- a:=strtofloat(edit16.Text);
- n:=a;
- a:=power(10,n/10.0); //dbm to mw
- a:=a*1000.0; //mw to uw
- b:=strtofloat(edit15.Text);
- ll:=combobox7.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit14.Text:=formatfloat('0.000',c);
- end;
- if str1='uw' then begin
- a:=strtofloat(edit16.Text);
- n:=a;
- // m:=m;
- b:=strtofloat(edit15.Text);
- ll:=combobox7.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit14.Text:=formatfloat('0.000',c);
- end;
- if str1='nw' then begin
- a:=strtofloat(edit16.Text);
- n:=a;
- a:=a/1000.0;
- b:=strtofloat(edit15.Text);
- ll:=combobox7.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/a;
- edit14.Text:=formatfloat('0.000',c);
- end;
- if str1='mw' then begin
- a:=strtofloat(edit16.Text);
- n:=a;
- a:=a*1000;
- b:=strtofloat(edit15.Text);
- ll:=combobox7.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:=b/a;
- edit14.Text:=formatfloat('0.000',c);
- end;
- // end;
- end
- else
- begin
- showmessage('请先输入正确的值!');
- edit14.SetFocus;
- end;
- end;
- procedure TForm1.Button18Click(Sender: TObject);
- var
- a,b:real;
- c: real;
- m,n:variant;
- str1:string;
- ll:integer;
- begin
- c:=0.00;
- if (edit3.Text<>'') and (edit4.Text<>'') then
- begin {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
- begin
- showmessage('数值超出合理范围(-45.00~+25.00');
- edit3.Text:='';
- end else begin }
- str1:=label22.Caption;
- if str1='dBm' then begin
- a:=strtofloat(edit19.Text);
- n:=a;
- a:=power(10,a/10.0); //dbm to mw
- a:=a*1000.0; //mw to uw
- b:=strtofloat(edit18.Text);
- ll:=combobox8.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/a;
- edit17.Text:=formatfloat('0.000',c);
- end;
- if str1='uw' then begin
- a:=strtofloat(edit19.Text);
- n:=a;
- // m:=m;
- b:=strtofloat(edit18.Text);
- ll:=combobox8.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/ a;
- edit17.Text:=formatfloat('0.000',c);
- end;
- if str1='nw' then begin
- a:=strtofloat(edit19.Text);
- n:=a;
- a:=a/1000.0;
- b:=strtofloat(edit18.Text);
- ll:=combobox8.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:= b/a;
- edit17.Text:=formatfloat('0.000',c);
- end;
- if str1='mw' then begin
- a:=strtofloat(edit19.Text);
- n:=a;
- a:=a*1000;
- b:=strtofloat(edit18.Text);
- ll:=combobox8.ItemIndex;
- case ll of
- 0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
- 1:b:= b*1000.0;
- 2:b:= b;
- 3:b:= b/1000.0
- end;
- c:=b/a;
- edit17.Text:=formatfloat('0.000',c);
- end;
- // end;
- end
- else
- begin
- showmessage('请先输入正确的值!');
- end;
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- var
- v,len,i,count:integer;
- tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- f:real;
- begin
- arr:=nil;
- if (edit2.Text='') then
- begin
- showmessage('无设定值!');
- end
- else begin if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- //hao add
- if not TsInputVal(edit2.Text) then
- begin
- edit2.SetFocus;
- exit
- end;
- //hao add end
- setlength(arr,9);
- f:=strtofloat(edit2.text)*1000.0;
- tmpstr:=floattostr(f);
- v:=strtoint(tmpstr);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $04; //length
- arr[3]:=$a1; //cid
- arr[4]:=$00; //datainfo
- arr[5]:=v div 256;
- arr[6]:= v mod 256 ;
- xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
- arr[7]:=xornum;
- arr[8]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer1.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- end;
- procedure TForm1.Timer1Timer(Sender: TObject);
- var
- i,n,m,chksum:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- begin
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer1.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer1.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
- //edit4.Text:=inttostr(arr[4]*256+arr[5]);
- if arr[n-3]=$0cc then begin
- showmessage('设置成功!') ;
- //tag:=true;
- end
- else if arr[n-3]=$66 then begin //success:=true;
- timer1.Enabled:=false;
- showmessage('设置失败!');
- end else begin timer1.Enabled:=false;
- showmessage('数据包错误!');
- end;
- end else
- begin
- timer1.Enabled:=false;
- showmessage('帧校验错误!'); //帧校验错误
- //success:=true;
- end;
- end else begin
- timer1.Enabled:=false;
- showmessage('响应数据错误!');
- //success:=true;
- end;
- end else begin
- sleep(10);
- timer1.Enabled:=true;
- end;
- end else begin
- //success:=true;
- timer1.Enabled:=false;
- timesum:=100;
- showmessage('通道0参数设定时响应超时!');
- end;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- tindexnum:=-1;
- timesum:=100;
- flag:=false;
- success:=0;
- zuhao:=-1;
- tag:=0;
- tagc:=0;
- pc:=0;
- p:=0;
- //edit4.Enabled:=false;
- //edit7.Enabled:=false;
- //edit10.Enabled:=false;
- //edit13.Enabled:=false;
- //edit16.Enabled:=false;
- //edit19.Enabled:=false;
- edit20.Enabled:=false;
- edit21.Enabled:=false;
- edit22.Enabled:=false;
- edit23.Enabled:=false;
- edit24.Enabled:=false;
- edit25.Enabled:=false;
- edit26.Enabled:=false;
- edit27.Enabled:=false;
- edit28.Enabled:=false;
- edit29.Enabled:=false;
- edit30.Enabled:=false;
- edit31.Visible:=false;
- label8.Visible:=false;
- label9.Visible:=false;
- label10.Visible:=false;
- label11.Visible:=false;
- label12.Visible:=false;
- label13.Visible:=false;
- label14.Visible:=false;
- label15.Visible:=false;
- label16.Visible:=false;
- edit29.Visible:=false;
- edit30.Visible:=false;
- edit27.Visible:=false;
- edit28.Visible:=false;
- button23.Visible:=false;
- end;
- procedure TForm1.Button26Click(Sender: TObject);
- begin
- if messagedlg('你确定要退出吗?',mtConfirmation,[mbyes,mbno],0)=mryes then
- begin
- if mscomm1.PortOpen then begin
- mscomm1.PortOpen:=false;
- shape1.Brush.Color:=clred;
- end;
- application.Terminate;
- end;
- end ;
- procedure TForm1.Button27Click(Sender: TObject);
- var
- pt:boolean;
- filename,s,ed:string;
- i:integer;
- text:textfile;
- dataarr:array[1..6] of string;
- begin
- pt:=false;
- if opendialog1.Execute then
- begin filename:=opendialog1.FileName;
- filename:=extractfilename(filename);
- if fileexists(filename) then begin
- if edit1.Text='' then ed:='""' else ed:=edit1.Text;
- assignfile(text,filename);
- reset(text);
- try
- while not eof(text) do
- begin
- readln(text,s);
- if s=ed then begin
- pt:=true;
- for i:=1 to 6 do begin
- readln(text,s) ;
- dataarr[i]:=s ;
- end;
- edit20.Text:=dataarr[1];
- edit21.Text:=dataarr[2];
- edit22.Text:=dataarr[3];
- edit23.Text:=dataarr[4];
- edit24.Text:=dataarr[5];
- edit25.Text:=dataarr[6];
- if edit20.Text= edit2.Text then
- checkbox1.Checked:=true else checkbox1.Checked:=false;
- if edit21.Text= edit5.Text then
- checkbox2.Checked:=true else checkbox2.Checked:=false;
- if edit22.Text= edit8.Text then
- checkbox3.Checked:=true else checkbox3.Checked:=false;
- if edit23.Text= edit11.Text then
- checkbox4.Checked:=true else checkbox4.Checked:=false;
- if edit24.Text= edit14.Text then
- checkbox5.Checked:=true else checkbox5.Checked:=false;
- if edit25.Text= edit17.Text then
- checkbox6.Checked:=true else checkbox6.Checked:=false;
- end ;
- end;
- finally
- closefile(text);
- end;
- if pt=false then begin
- edit20.Text:='';
- edit21.Text:='';
- edit22.Text:='';
- edit23.Text:='';
- edit24.Text:='';
- edit25.Text:='';
- showmessage('文件中无匹配记录!');
- end;
- end else
- begin
- edit20.Text:='';
- edit21.Text:='';
- edit22.Text:='';
- edit23.Text:='';
- edit24.Text:='';
- edit25.Text:='';
- showmessage('没有找到指定文件!');
- end;
- end;
- end;
- procedure TForm1.Button5Click(Sender: TObject);
- var
- v,len,i,count:integer;
- tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- f:real;
- begin
- arr:=nil;
- if (edit5.Text='') then
- begin
- showmessage('无设定值!');
- end
- else begin if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- //hao add
- if not TsInputVal(edit5.Text) then
- begin
- edit5.SetFocus;
- exit
- end;
- //hao add end
- setlength(arr,9);
- f:=strtofloat(edit5.text)*1000.0;
- tmpstr:=floattostr(f);
- v:=strtoint(tmpstr);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $04; //length
- arr[3]:=$a1; //cid
- arr[4]:=$01; //datainfo
- arr[5]:=v div 256;
- arr[6]:= v mod 256 ;
- xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
- arr[7]:=xornum;
- arr[8]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer2.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- end;
- procedure TForm1.Button8Click(Sender: TObject);
- var
- v,len,i,count:integer;
- tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- f:real;
- begin
- arr:=nil;
- if (edit8.Text='') then
- begin
- showmessage('无设定值!');
- end
- else begin if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- //hao add
- if not TsInputVal(edit8.Text) then
- begin
- edit8.SetFocus;
- exit
- end;
- //hao add end
- setlength(arr,9);
- f:=strtofloat(edit8.text)*1000.0;
- tmpstr:=floattostr(f);
- v:=strtoint(tmpstr);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $04; //length
- arr[3]:=$a1; //cid
- arr[4]:=$02; //datainfo
- arr[5]:=v div 256;
- arr[6]:= v mod 256 ;
- xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
- arr[7]:=xornum;
- arr[8]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer3.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- end;
- procedure TForm1.Button11Click(Sender: TObject);
- var
- v,len,i,count:integer;
- tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- f:real;
- begin
- arr:=nil;
- if (edit11.Text='') then
- begin
- showmessage('无设定值!');
- end
- else begin if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- //hao add
- if not TsInputVal(edit11.Text) then
- begin
- edit11.SetFocus;
- exit
- end;
- //hao add end
- setlength(arr,9);
- f:=strtofloat(edit11.text)*1000.0;
- tmpstr:=floattostr(f);
- v:=strtoint(tmpstr);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $04; //length
- arr[3]:=$a1; //cid
- arr[4]:=$03; //datainfo
- arr[5]:=v div 256;
- arr[6]:= v mod 256 ;
- xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
- arr[7]:=xornum;
- arr[8]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer4.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- end;
- procedure TForm1.Button14Click(Sender: TObject);
- var
- v,len,i,count:integer;
- tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- f:real;
- begin
- arr:=nil;
- if (edit14.Text='') then
- begin
- showmessage('无设定值!');
- end
- else begin if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- //hao add
- if not TsInputVal(edit14.Text) then
- begin
- edit14.SetFocus;
- exit
- end;
- //hao add end
- setlength(arr,9);
- f:=strtofloat(edit14.text)*1000.0;
- tmpstr:=floattostr(f);
- v:=strtoint(tmpstr);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $04; //length
- arr[3]:=$a1; //cid
- arr[4]:=$04; //datainfo
- arr[5]:=v div 256;
- arr[6]:= v mod 256 ;
- xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
- arr[7]:=xornum;
- arr[8]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer5.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- end;
- procedure TForm1.Button17Click(Sender: TObject);
- var
- v,len,i,count:integer;
- tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- f:real;
- begin
- arr:=nil;
- if (edit17.Text='') then
- begin
- showmessage('无设定值!');
- end
- else begin if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- //hao add
- if not TsInputVal(edit17.Text) then
- begin
- edit17.SetFocus;
- exit
- end;
- //hao add end
- setlength(arr,9);
- f:=strtofloat(edit17.text)*1000.0;
- tmpstr:=floattostr(f);
- v:=strtoint(tmpstr);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $04; //length
- arr[3]:=$a1; //cid
- arr[4]:=$05; //datainfo
- arr[5]:=v div 256;
- arr[6]:= v mod 256 ;
- xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
- arr[7]:=xornum;
- arr[8]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer6.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- end;
- procedure TForm1.Timer2Timer(Sender: TObject);
- var
- i,n,m,chksum:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- begin
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer2.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer2.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
- //edit4.Text:=inttostr(arr[4]*256+arr[5]);
- if arr[n-3]=$0cc then begin
- showmessage('设置成功!') ;
- //tag:=true;
- end
- else if arr[n-3]=$66 then begin //success:=true;
- timer2.Enabled:=false;
- showmessage('设置失败!');
- end else begin timer1.Enabled:=false;
- showmessage('数据包错误!');
- end;
- end else begin
- timer2.Enabled:=false;
- showmessage('数据错误!'); //帧校验错误
- end;
- end else begin
- timer2.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer2.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer2.Enabled:=false;
- showmessage('通道5参数设定响应超时!');
- end;
- end;
- procedure TForm1.Timer3Timer(Sender: TObject);
- var
- i,n,m,chksum:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- begin
- timer3.Enabled:=false;
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer3.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer3.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
- //edit4.Text:=inttostr(arr[4]*256+arr[5]);
- if arr[n-3]=$0cc then begin
- showmessage('设置成功!') ;
- //tag:=true;
- end
- else if arr[n-3]=$66 then begin //success:=true;
- timer3.Enabled:=false;
- showmessage('设置失败!');
- end else begin timer1.Enabled:=false;
- showmessage('数据包错误!');
- end;
- end else begin
- timer3.Enabled:=false;
- showmessage('数据错误!'); //帧校验错误
- end;
- end else begin
- timer3.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer3.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer3.Enabled:=false;
- showmessage('1310nm校正参数设定响应超时!');
- end;
- end;
- procedure TForm1.Timer4Timer(Sender: TObject);
- var
- i,n,m,chksum:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- begin
- timer4.Enabled:=false;
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer4.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer4.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
- //edit4.Text:=inttostr(arr[4]*256+arr[5]);
- if arr[n-3]=$0cc then begin
- showmessage('设置成功!') ;
- //tag:=true;
- end
- else if arr[n-3]=$66 then begin //success:=true;
- timer4.Enabled:=false;
- showmessage('设置失败!');
- end else begin
- timer4.Enabled:=false;
- showmessage('数据包错误!');
- end;
- end else begin
- timer4.Enabled:=false;
- showmessage('数据错误!'); //帧校验错误
- end;
- end else begin
- timer4.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer4.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer4.Enabled:=false;
- showmessage('1550nm校正参数设定响应超时!');
- end;
- end;
- procedure TForm1.Timer5Timer(Sender: TObject);
- var
- i,n,m,chksum:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- begin
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer5.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer5.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
- //edit4.Text:=inttostr(arr[4]*256+arr[5]);
- if arr[n-3]=$0cc then begin
- showmessage('设置成功!') ;
- //tag:=true;
- end
- else if arr[n-3]=$66 then begin //success:=true;
- timer5.Enabled:=false;
- showmessage('设置失败!');
- end else
- begin
- timer5.Enabled:=false;
- showmessage('数据包错误!');
- end;
- end else begin
- timer5.Enabled:=false;
- showmessage('数据错误!'); //帧校验错误
- end;
- end else begin
- timer5.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer5.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer5.Enabled:=false;
- showmessage('850nm校正参数设定响应超时!');
- end;
- end;
- procedure TForm1.Timer6Timer(Sender: TObject);
- var
- i,n,m,chksum:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- begin
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer6.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer6.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
- //edit4.Text:=inttostr(arr[4]*256+arr[5]);
- if arr[n-3]=$0cc then begin
- showmessage('设置成功!') ;
- //tag:=true;
- end
- else if arr[n-3]=$66 then begin //success:=true;
- timer6.Enabled:=false;
- showmessage('设置失败!');
- end else begin
- timer6.Enabled:=false;
- showmessage('数据包错误');
- end;
- end else begin
- timer6.Enabled:=false;
- showmessage('数据错误'); //帧校验错误
- end;
- end else begin
- timer6.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer6.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer6.Enabled:=false;
- showmessage('980nm校正参数设定响应超时!');
- end;
- end;
- procedure TForm1.Button21Click(Sender: TObject);
- var
- fl:boolean;
- text:textfile;
- s,pa,filename:string;
- i,countlin,c :integer;
- begin
- fl:=false;
- if(edit2.Text='')or(edit5.Text='')or(edit8.Text='')or(edit11.Text='')or(edit14.Text='')or(edit17.Text='') then
- showmessage('计算未完成!')
- else if savedialog1.Execute then begin
- filename:=opendialog1.FileName;
- if fileexists(savedialog1.FileName) then
- begin
- memo1.Lines.LoadFromFile(savedialog1.FileName);
- countlin:= memo1.lines.Count ;
- if edit1.Text='' then s:='""'
- else s:=edit1.Text;
- for i:=0 to countlin-1 do begin
- if memo1.Lines[i]=s then
- begin
- for c:=0 to 6 do begin
- memo1.Lines.Delete(i);
- memo1.Refresh;
- end;
- memo1.Lines.Add(s);
- memo1.Lines.add(edit2.text);
- memo1.Lines.Add(edit5.Text);
- memo1.Lines.Add(edit8.Text) ;
- memo1.Lines.Add(edit11.Text) ;
- memo1.Lines.Add(edit14.Text);
- memo1.Lines.Add(edit17.Text);
- memo1.Lines.SaveToFile(savedialog1.FileName);
- flag:=true;
- fl:=true;
- end;
- end;
- if fl=false then begin
- memo1.Lines.add(s);
- memo1.Lines.add(edit2.text);
- memo1.Lines.Add(edit5.Text);
- memo1.Lines.Add(edit8.Text) ;
- memo1.Lines.Add(edit11.Text) ;
- memo1.Lines.Add(edit14.Text);
- memo1.Lines.Add(edit17.Text);
- memo1.Lines.SaveToFile(savedialog1.FileName);
- end;
- end else begin //file is not exist
- assignfile(text,savedialog1.FileName);
- rewrite(text);
- if edit1.Text='' then pa:='""' else pa:=edit1.Text ;
- try
- writeln(text,pa);
- writeln(text,edit2.text);
- writeln(text,edit5.text);
- writeln(text,edit8.text);
- writeln(text,edit11.text);
- writeln(text,edit14.text);
- writeln(text,edit17.text);
- finally
- closefile(text);
- end;
- flag:=true;
- end;
- end ;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- var
- len,i,count:integer;
- //tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- begin
- arr:=nil;
- if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- setlength(arr,7);
- // f:=strtoint(edit2.text);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $02; //length
- arr[3]:=$a3; //cid
- arr[4]:=$00; //datainfo
- // arr[5]:=f div 255;
- // arr[6]:= f mod 255 ;
- xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
- arr[5]:=xornum;
- arr[6]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer7.Enabled:=true;
- // button23.Click;
- end;
- end;
- procedure TForm1.Timer7Timer(Sender: TObject);
- var
- i,n,m,chksum,tp,tph,tpl:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- xy:real;
- str:string;
- begin
- str:='';
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer7.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer7.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do begin
- arr[i]:=tmpvar[i];
- str:=str+inttostr(arr[i]);
- end;
- // showmessage(inttostr(arr[i]));
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then //头校验
- begin if arr[2]<>n-5 then showmessage('长度错误!') else //长度校验
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a3) then begin //帧校验
- tp:=arr[4] and $f0 ;
- tph:=strtoint(floattostr(tp/16));
- tpl:=arr[4] and $0f;
- case tph of
- 0:begin label17.Caption:='mw';
- if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 1: begin label17.Caption:='uw';if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 2: begin label17.Caption:='nw';if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 4: begin label17.Caption:='dBm'; if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 8: showmessage('测量单位不能是dB。');
- 9: showmessage('超范围!');
- end;
- { if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end; }
- end else begin
- timer7.Enabled:=false;
- showmessage('帧校验错误!'); //帧校验错误
- end;
- end;
- end else begin
- timer7.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer7.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer7.Enabled:=false;
- showmessage('响应超时!');
- end;
- end;
- procedure TForm1.Button4Click(Sender: TObject);
- var
- len,i,count:integer;
- //tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- begin
- arr:=nil;
- if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- setlength(arr,7);
- // f:=strtoint(edit2.text);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $02; //length
- arr[3]:=$a3; //cid
- arr[4]:=$00; //datainfo
- // arr[5]:=f div 255;
- // arr[6]:= f mod 255 ;
- xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
- arr[5]:=xornum;
- arr[6]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer8.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- procedure TForm1.Button7Click(Sender: TObject);
- var
- len,i,count:integer;
- //tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- begin
- arr:=nil;
- if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- setlength(arr,7);
- // f:=strtoint(edit2.text);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $02; //length
- arr[3]:=$a3; //cid
- arr[4]:=$00; //datainfo
- // arr[5]:=f div 255;
- // arr[6]:= f mod 255 ;
- xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
- arr[5]:=xornum;
- arr[6]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer9.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- procedure TForm1.Button10Click(Sender: TObject);
- var
- len,i,count:integer;
- //tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- begin
- arr:=nil;
- if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- setlength(arr,7);
- // f:=strtoint(edit2.text);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $02; //length
- arr[3]:=$a3; //cid
- arr[4]:=$00; //datainfo
- // arr[5]:=f div 255;
- // arr[6]:= f mod 255 ;
- xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
- arr[5]:=xornum;
- arr[6]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer10.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- procedure TForm1.Button13Click(Sender: TObject);
- var
- len,i,count:integer;
- //tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- begin
- arr:=nil;
- if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- setlength(arr,7);
- // f:=strtoint(edit2.text);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $02; //length
- arr[3]:=$a3; //cid
- arr[4]:=$00; //datainfo
- // arr[5]:=f div 255;
- // arr[6]:= f mod 255 ;
- xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
- arr[5]:=xornum;
- arr[6]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer11.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- procedure TForm1.Button16Click(Sender: TObject);
- var
- len,i,count:integer;
- //tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- begin
- arr:=nil;
- if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- setlength(arr,7);
- // f:=strtoint(edit2.text);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $02; //length
- arr[3]:=$a3; //cid
- arr[4]:=$00; //datainfo
- // arr[5]:=f div 255;
- // arr[6]:= f mod 255 ;
- xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
- arr[5]:=xornum;
- arr[6]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer12.Enabled:=true;
- end;
- //while mscomm1.InBufferCount
- end;
- procedure TForm1.Timer8Timer(Sender: TObject);
- var
- i,n,m,chksum,tp,tph,tpl:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- xy:real;
- str:string;
- begin
- str:='';
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer8.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer8.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do begin
- arr[i]:=tmpvar[i];
- str:=str+inttostr(arr[i]);
- end;
- // showmessage(inttostr(arr[i]));
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then //头校验
- begin if arr[2]<>n-5 then showmessage('长度错误!') else //长度校验
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a3) then begin //帧校验
- tp:=arr[4] and $f0 ;
- tph:=strtoint(floattostr(tp/16));
- tpl:=arr[4] and $0f;
- case tph of
- 0:begin label18.Caption:='mw';
- if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit7.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit7.Text:=formatfloat('0.000',xy/100.0);
- 2: edit7.Text:=formatfloat('0.000',xy/10.0);
- 3: edit7.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit7.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit7.Text:=formatfloat('0.000',xy/100.0);
- 2: edit7.Text:=formatfloat('0.000',xy/10.0);
- 3: edit7.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 1: begin label18.Caption:='uw';
- if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit7.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit7.Text:=formatfloat('0.000',xy/100.0);
- 2: edit7.Text:=formatfloat('0.000',xy/10.0);
- 3: edit7.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit7.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit7.Text:=formatfloat('0.000',xy/100.0);
- 2: edit7.Text:=formatfloat('0.000',xy/10.0);
- 3: edit7.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 2: begin label18.Caption:='nw';
- if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit7.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit7.Text:=formatfloat('0.000',xy/100.0);
- 2: edit7.Text:=formatfloat('0.000',xy/10.0);
- 3: edit7.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit7.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit7.Text:=formatfloat('0.000',xy/100.0);
- 2: edit7.Text:=formatfloat('0.000',xy/10.0);
- 3: edit7.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 4: begin label18.Caption:='dBm';
- if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit7.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit7.Text:=formatfloat('0.000',xy/100.0);
- 2: edit7.Text:=formatfloat('0.000',xy/10.0);
- 3: edit7.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit7.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit7.Text:=formatfloat('0.000',xy/100.0);
- 2: edit7.Text:=formatfloat('0.000',xy/10.0);
- 3: edit7.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 8: showmessage('测量单位不能是dB。');
- 9: showmessage('超范围!');
- end;
- { if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end; }
- end else begin
- timer8.Enabled:=false;
- showmessage('帧校验错误!'); //帧校验错误
- end;
- end;
- end else begin
- timer8.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer8.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer8.Enabled:=false;
- showmessage('响应超时!');
- end;
- end;
- procedure TForm1.Timer9Timer(Sender: TObject);
- var
- i,n,m,chksum,tp,tph,tpl:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- xy:real;
- str:string;
- begin
- str:='';
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer9.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer9.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do begin
- arr[i]:=tmpvar[i];
- str:=str+inttostr(arr[i]);
- end;
- // showmessage(inttostr(arr[i]));
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then //头校验
- begin if arr[2]<>n-5 then showmessage('长度错误!') else //长度校验
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a3) then begin //帧校验
- tp:=arr[4] and $f0 ;
- tph:=strtoint(floattostr(tp/16));
- tpl:=arr[4] and $0f;
- case tph of
- 0:begin label19.Caption:='mw';
- if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit10.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit10.Text:=formatfloat('0.000',xy/100.0);
- 2: edit10.Text:=formatfloat('0.000',xy/10.0);
- 3: edit10.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit10.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit10.Text:=formatfloat('0.000',xy/100.0);
- 2: edit10.Text:=formatfloat('0.000',xy/10.0);
- 3: edit10.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 1: begin label19.Caption:='uw';if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit10.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit10.Text:=formatfloat('0.000',xy/100.0);
- 2: edit10.Text:=formatfloat('0.000',xy/10.0);
- 3: edit10.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit10.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit10.Text:=formatfloat('0.000',xy/100.0);
- 2: edit10.Text:=formatfloat('0.000',xy/10.0);
- 3: edit10.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 2: begin label19.Caption:='nw';if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit10.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit10.Text:=formatfloat('0.000',xy/100.0);
- 2: edit10.Text:=formatfloat('0.000',xy/10.0);
- 3: edit10.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit10.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit10.Text:=formatfloat('0.000',xy/100.0);
- 2: edit10.Text:=formatfloat('0.000',xy/10.0);
- 3: edit10.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 4: begin label19.Caption:='dBm'; if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit10.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit10.Text:=formatfloat('0.000',xy/100.0);
- 2: edit10.Text:=formatfloat('0.000',xy/10.0);
- 3: edit10.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit10.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit10.Text:=formatfloat('0.000',xy/100.0);
- 2: edit10.Text:=formatfloat('0.000',xy/10.0);
- 3: edit10.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 8: showmessage('测量单位不能是dB。');
- 9: showmessage('超范围!');
- end;
- { if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end; }
- end else begin
- timer9.Enabled:=false;
- showmessage('帧校验错误!'); //帧校验错误
- end;
- end;
- end else begin
- timer9.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer9.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer9.Enabled:=false;
- showmessage('响应超时!');
- end;
- end;
- procedure TForm1.Timer10Timer(Sender: TObject);
- var
- i,n,m,chksum,tp,tph,tpl:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- xy:real;
- str:string;
- begin
- str:='';
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer10.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer10.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do begin
- arr[i]:=tmpvar[i];
- str:=str+inttostr(arr[i]);
- end;
- // showmessage(inttostr(arr[i]));
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then //头校验
- begin if arr[2]<>n-5 then showmessage('长度错误!') else //长度校验
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a3) then begin //帧校验
- tp:=arr[4] and $f0 ;
- tph:=strtoint(floattostr(tp/16));
- tpl:=arr[4] and $0f;
- case tph of
- 0:begin label20.Caption:='mw';
- if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit13.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit13.Text:=formatfloat('0.000',xy/100.0);
- 2: edit13.Text:=formatfloat('0.000',xy/10.0);
- 3: edit13.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit13.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit13.Text:=formatfloat('0.000',xy/100.0);
- 2: edit13.Text:=formatfloat('0.000',xy/10.0);
- 3: edit13.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 1: begin label20.Caption:='uw';if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit13.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit13.Text:=formatfloat('0.000',xy/100.0);
- 2: edit13.Text:=formatfloat('0.000',xy/10.0);
- 3: edit13.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit13.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit13.Text:=formatfloat('0.000',xy/100.0);
- 2: edit13.Text:=formatfloat('0.000',xy/10.0);
- 3: edit13.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 2: begin label20.Caption:='nw';if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit13.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit13.Text:=formatfloat('0.000',xy/100.0);
- 2: edit13.Text:=formatfloat('0.000',xy/10.0);
- 3: edit13.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit13.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit13.Text:=formatfloat('0.000',xy/100.0);
- 2: edit13.Text:=formatfloat('0.000',xy/10.0);
- 3: edit13.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 4: begin label20.Caption:='dBm'; if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit13.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit13.Text:=formatfloat('0.000',xy/100.0);
- 2: edit13.Text:=formatfloat('0.000',xy/10.0);
- 3: edit13.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit13.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit13.Text:=formatfloat('0.000',xy/100.0);
- 2: edit13.Text:=formatfloat('0.000',xy/10.0);
- 3: edit13.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 8: showmessage('测量单位不能是dB。');
- 9: showmessage('超范围!');
- end;
- { if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end; }
- end else begin
- timer10.Enabled:=false;
- showmessage('帧校验错误!'); //帧校验错误
- end;
- end;
- end else begin
- timer10.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer10.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer10.Enabled:=false;
- showmessage('响应超时!');
- end;
- end;
- procedure TForm1.Timer11Timer(Sender: TObject);
- var
- i,n,m,chksum,tp,tph,tpl:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- xy:real;
- str:string;
- begin
- str:='';
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer11.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer11.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do begin
- arr[i]:=tmpvar[i];
- str:=str+inttostr(arr[i]);
- end;
- // showmessage(inttostr(arr[i]));
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then //头校验
- begin if arr[2]<>n-5 then showmessage('长度错误!') else //长度校验
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a3) then begin //帧校验
- tp:=arr[4] and $f0 ;
- tph:=strtoint(floattostr(tp/16));
- tpl:=arr[4] and $0f;
- case tph of
- 0:begin label21.Caption:='mw';
- if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit16.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit16.Text:=formatfloat('0.000',xy/100.0);
- 2: edit16.Text:=formatfloat('0.000',xy/10.0);
- 3: edit16.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit16.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit16.Text:=formatfloat('0.000',xy/100.0);
- 2: edit16.Text:=formatfloat('0.000',xy/10.0);
- 3: edit16.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 1: begin label21.Caption:='uw';if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit16.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit16.Text:=formatfloat('0.000',xy/100.0);
- 2: edit16.Text:=formatfloat('0.000',xy/10.0);
- 3: edit16.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit16.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit16.Text:=formatfloat('0.000',xy/100.0);
- 2: edit16.Text:=formatfloat('0.000',xy/10.0);
- 3: edit16.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 2: begin label21.Caption:='nw';if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit16.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit16.Text:=formatfloat('0.000',xy/100.0);
- 2: edit16.Text:=formatfloat('0.000',xy/10.0);
- 3: edit16.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit16.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit16.Text:=formatfloat('0.000',xy/100.0);
- 2: edit16.Text:=formatfloat('0.000',xy/10.0);
- 3: edit16.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 4: begin label21.Caption:='dBm'; if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit16.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit16.Text:=formatfloat('0.000',xy/100.0);
- 2: edit16.Text:=formatfloat('0.000',xy/10.0);
- 3: edit16.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit16.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit16.Text:=formatfloat('0.000',xy/100.0);
- 2: edit16.Text:=formatfloat('0.000',xy/10.0);
- 3: edit16.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 8: showmessage('测量单位不能是dB。');
- 9: showmessage('超范围!');
- end;
- { if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end; }
- end else begin
- timer11.Enabled:=false;
- showmessage('帧校验错误!'); //帧校验错误
- end;
- end;
- end else begin
- timer11.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer11.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer11.Enabled:=false;
- showmessage('响应超时!');
- end;
- end;
- procedure TForm1.Timer12Timer(Sender: TObject);
- var
- i,n,m,chksum,tp,tph,tpl:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- xy:real;
- str:string;
- begin
- str:='';
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer12.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer12.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do begin
- arr[i]:=tmpvar[i];
- str:=str+inttostr(arr[i]);
- end;
- // showmessage(inttostr(arr[i]));
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then //头校验
- begin if arr[2]<>n-5 then showmessage('长度错误!') else //长度校验
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a3) then begin //帧校验
- tp:=arr[4] and $f0 ;
- tph:=strtoint(floattostr(tp/16));
- tpl:=arr[4] and $0f;
- case tph of
- 0:begin label22.Caption:='mw';
- if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit19.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit19.Text:=formatfloat('0.000',xy/100.0);
- 2: edit19.Text:=formatfloat('0.000',xy/10.0);
- 3: edit19.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit19.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit19.Text:=formatfloat('0.000',xy/100.0);
- 2: edit19.Text:=formatfloat('0.000',xy/10.0);
- 3: edit19.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 1: begin label22.Caption:='uw';if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit19.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit19.Text:=formatfloat('0.000',xy/100.0);
- 2: edit19.Text:=formatfloat('0.000',xy/10.0);
- 3: edit19.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit19.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit19.Text:=formatfloat('0.000',xy/100.0);
- 2: edit19.Text:=formatfloat('0.000',xy/10.0);
- 3: edit19.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 2: begin label22.Caption:='nw';if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit19.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit19.Text:=formatfloat('0.000',xy/100.0);
- 2: edit19.Text:=formatfloat('0.000',xy/10.0);
- 3: edit19.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit19.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit19.Text:=formatfloat('0.000',xy/100.0);
- 2: edit19.Text:=formatfloat('0.000',xy/10.0);
- 3: edit19.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 4: begin label22.Caption:='dBm'; if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit19.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit19.Text:=formatfloat('0.000',xy/100.0);
- 2: edit19.Text:=formatfloat('0.000',xy/10.0);
- 3: edit19.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit19.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit19.Text:=formatfloat('0.000',xy/100.0);
- 2: edit19.Text:=formatfloat('0.000',xy/10.0);
- 3: edit19.Text:=formatfloat('0.000',xy);
- end;
- end;
- end;
- 8: showmessage('测量单位不能是dB。');
- 9: showmessage('超范围!');
- end;
- { if arr[6]<127 then begin
- xy := (arr[6]*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end else begin
- xy := -((arr[6]-128)*256+arr[7]) ;
- case tpl of
- 0: edit4.Text:=formatfloat('0.000',xy/1000.0);
- 1: edit4.Text:=formatfloat('0.000',xy/100.0);
- 2: edit4.Text:=formatfloat('0.000',xy/10.0);
- 3: edit4.Text:=formatfloat('0.000',xy);
- end;
- end; }
- end else begin
- timer12.Enabled:=false;
- showmessage('帧校验错误!'); //帧校验错误
- end;
- end;
- end else begin
- timer12.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer12.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer12.Enabled:=false;
- showmessage('响应超时!');
- end;
- end;
- procedure TForm1.Button24Click(Sender: TObject);
- var
- len,i,count:integer;
- //tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- begin
- arr:=nil;
- begin if not mscomm1.PortOpen then begin
- showmessage('serials is not open!');
- end else begin
- setlength(arr,7);
- // f:=strtoint(edit2.text);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $02; //length
- arr[3]:=$a3; //cid
- arr[4]:=$0ff; //datainfo
- // arr[5]:=f div 255;
- // arr[6]:= f mod 255 ;
- xornum:= arr[2] xor arr[3] xor arr[4] ;//xor arr[5]xor arr[6];
- arr[5]:=xornum;
- arr[6]:=$0d;
- // send data
- len:=length(arr);
- //showmessage('hex:point'+inttostr(len));
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer13.Enabled:=true;
- end;
- end;
- end;
- procedure TForm1.Timer13Timer(Sender: TObject);
- var
- i,n,m,chksum:integer;
- arr:array of byte;
- tmpvar:variant;
- begin
- timer13.Enabled:=false;
- arr:=nil;
- chksum:=0;
- timesum:=timesum+integer(timer13.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.Input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (chksum=arr[n-2])and(arr[3]=$a3) then begin
- edit30.Text:=inttostr(arr[4]);
- edit29.Clear;
- edit28.Clear;
- edit27.Clear;
- { if (arr[4]=$0cc)or(arr[4]=$66) then
- showmessage('参数设定成功!')
- else showmessage('参数设定失败!');}
- end else begin
- timer13.Enabled:=false;
- showmessage('帧校验错误!'); //帧校验错误
- end;
- end else
- begin
- timer13.Enabled:=false;
- showmessage('回应帧错误!');
- //showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer13.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer13.Enabled:=false;
- showmessage('响应超时!');
- end;
- end;
- procedure TForm1.Button25Click(Sender: TObject);
- var
- point,len,i,p,count:integer;
- // f:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- begin
- arr:=nil;
- point:=0;
- if not mscomm1.PortOpen then begin
- showmessage('serials is not open!');
- end else begin
- if combobox2.ItemIndex=0 then showmessage('请选择上传类型!')
- else begin
- if combobox2.ItemIndex=3 then begin
- if edit31.Text='' then showmessage(' 输入上传数组号!')
- else begin
- point:=strtoint(edit31.Text);
- zuhao:=point;
- button24.Click;
- TIMEDELAY(1000);
- if edit30.Text='' then showmessage('数组数目上传失败!')
- else begin
- p:=strtoint(edit30.text);
- // f:= inputbox('输入','输入数组号','0');
- //point:=strtoint(inputbox('输入','输入数组号','0'));
- if (zuhao<0 )and (zuhao>100) then showmessage('数组号输入非法!')
- else begin
- if zuhao>p then showmessage('目前有'+inttostr(p)+'组数,请重新输入!')
- else begin //send data
- setlength(arr,7);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $02; //length
- arr[3]:=$a3; //cid
- arr[4]:=point; //datainfo
- xornum:= arr[2] xor arr[3] xor arr[4];
- arr[5]:=xornum;
- arr[6]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer14.Enabled:=true;
- end ;
- // end;
- end ;
- end ;
- end;
- //showmessage('hex:point'+f);
- //end;
- end else begin
- if combobox2.ItemIndex=1 then
- begin
- point:=$00;
- edit30.Clear;
- edit29.Clear;
- end;
- if combobox2.ItemIndex=2 then point:=$0ff ;
- setlength(arr,7);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $02; //length
- arr[3]:=$a3; //cid
- arr[4]:=point; //datainfo
- xornum:= arr[2] xor arr[3] xor arr[4];
- arr[5]:=xornum;
- arr[6]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer14.Enabled:=true;
- end;
- end;
- end;
- end;
- //end;
- procedure TForm1.Timer14Timer(Sender: TObject);
- var
- i,n,m,chksum:integer;
- arr:array of byte;
- tmpvar:variant;
- tp,tph,tpl:integer;
- begin
- arr:=nil;
- chksum:=0;
- timesum:=timesum+integer(timer14.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer14.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.Input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- if arr[2]<>n-5 then showmessage('长度错误!') else //长度校验
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (chksum=arr[n-2])and(arr[3]=$a3) then begin
- if combobox2.ItemIndex=2 then begin
- edit27.Clear;
- edit28.Clear;
- edit29.Clear;
- edit30.Clear;
- edit30.Text:=inttostr(arr[4]);
- end else begin
- tp:=arr[4] and $f0 ;
- tph:=strtoint(floattostr(tp/16));
- tpl:=arr[4]and $0f;
- case tph of
- 0: begin label11.Caption:='mw';
- if arr[6]>127 then begin
- case tpl of
- 0: edit28.text:=formatfloat('0.000', -((arr[6]-128)*256+arr[7])/1000.0);
- 1: edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
- 2:edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/10.0);
- 3: edit28.text:=formatfloat('0.00', -(arr[6]-128)*256+arr[7]);
- end;
- // edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
- timesum:=100;
- end
- else begin
- case tpl of
- 0: edit28.text:=formatfloat('0.000', (arr[6]*256+arr[7])/1000.0);
- 1: edit28.text:=formatfloat('0.00', (arr[6]*256+arr[7])/100.0);
- 2:edit28.text:=formatfloat('0.00',(arr[6]*256+arr[7])/10.0);
- 3: edit28.text:=formatfloat('0.00',arr[6]*256+arr[7]);
- end;
- end;
- end;
- 1: begin label11.Caption:='uw'; if arr[6]>127 then begin
- case tpl of
- 0: edit28.text:=formatfloat('0.000', -((arr[6]-128)*256+arr[7])/1000.0);
- 1: edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
- 2:edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/10.0);
- 3: edit28.text:=formatfloat('0.00', -(arr[6]-128)*256+arr[7]);
- end;
- // edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
- timesum:=100;
- end
- else begin
- case tpl of
- 0: edit28.text:=formatfloat('0.000', (arr[6]*256+arr[7])/1000.0);
- 1: edit28.text:=formatfloat('0.00', (arr[6]*256+arr[7])/100.0);
- 2:edit28.text:=formatfloat('0.00',(arr[6]*256+arr[7])/10.0);
- 3: edit28.text:=formatfloat('0.00',arr[6]*256+arr[7]);
- end;
- end;
- end;
- 2:begin label11.Caption:='nw'; if arr[6]>127 then begin
- case tpl of
- 0: edit28.text:=formatfloat('0.000', -((arr[6]-128)*256+arr[7])/1000.0);
- 1: edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
- 2:edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/10.0);
- 3: edit28.text:=formatfloat('0.00', -(arr[6]-128)*256+arr[7]);
- end;
- // edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
- timesum:=100;
- end
- else begin
- case tpl of
- 0: edit28.text:=formatfloat('0.000', (arr[6]*256+arr[7])/1000.0);
- 1: edit28.text:=formatfloat('0.00', (arr[6]*256+arr[7])/100.0);
- 2:edit28.text:=formatfloat('0.00',(arr[6]*256+arr[7])/10.0);
- 3: edit28.text:=formatfloat('0.00',arr[6]*256+arr[7]);
- end;
- end;
- end;
- 4: begin label11.Caption:='dBm'; if arr[6]>127 then begin
- case tpl of
- 0: edit28.text:=formatfloat('0.000', -((arr[6]-128)*256+arr[7])/1000.0);
- 1: edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
- 2:edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/10.0);
- 3: edit28.text:=formatfloat('0.00', -(arr[6]-128)*256+arr[7]);
- end;
- // edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
- timesum:=100;
- end
- else begin
- case tpl of
- 0: edit28.text:=formatfloat('0.000', (arr[6]*256+arr[7])/1000.0);
- 1: edit28.text:=formatfloat('0.00', (arr[6]*256+arr[7])/100.0);
- 2:edit28.text:=formatfloat('0.00',(arr[6]*256+arr[7])/10.0);
- 3: edit28.text:=formatfloat('0.00',arr[6]*256+arr[7]);
- end;
- end;
- end;
- 8: showmessage('单位为dB,请调整单位!');
- 9: showmessage('超范围!');
- end;
- case arr[5] of
- 0: edit27.text:='1310';
- 1: edit27.Text:='1550';
- 2: edit27.Text:='850';
- 3:edit27.Text:='980';
- end;
- { if arr[6]>127 then begin
- case tpl of
- 0: edit28.text:=formatfloat('0.000', -((arr[6]-128)*256+arr[7])/1000.0);
- 1: edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
- 2:edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/10.0);
- 3: edit28.text:=formatfloat('0.00', -(arr[6]-128)*256+arr[7]);
- end;
- // edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
- timesum:=100;
- end
- else begin
- case tpl of
- 0: edit28.text:=formatfloat('0.000', (arr[6]*256+arr[7])/1000.0);
- 1: edit28.text:=formatfloat('0.00', (arr[6]*256+arr[7])/100.0);
- 2:edit28.text:=formatfloat('0.00',(arr[6]*256+arr[7])/10.0);
- 3: edit28.text:=formatfloat('0.00',arr[6]*256+arr[7]);
- end;
- end; }
- if combobox2.ItemIndex=3 then begin
- edit29.Clear;
- edit29.text:=inttostr(zuhao);
- //edit31.Visible:=false;
- //label16.Visible:=false;
- end;
- end;
- //end;
- //end;
- end else begin
- timer14.Enabled:=false;
- showmessage('帧校验错误!');
- end;
- end;
- end else begin
- timer14.Enabled:=false;
- showmessage('响应数据错误!');
- end;
- end else begin
- sleep(10);
- timer14.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer14.Enabled:=false;
- showmessage('响应超时!');
- end;
- end;
- procedure TForm1.Button28Click(Sender: TObject);
- var
- text:textfile;
- begin
- if edit1.Text<>'' then begin
- if zuhao<>-1 then begin
- if savedialog1.Execute then begin
- savedialog1.FileName:=edit1.Text+'上传参数存储'+'.txt';
- if fileexists(savedialog1.FileName) then
- begin
- assignfile(text,savedialog1.FileName);
- append(text);
- try
- writeln(text,'第',zuhao,'组',' ',edit27.text,' ',edit28.text,' ');
- flush(text);
- finally
- closefile(text);
- end;
- flag:=true;
- end
- else begin
- assignfile(text,savedialog1.FileName);
- rewrite(text);
- try
- writeln(text,'存储数据组号 '+'通道0 '+' 通道5'+' 1310nm'+' 1550nm'+' 850nm'+' 980nm');
- writeln(text,'第',zuhao,'组',' ',edit27.text,' ',edit28.text,' ');
- finally
- closefile(text);
- end;
- flag:=true;
- end;
- end ;
- end else begin
- showmessage('未选择数据组号!');
- end;
- end else begin
- showmessage('先输入机器编号!');
- end;
- end;
- procedure TForm1.Button19Click(Sender: TObject);
- var
- v,len,i,count:integer;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- f:real;
- p:string;
- begin
- //P:=0;
- arr:=nil;
- f:=0;
- if not mscomm1.PortOpen then
- begin
- showmessage('串口没有打开!');
- exit;
- end;
- if (edit2.Text='')or(edit5.Text='')or(edit8.Text='')or(edit11.Text='')or(edit14.Text='')or(edit17.Text='') then
- begin
- showmessage('请先计算设定值');
- exit;
- end
- else
- begin
- ////////////////////////////////////////
- //hao add
- if not TsInputVal(edit2.Text) then
- begin
- edit2.SetFocus;
- exit
- end;
- if not TsInputVal(edit5.Text) then
- begin
- edit5.SetFocus;
- exit
- end;
- if not TsInputVal(edit8.Text) then
- begin
- edit8.SetFocus;
- exit
- end;
- if not TsInputVal(edit11.Text) then
- begin
- edit11.SetFocus;
- exit
- end;
- if not TsInputVal(edit14.Text) then
- begin
- edit14.SetFocus;
- exit
- end;
- if not TsInputVal(edit17.Text) then
- begin
- edit17.SetFocus;
- exit
- end;
- //hao add end
- setlength(arr,9);
- if tag=0 then begin
- f:=strtofloat(edit2.text);
- success:=$00;
- end;
- if tag=1 then begin
- f:=strtofloat(edit5.text);
- success:=$01;
- end;
- if tag=2 then begin
- f:=strtofloat(edit8.text);
- success:=$02;
- end;
- if tag=3 then begin
- f:=strtofloat(edit11.text);
- success:=$03;
- end;
- if tag=4 then begin
- f:=strtofloat(edit14.text);
- success:=$04;
- end;
- if tag=5 then begin
- f:=strtofloat(edit17.text);
- success:=$05;
- end;
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $04; //length
- arr[3]:=$a1; //cid
- arr[4]:=success;
- p:=floattostr(f*1000);
- v:=strtoint(p); //datainfo
- arr[5]:=v div 256;
- arr[6]:= v mod 256 ;
- xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
- arr[7]:=xornum;
- arr[8]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer15.Enabled:=true;
- end;
- ///////////////////////////////////////
- end;
- procedure TForm1.Timer15Timer(Sender: TObject);
- var
- i,n,m,chksum:integer;
- arr:array of byte;
- tmpvar:variant;
- begin
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer15.Interval)+10;
- if timesum<900 then
- begin
- //application.ProcessMessages;
- if mscomm1.InBufferCount>0 then begin
- timer15.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
- if arr[n-3]=$0cc then begin
- {if tag>6 then begin
- tag:=0;
- showmessage('参数设定成功!');
- end else begin }
- tag:=tag+1;
- if tag>5 then begin
- tag:=0;
- showmessage('参数设定成功!');
- timer15.Enabled:=false;
- end else begin
- //timer15.Enabled:=false;
- button19.Click;
- end;
- end
- else if arr[n-3]=$66 then begin
- timer15.Enabled:=false;
- showmessage('设置失败!');
- //p:=p+1;
- end ;
- end else
- begin
- showmessage('帧校验错误!'); //帧校验错误
- timer15.Enabled:=false;
- //p:=p+1;
- end;
- end else begin
- showmessage('响应数据头错误!');
- timer15.Enabled:=false;
- //P:=p+1;
- end;
- end else begin
- sleep(10);
- timer15.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer15.Enabled:=false;
- // P:=p+1;
- // button19.Click;
- // showmessage('通道0参数设定时响应超时!');
- showmessage('参数设定失败!,请重试!');
- end;
- {if tag>6 then begin
- tag:=0;
- /showmessage('参数设定成功!');
- end ; }
- end;
- procedure TForm1.Button20Click(Sender: TObject);
- var
- //f,
- len,i,count:integer;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- begin
- arr:=nil;
- if not mscomm1.PortOpen then
- begin
- showmessage('串口没有打开!');
- end else begin
- ////////////////////////////////////////
- setlength(arr,7);
- if tagc=0 then begin
- // f:=strtoint(edit2.text);
- success:=$00;
- end;
- if tagc=1 then begin
- //f:=strtoint(edit5.text);
- success:=$01;
- end;
- if tagc=2 then begin
- // f:=strtoint(edit8.text);
- success:=$02;
- end;
- if tagc=3 then begin
- // f:=strtoint(edit11.text);
- success:=$03;
- end;
- if tagc=4 then begin
- // f:=strtoint(edit14.text);
- success:=$04;
- end;
- if tagc=5 then begin
- // f:=strtoint(edit17.text);
- success:=$05;
- end;
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $02; //length
- arr[3]:=$a2; //cid
- arr[4]:=success; //datainfo
- // arr[5]:=f div 256;
- // arr[6]:= f mod 256 ;
- xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
- arr[5]:=xornum;
- arr[6]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer16.Enabled:=true;
- end;
- ///////////////////////////////////////
- //end else begin
- //showmessage('请先计算设定值!');
- //end;
- end;
- procedure TForm1.Timer16Timer(Sender: TObject);
- var
- i,n,m,chksum:integer; //,timesum
- arr:array of byte;
- tmpvar:variant;
- a:real;
- begin
- arr:=nil;
- chksum:=$00;
- timesum:=timesum+integer(timer16.Interval)+10;
- if timesum<900 then
- begin
- if mscomm1.InBufferCount>0 then begin
- timer16.Enabled:=false;
- timesum:=100;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a2) then begin
- //edit4.Text:=inttostr(arr[4]*256+arr[5]);
- //if (arr[n-3]=$0cc)or(arr[n-3]=$66) then begin
- //showmessage('设置成功!') ;
- if arr[4]>127 then begin
- a:=-((arr[4]-128)*256+arr[5])/1000.0;
- end else begin
- a:=(arr[4]*256+arr[5])/1000.0;
- end;
- case tagc of
- $00:edit2.Text:=formatfloat('0.000',a);
- $01:edit5.Text:=formatfloat('0.000',a);
- $02:edit8.Text:=formatfloat('0.000',a);
- $03:edit11.Text:=formatfloat('0.000',a);
- $04:edit14.Text:=formatfloat('0.000',a);
- $05:edit17.Text:=formatfloat('0.000',a);
- end;
- // pc:=0 ;
- //tagc:=tagc+1;
- if tagc>5 then begin
- tagc:=0;
- showmessage('参数回读完毕!');
- if edit20.Text= edit2.Text then
- checkbox1.Checked:=true else checkbox1.Checked:=false;
- if edit21.Text= edit5.Text then
- checkbox2.Checked:=true else checkbox2.Checked:=false;
- if edit22.Text= edit8.Text then
- checkbox3.Checked:=true else checkbox3.Checked:=false;
- if edit23.Text= edit11.Text then
- checkbox4.Checked:=true else checkbox4.Checked:=false;
- if edit24.Text= edit14.Text then
- checkbox5.Checked:=true else checkbox5.Checked:=false;
- if edit25.Text= edit17.Text then
- checkbox6.Checked:=true else checkbox6.Checked:=false;
- end else begin
- tagc:=tagc+1;
- button20.Click;
- end ;
- end;
- end else
- begin
- end;
- end else begin
- sleep(10);
- timer16.Enabled:=true;
- end;
- end else begin
- timesum:=100;
- timer16.Enabled:=false;
- showmessage('参数回读失败,请重试!');
- end;
- end;
- procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- var
- closeconfirm:integer;
- begin
- closeconfirm:=messagedlg('您确定要退出吗?',mtconfirmation,[mbyes,mbno],0);
- canclose:=(closeconfirm=mryes);
- end;
- procedure TForm1.ComboBox1Change(Sender: TObject);
- begin
- if mscomm1.PortOpen then
- begin
- //mscomm1.PortOpen:=false;
- //shape1.Brush.Color:=clred;
- //button22.Caption:='连接';
- //if tstr=combobox1.Items.Text then
- if tindexnum<>combobox1.ItemIndex then begin
- mscomm1.PortOpen:=false;
- shape1.Brush.Color:=clred;
- button22.Caption:='连接';
- statusbar1.Panels[0].Text:='串口com'+inttostr(tindexnum+1)+'已断开';
- combobox2.ItemIndex:=0;
- label8.Visible:=false;
- label9.Visible:=false;
- label10.Visible:=false;
- label11.Visible:=false;
- label12.Visible:=false;
- label13.Visible:=false;
- label14.Visible:=false;
- label15.Visible:=false;
- label16.Visible:=false;
- edit29.Visible:=false;
- edit30.Visible:=false;
- edit27.Visible:=false;
- edit28.Visible:=false;
- // else statusbar1.Panels[0].Text:='串口com'+inttostr(combobox1.ItemIndex+1)+'已断开';
- end ;
- end else statusbar1.Panels[0].Text:='';
- end;
- procedure TForm1.ComboBox2Change(Sender: TObject);
- begin
- if combobox2.ItemIndex=1 then begin
- label8.Visible:=true;
- label9.Visible:=true;
- label10.Visible:=true;
- label11.Visible:=true;
- label12.Visible:=false;
- label13.Visible:=false;
- label14.Visible:=false;
- label15.Visible:=false;
- label16.Visible:=false;
- edit27.Visible:=true;
- edit27.Clear;
- edit28.Visible:=true;
- edit28.Clear;
- edit29.Visible:=false;
- edit29.Clear;
- edit30.Clear;
- edit30.Visible:=false;
- edit31.Clear;
- edit31.Visible:=false;
- end;
- if combobox2.ItemIndex=2 then begin
- label14.Visible:=true;
- label15.Visible:=true;
- edit30.Visible:=true;
- label8.Visible:=false;
- label9.Visible:=false;
- label10.Visible:=false;
- label11.Visible:=false;
- label12.Visible:=false;
- label13.Visible:=false;
- edit27.Clear;
- edit28.Clear;
- edit29.Clear;
- edit30.Clear;
- edit31.Clear;
- edit27.Visible:=false;
- edit28.Visible:=false;
- edit29.Visible:=false;
- edit31.Visible:=false;
- label16.Visible:=false;
- end;
- if combobox2.ItemIndex=3 then begin
- edit31.Visible:=true;
- label16.Visible:=true;
- label8.Visible:=true;
- label9.Visible:=true;
- label10.Visible:=true;
- label11.Visible:=true;
- label12.Visible:=false;
- label13.Visible:=false;
- edit27.Clear;
- edit28.Clear;
- edit29.Clear;
- edit30.Clear;
- edit31.Clear;
- edit27.Visible:=true;
- edit28.Visible:=true;
- label14.Visible:=true;
- label15.Visible:=true;
- edit30.Visible:=true;
- end;
- if combobox2.ItemIndex=0 then begin
- label8.Visible:=false;
- label9.Visible:=false;
- label10.Visible:=false;
- label11.Visible:=false;
- label12.Visible:=false;
- label13.Visible:=false;
- label14.Visible:=false;
- label15.Visible:=false;
- label16.Visible:=false;
- edit27.Clear;
- edit28.Clear;
- edit29.Clear;
- edit30.Clear;
- edit31.Clear;
- edit27.Visible:=false;
- edit28.Visible:=false;
- edit29.Visible:=false;
- edit30.Visible:=false;
- edit31.Visible:=false;
- end;
- end;
- procedure TForm1.Button23Click(Sender: TObject);
- var
- len,i,count:integer;
- //tmpstr:string;
- tmpvar:variant;
- xornum:byte;
- arr:array of byte;
- begin
- arr:=nil;
- if not mscomm1.PortOpen then begin
- showmessage('串口没有打开!');
- end else begin
- setlength(arr,7);
- // f:=strtoint(edit2.text);
- arr[0]:=$7e; //soi
- arr[1]:=$10; //ver
- arr[2]:= $07; //length
- arr[3]:=$a3; //cid
- arr[4]:=$80; //datainfo
- arr[5]:=$00;
- arr[6]:=230 ;//div 255
- arr[7]:=201 ; //f mod 255 ;
- xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5] xor arr[6] xor arr[7];// xor arr[5]xor arr[6];
- arr[8]:=xornum;
- arr[9]:=$0d;
- // send data
- len:=length(arr);
- i:=0;
- count:=0;
- tmpvar:=vararraycreate([0,0],varbyte);
- //tmpvar[count]:=arr[i];
- //inc(count);
- //inc(i);
- while(count<=len-1)do begin
- tmpvar[count]:=arr[i];
- inc(count);
- inc(i);
- vararrayredim(tmpvar,count);
- end;
- MSComm1.Output:=tmpvar;
- timer7.Enabled:=true;
- end;
- {if mscomm1.InBufferCount>0 then begin
- timer7.Enabled:=false;
- n:=mscomm1.InBufferCount;
- setlength(arr,n);
- tmpvar:=mscomm1.input;
- for i:=0 to n-1 do arr[i]:=tmpvar[i];
- if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
- begin
- for m:=2 to (n-3) do chksum:=chksum xor arr[m];
- if (arr[n-2]=chksum)and(arr[3]=$a3) then begin
- if arr[5]<127 then begin
- xy := (arr[5]*256+arr[6])/100.0 ;
- edit4.Text:=floattostr(xy);//inttostr(arr[5]*256+arr[6]);
- showmessage('回读成功!');
- //tag:=true;
- end else begin
- xy := -((arr[5]-128)*256+arr[6])/100.0 ;
- edit4.Text:=floattostr(xy);//inttostr(-((arr[5]-128)*256+arr[6]));
- showmessage('回读成功!');
- //tag:=true;
- end;
- end else
- showmessage('帧校验错误!'); //帧校验错误
- end else
- showmessage('响应数据错误!');
- end else begin
- sleep(10);
- timer7.Enabled:=true;
- end;
- end else begin
- showmessage('响应超时!');
- timesum:=100;
- end; }
- //while mscomm1.InBufferCount
- end;
- end.
English
