mainform.pas
上传用户:jitai139
上传日期:2013-04-11
资源大小:1244k
文件大小:122k
开发平台:

Delphi

  1. unit mainform;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls, ExtCtrls, ComCtrls,math;
  6. type
  7.   TForm1 = class(TForm)
  8.     Panel1: TPanel;
  9.     GroupBox1: TGroupBox;
  10.     Edit1: TEdit;
  11.     GroupBox2: TGroupBox;
  12.     Label1: TLabel;
  13.     Label2: TLabel;
  14.     Label3: TLabel;
  15.     Label4: TLabel;
  16.     Label5: TLabel;
  17.     Label6: TLabel;
  18.     Edit2: TEdit;
  19.     Edit3: TEdit;
  20.     Edit4: TEdit;
  21.     Edit5: TEdit;
  22.     Edit6: TEdit;
  23.     Edit7: TEdit;
  24.     Edit8: TEdit;
  25.     Edit9: TEdit;
  26.     Edit10: TEdit;
  27.     Edit11: TEdit;
  28.     Edit12: TEdit;
  29.     Edit13: TEdit;
  30.     Edit14: TEdit;
  31.     Edit15: TEdit;
  32.     Edit16: TEdit;
  33.     Edit17: TEdit;
  34.     Edit18: TEdit;
  35.     Edit19: TEdit;
  36.     Button1: TButton;
  37.     Button2: TButton;
  38.     Button3: TButton;
  39.     Button4: TButton;
  40.     Button5: TButton;
  41.     Button6: TButton;
  42.     Button7: TButton;
  43.     Button8: TButton;
  44.     Button9: TButton;
  45.     Button10: TButton;
  46.     Button11: TButton;
  47.     Button12: TButton;
  48.     Button13: TButton;
  49.     Button14: TButton;
  50.     Button15: TButton;
  51.     Button16: TButton;
  52.     Button17: TButton;
  53.     Button18: TButton;
  54.     Edit20: TEdit;
  55.     Edit21: TEdit;
  56.     Edit22: TEdit;
  57.     Edit23: TEdit;
  58.     Edit24: TEdit;
  59.     Edit25: TEdit;
  60.     Button19: TButton;
  61.     Button20: TButton;
  62.     Button21: TButton;
  63.     GroupBox3: TGroupBox;
  64.     ComboBox1: TComboBox;
  65.     Button22: TButton;
  66.     GroupBox4: TGroupBox;
  67.     Edit26: TEdit;
  68.     Label7: TLabel;
  69.     Button24: TButton;
  70.     GroupBox5: TGroupBox;
  71.     ComboBox2: TComboBox;
  72.     Edit27: TEdit;
  73.     Edit28: TEdit;
  74.     Button25: TButton;
  75.     MSComm1: TMSComm;
  76.     StatusBar1: TStatusBar;
  77.     Timer1: TTimer;
  78.     Button26: TButton;
  79.     OpenDialog1: TOpenDialog;
  80.     SaveDialog1: TSaveDialog;
  81.     Button27: TButton;
  82.     Timer2: TTimer;
  83.     Timer3: TTimer;
  84.     Timer4: TTimer;
  85.     Timer5: TTimer;
  86.     Timer6: TTimer;
  87.     Timer7: TTimer;
  88.     Timer8: TTimer;
  89.     Timer9: TTimer;
  90.     Timer10: TTimer;
  91.     Timer11: TTimer;
  92.     Timer12: TTimer;
  93.     Timer13: TTimer;
  94.     Timer14: TTimer;
  95.     Button28: TButton;
  96.     SaveDialog2: TSaveDialog;
  97.     Shape1: TShape;
  98.     Timer15: TTimer;
  99.     Timer16: TTimer;
  100.     Label8: TLabel;
  101.     Label9: TLabel;
  102.     Label10: TLabel;
  103.     Memo1: TMemo;
  104.     CheckBox1: TCheckBox;
  105.     CheckBox2: TCheckBox;
  106.     CheckBox3: TCheckBox;
  107.     CheckBox4: TCheckBox;
  108.     CheckBox5: TCheckBox;
  109.     CheckBox6: TCheckBox;
  110.     Label12: TLabel;
  111.     Edit29: TEdit;
  112.     Label13: TLabel;
  113.     Label14: TLabel;
  114.     Edit30: TEdit;
  115.     Label15: TLabel;
  116.     Edit31: TEdit;
  117.     Label16: TLabel;
  118.     ComboBox3: TComboBox;
  119.     ComboBox4: TComboBox;
  120.     ComboBox5: TComboBox;
  121.     ComboBox6: TComboBox;
  122.     ComboBox7: TComboBox;
  123.     ComboBox8: TComboBox;
  124.     Label17: TLabel;
  125.     Label18: TLabel;
  126.     Label19: TLabel;
  127.     Label20: TLabel;
  128.     Label21: TLabel;
  129.     Label22: TLabel;
  130.     Button23: TButton;
  131.     Label11: TLabel;
  132.     procedure Button22Click(Sender: TObject);
  133.     procedure Button3Click(Sender: TObject);
  134.     procedure Button6Click(Sender: TObject);
  135.     procedure Button9Click(Sender: TObject);
  136.     procedure Button12Click(Sender: TObject);
  137.     procedure Button15Click(Sender: TObject);
  138.     procedure Button18Click(Sender: TObject);
  139.     procedure Button2Click(Sender: TObject);
  140.     procedure Timer1Timer(Sender: TObject);
  141.     procedure FormCreate(Sender: TObject);
  142.     procedure Button26Click(Sender: TObject);
  143.     procedure Button27Click(Sender: TObject);
  144.     procedure Button5Click(Sender: TObject);
  145.     procedure Button8Click(Sender: TObject);
  146.     procedure Button11Click(Sender: TObject);
  147.     procedure Button14Click(Sender: TObject);
  148.     procedure Button17Click(Sender: TObject);
  149.     procedure Timer2Timer(Sender: TObject);
  150.     procedure Timer3Timer(Sender: TObject);
  151.     procedure Timer4Timer(Sender: TObject);
  152.     procedure Timer5Timer(Sender: TObject);
  153.     procedure Timer6Timer(Sender: TObject);
  154.     procedure Button21Click(Sender: TObject);
  155.     procedure Button1Click(Sender: TObject);
  156.     procedure Timer7Timer(Sender: TObject);
  157.     procedure Button4Click(Sender: TObject);
  158.     procedure Button7Click(Sender: TObject);
  159.     procedure Button10Click(Sender: TObject);
  160.     procedure Button13Click(Sender: TObject);
  161.     procedure Button16Click(Sender: TObject);
  162.     procedure Timer8Timer(Sender: TObject);
  163.     procedure Timer9Timer(Sender: TObject);
  164.     procedure Timer10Timer(Sender: TObject);
  165.     procedure Timer11Timer(Sender: TObject);
  166.     procedure Timer12Timer(Sender: TObject);
  167.     procedure Button24Click(Sender: TObject);
  168.     procedure Timer13Timer(Sender: TObject);
  169.     procedure Button25Click(Sender: TObject);
  170.     procedure Timer14Timer(Sender: TObject);
  171.     procedure Button28Click(Sender: TObject);
  172.     procedure Button19Click(Sender: TObject);
  173.     procedure Timer15Timer(Sender: TObject);
  174.     procedure Button20Click(Sender: TObject);
  175.     procedure Timer16Timer(Sender: TObject);
  176.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  177.     procedure ComboBox1Change(Sender: TObject);
  178.     procedure ComboBox2Change(Sender: TObject);
  179.     procedure Button23Click(Sender: TObject);
  180.    
  181.    // function setvar(tag:boolean;btn:tbutton):integer;
  182.   private
  183.     { Private declarations }
  184.       function TsInputVal(staStr:string):boolean;
  185.   public
  186.     { Public declarations }
  187.    timesum,tag,success,p,tagc,pc:integer;
  188.    flag:boolean;
  189.    zuhao:integer;
  190.    tindexnum:integer;
  191.   end;
  192. var
  193.   Form1: TForm1;
  194. implementation
  195.   //uses sysutils;
  196. {$R *.dfm}
  197. {function setvar(tag:boolean;btn:tbutton):integer;
  198. var
  199. i:integer;
  200.   begin
  201.   i:=-1;
  202.   while tag<>true do begin
  203.     if (edit2.)or()or()or()or()or()
  204.                        btn.Click;
  205.                      end;
  206.   i:=1  ;
  207.    tag:=false;
  208.    result:= i;
  209.  end;  }
  210.  //function  senddata(cid:integer) :boolean;
  211.  function TForm1.TsInputVal(staStr:string):boolean;
  212.   var
  213.     flag1,flag2:boolean ;
  214.     f:real;
  215.   begin
  216.     f:=strToFloat(staStr);
  217.     if f>=0.0000 then
  218.        flag1:=true
  219.     else
  220.        flag1:=false;
  221.     if  f>9.999001 then
  222.         flag2:=false
  223.     else
  224.        flag2:=true;
  225.     if flag1 and flag2 then
  226.        begin
  227.         result:=true;
  228.         exit;
  229.        end
  230.      else
  231.        begin
  232.          showmessage('输入或所得的设定值非法!!--范围在:0.000~9.999 之间。');
  233.          result:=false;
  234.        end;
  235. end;
  236.  PROCEDURE TIMEDELAY(DT:DWORD);                  //延时程序 timedelay(sencond)
  237.   VAR
  238.     TT:DWORD;
  239.   begin
  240.     //取得现在的TICK值
  241.     TT:=GetTickCount();
  242.     //计算TICK差值是否超过设置之
  243.   while GetTickCount()-TT<DT do
  244.    APPLICATION.ProcessMessages;//释放控制权
  245.   end;
  246.   function hex(c:char):integer;                  //16进制转换
  247. var
  248. x:integer;
  249. begin
  250.     if c='' then
  251.       x:=0
  252.       else if (ord(c)>=ord('0'))and(ord(c)<=ord('9')) then
  253.       x:=ord(c)-ord('0')
  254.       else if (ord(c)>=ord('a'))and(ord(c)<=ord('f')) then
  255.       x:=ord(c)-ord('a')+10
  256.       else if (ord(c)>=ord('A'))and(ord(c)<=ord('F')) then
  257.       x:=ord(c)-ord('A')+10
  258.       else
  259.       x:=-1;
  260.      result:=x;
  261. end;
  262. function hextoint(s:string):integer ;                  //16进制toINT
  263. var
  264.   tmpstr1,tmpstr2:integer;
  265. begin
  266.  if length(s)=1 then
  267.   begin
  268.      result:=hex(s[1]);
  269.   end
  270.   else if length(s)=2 then
  271.   begin
  272.   tmpstr1:=hex(s[1]) ;
  273.   tmpstr2:=hex(s[2]);
  274.     if(tmpstr1=-1)and(tmpstr2=-1) then
  275.     result:=-1
  276.     else
  277.     result:=tmpstr1*16+tmpstr2;
  278.    end
  279.    else
  280.     result:=-1;
  281. end;
  282. procedure TForm1.Button22Click(Sender: TObject);       //open the serial port
  283. begin
  284.    if  not mscomm1.PortOpen then
  285.     begin
  286.           mscomm1.CommPort:=combobox1.ItemIndex+1;
  287.          tindexnum:= combobox1.ItemIndex;
  288.       mscomm1.Settings:='2400,n,8,1';
  289.            mscomm1.PortOpen:=true;
  290.            statusbar1.Panels[0].Text:='串口com'+inttostr(combobox1.ItemIndex+1)+'已打开';
  291.            shape1.Brush.Color:=clgreen;
  292.            button22.Caption:='断开';
  293.     end else
  294.     begin
  295.        mscomm1.PortOpen:=false;
  296.            shape1.Brush.Color:=clred;
  297.             tindexnum:= combobox1.ItemIndex;
  298.            statusbar1.Panels[0].Text:='串口com'+inttostr(combobox1.ItemIndex+1)+'已关闭';
  299.            button22.Caption:='连接';
  300.              edit4.Text:='';
  301.    edit7.Text:='';
  302.    edit10.Text:='';
  303.    edit13.Text:='';
  304.    edit16.Text:='';
  305.    edit19.Text:='';
  306.    combobox2.ItemIndex:=0;
  307.    label8.Visible:=false;
  308.  label9.Visible:=false;
  309.  label10.Visible:=false;
  310. label11.Visible:=false;
  311.  label12.Visible:=false;
  312.  label13.Visible:=false;
  313.  label14.Visible:=false;
  314.  label15.Visible:=false;
  315.  label16.Visible:=false;
  316.  edit27.Visible:=false;
  317.  edit28.Visible:=false;
  318.  edit29.Visible:=false;
  319.  edit30.Visible:=false;
  320.   edit31.Visible:=false;
  321.     end;
  322.     // mscomm1.CommPort:=combobox1.ItemIndex+1;
  323.       //mscomm1.Settings:='2400,n,8,1';
  324.      // mscomm1.PortOpen:=true;
  325.       //statusbar1.Panels[0].Text:='serial was open';
  326.       //shape1.Brush.Color:=clgreen;
  327.       //edit3.Text:='';
  328.   edit4.Text:='';
  329.  // edit6.Text:='';
  330.    edit7.Text:='';
  331.   // edit9.Text:='';
  332.    edit10.Text:='';
  333.   // edit12.Text:='';
  334.    edit13.Text:='';
  335.    //edit15.Text:='';
  336.    edit16.Text:='';
  337.   // edit18.Text:='';
  338.    edit19.Text:='';
  339. end;
  340. procedure TForm1.Button3Click(Sender: TObject);
  341. var
  342.   a,b:real;
  343.   c: real;
  344.  m,n:variant;
  345.  str1:string;
  346.  ll:integer;
  347. begin
  348. c:=0.00;
  349.   if (edit3.Text<>'') and (edit4.Text<>'') then
  350.   begin
  351.    {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  352.  begin
  353.  showmessage('数值超出合理范围(-45.00~+25.00)');     /////////////////////////////////
  354.  edit3.Text:='';
  355.   end else begin }
  356.        str1:=label17.Caption;
  357.   if str1='dBm' then  begin
  358.       a:=strtofloat(edit4.Text);
  359.       n:=a;
  360.       a:=power(10,a/10.0);              //dbm to mw
  361.       a:=a*1000.0;                       //mw to uw
  362.       b:=strtofloat(edit3.Text);
  363.       ll:=combobox3.ItemIndex;
  364.       case ll of
  365.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  366.          1:b:= b*1000.0;
  367.          2:b:= b;
  368.          3:b:= b/1000.0 ;
  369.          end;
  370.                c:= b/ a;
  371.   edit2.Text:=formatfloat('0.000',c);
  372.   end;
  373.   if str1='uw' then begin
  374.       a:=strtofloat(edit4.Text);
  375.       n:=a;
  376.      // m:=m;
  377.       b:=strtofloat(edit3.Text);
  378.      ll:=combobox3.ItemIndex;
  379.       case ll of
  380.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  381.          1:b:= b*1000.0;
  382.          2:b:= b;
  383.          3:b:= b/1000.0;
  384.          end;
  385.       c:= b/ a;
  386.   edit2.Text:=formatfloat('0.000',c);
  387.       end;
  388.       if str1='nw' then begin
  389.        a:=strtofloat(edit4.Text);
  390.       n:=a;
  391.       a:=a/1000.0;
  392.       b:=strtofloat(edit3.Text);
  393.       ll:=combobox3.ItemIndex;
  394.       case ll of
  395.         0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
  396.          1:b:= b*1000.0;
  397.          2:b:= b;
  398.          3:b:= b/1000.0;
  399.          end;
  400.       c:= b/ a;
  401.   edit2.Text:=formatfloat('0.000',c);
  402.       end;
  403.       if str1='mw' then begin
  404.         a:=strtofloat(edit4.Text);
  405.       n:=a;
  406.       a:=a*1000.0;
  407.       b:=strtofloat(edit3.Text);
  408.       ll:=combobox3.ItemIndex;
  409.       case ll of
  410.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  411.          1:b:= b*1000.0;
  412.          2:b:= b;
  413.          3:b:= b/1000.0;
  414.          end;
  415.          c:=b/a;
  416.   edit2.Text:=formatfloat('0.000',c);
  417. end;
  418.  // end;
  419.   end
  420.   else
  421.   begin
  422.       showmessage('请先输入正确的值!');
  423.       edit2.SetFocus;
  424.   end;
  425. end;
  426. procedure TForm1.Button9Click(Sender: TObject);
  427. var
  428.   a,b:real;
  429.   c: real;
  430.  m,n:variant;
  431.  str1:string;
  432.  ll:integer;
  433. begin
  434. c:=0.00;
  435.   if (edit9.Text<>'') and (edit10.Text<>'') then
  436.   begin  {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  437.  begin
  438.  showmessage('数值超出合理范围(-45.00~+25.00)');     /////////////////////////////////
  439.  edit3.Text:='';
  440.   end else begin }
  441.        str1:=label19.Caption;
  442.   if str1='dBm' then  begin
  443.       a:=strtofloat(edit10.Text);
  444.       n:=a;
  445.       a:=power(10,a/10.0);              //dbm to mw
  446.       a:=a*1000.0;                       //mw to uw
  447.       b:=strtofloat(edit9.Text);
  448.       ll:=combobox5.ItemIndex;
  449.       case ll of
  450.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  451.          1:b:= b*1000.0;
  452.          2:b:= b;
  453.          3:b:= b/1000.0
  454.          end;
  455.       c:= b/ a;
  456.   edit8.Text:=formatfloat('0.000',c);
  457.   end;
  458.   if str1='uw' then begin
  459.       a:=strtofloat(edit10.Text);
  460.       n:=a;
  461.      // m:=m;
  462.       b:=strtofloat(edit9.Text);
  463.      ll:=combobox5.ItemIndex;
  464.       case ll of
  465.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  466.          1:b:= b*1000.0;
  467.          2:b:= b;
  468.          3:b:= b/1000.0
  469.          end;
  470.       c:= b/ a;
  471.   edit8.Text:=formatfloat('0.000',c);
  472.       end;
  473.       if str1='nw' then begin
  474.        a:=strtofloat(edit10.Text);
  475.       n:=a;
  476.       a:=a/1000.0;
  477.       b:=strtofloat(edit9.Text);
  478.       ll:=combobox5.ItemIndex;
  479.       case ll of
  480.         0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
  481.          1:b:= b*1000.0;
  482.          2:b:= b;
  483.          3:b:= b/1000.0
  484.          end;
  485.       c:= b/ a;
  486.   edit8.Text:=formatfloat('0.000',c);
  487.       end;
  488.       if str1='mw' then begin
  489.         a:=strtofloat(edit10.Text);
  490.       n:=a;
  491.       a:=a*1000;
  492.       b:=strtofloat(edit9.Text);
  493.       ll:=combobox5.ItemIndex;
  494.       case ll of
  495.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  496.          1:b:= b*1000.0;
  497.          2:b:= b;
  498.          3:b:= b/1000.0
  499.          end;
  500.          c:=b/a;
  501.   edit8.Text:=formatfloat('0.000',c);
  502. end;
  503.  // end;
  504.   end
  505.   else
  506.   begin
  507.       showmessage('请先输入正确的值!');
  508.       edit8.setfocus;
  509.   end;
  510. end;
  511. procedure TForm1.Button6Click(Sender: TObject);
  512. var
  513.   a,b:real;
  514.   c: real;
  515.  m,n:variant;
  516.  str1:string;
  517.  ll:integer;
  518. begin
  519. c:=0.00;
  520.   if (edit6.Text<>'') and (edit7.Text<>'') then
  521.   begin  {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  522.  begin
  523.  showmessage('数值超出合理范围(-45.00~+25.00');     /////////////////////////////////
  524.  edit3.Text:='';
  525.   end else begin }
  526.        str1:=label18.Caption;
  527.   if str1='dBm' then  begin
  528.       a:=strtofloat(edit7.Text);
  529.      n:=a;
  530.       a:=power(10,a/10.0);              //dbm to mw
  531.       a:=a*1000.0;                       //mw to uw
  532.       b:=strtofloat(edit6.Text);
  533.       ll:=combobox4.ItemIndex;
  534.       case ll of
  535.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  536.          1:b:= b*1000.0;
  537.          2:b:= b;
  538.          3:b:= b/1000.0
  539.          end;
  540.       c:= b/ a;
  541.   edit5.Text:=formatfloat('0.000',c);
  542.   end;
  543.   if str1='uw' then begin
  544.       a:=strtofloat(edit7.Text);
  545.       n:=a;
  546.      // m:=m;
  547.       b:=strtofloat(edit6.Text);
  548.      ll:=combobox4.ItemIndex;
  549.       case ll of
  550.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  551.          1:b:= b*1000.0;
  552.          2:b:= b;
  553.          3:b:= b/1000.0
  554.          end;
  555.       c:= b/ a;
  556.   edit5.Text:=formatfloat('0.000',c);
  557.       end;
  558.       if str1='nw' then begin
  559.        a:=strtofloat(edit7.Text);
  560.       n:=a;
  561.       a:=a/1000.0;
  562.       b:=strtofloat(edit6.Text);
  563.       ll:=combobox4.ItemIndex;
  564.       case ll of
  565.         0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
  566.          1:b:= b*1000.0;
  567.          2:b:= b;
  568.          3:b:= b/1000.0
  569.          end;
  570.       c:= b/a;
  571.   edit5.Text:=formatfloat('0.000',c);
  572.       end;
  573.       if str1='mw' then begin
  574.         a:=strtofloat(edit7.Text);
  575.       n:=a;
  576.       a:=a*1000;
  577.       b:=strtofloat(edit6.Text);
  578.       ll:=combobox4.ItemIndex;
  579.       case ll of
  580.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  581.          1:b:= b*1000.0;
  582.          2:b:= b;
  583.          3:b:= b/1000.0
  584.          end;
  585.          c:=b/a;
  586.   edit5.Text:=formatfloat('0.000',c);
  587. end;
  588.  // end;
  589.   end
  590.   else
  591.   begin
  592.       showmessage('请先输入正确的值!');
  593.       edit5.SetFocus;
  594.   end;
  595. end;
  596.  procedure TForm1.Button12Click(Sender: TObject);
  597. var
  598.   a,b:real;
  599.   c: real;
  600.  m,n:variant;
  601.  str1:string;
  602.  ll:integer;
  603. begin
  604. c:=0.00;
  605.   if (edit12.Text<>'') and (edit13.Text<>'') then
  606.   begin  {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  607.  begin
  608.  showmessage('数值超出合理范围(-45.00~+25.00');     /////////////////////////////////
  609.  edit3.Text:='';
  610.   end else begin }
  611.        str1:=label20.Caption;
  612.   if str1='dBm' then  begin
  613.       a:=strtofloat(edit13.Text);
  614.       n:=a;
  615.       a:=power(10,a/10.0);              //dbm to mw
  616.       a:=a*1000.0;                       //mw to uw
  617.       b:=strtofloat(edit12.Text);
  618.       ll:=combobox6.ItemIndex;
  619.       case ll of
  620.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  621.          1:b:= b*1000.0;
  622.          2:b:= b;
  623.          3:b:= b/1000.0
  624.          end;
  625.       c:= b/ a;
  626.   edit11.Text:=formatfloat('0.000',c);
  627.   end;
  628.   if str1='uw' then begin
  629.       a:=strtofloat(edit13.Text);
  630.       n:=a;
  631.      // m:=m;
  632.       b:=strtofloat(edit12.Text);
  633.      ll:=combobox6.ItemIndex;
  634.       case ll of
  635.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  636.          1:b:= b*1000.0;
  637.          2:b:= b;
  638.          3:b:= b/1000.0
  639.          end;
  640.       c:= b/ a;
  641.   edit11.Text:=formatfloat('0.000',c);
  642.       end;
  643.       if str1='nw' then begin
  644.        a:=strtofloat(edit13.Text);
  645.       n:=a;
  646.       a:=a/1000.0;
  647.       b:=strtofloat(edit12.Text);
  648.       ll:=combobox6.ItemIndex;
  649.       case ll of
  650.         0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
  651.          1:b:= b*1000.0;
  652.          2:b:= b;
  653.          3:b:= b/1000.0
  654.          end;
  655.       c:= b/ a;
  656.   edit11.Text:=formatfloat('0.000',c);
  657.       end;
  658.       if str1='mw' then begin
  659.         a:=strtofloat(edit13.Text);
  660.       n:=a;
  661.       a:=a*1000;
  662.       b:=strtofloat(edit12.Text);
  663.       ll:=combobox6.ItemIndex;
  664.       case ll of
  665.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  666.          1:b:= b*1000.0;
  667.          2:b:= b;
  668.          3:b:= b/1000.0
  669.          end;
  670.          c:=b/a;
  671.   edit11.Text:=formatfloat('0.000',c);
  672. end;
  673.  // end;
  674.   end
  675.   else
  676.   begin
  677.       showmessage('请先输入正确的值!');
  678.       edit11.SetFocus;
  679.   end;
  680. end;
  681. procedure TForm1.Button15Click(Sender: TObject);
  682. var
  683.   a,b:real;
  684.   c: real;
  685.  m,n:variant;
  686.  str1:string;
  687.  ll:integer;
  688. begin
  689. c:=0.00;
  690.   if (edit15.Text<>'') and (edit16.Text<>'') then
  691.   begin  {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  692.  begin
  693.  showmessage('数值超出合理范围(-45.00~+25.00');
  694.  edit3.Text:='';
  695.   end else begin }
  696.        str1:=label21.Caption;
  697.   if str1='dBm' then  begin
  698.       a:=strtofloat(edit16.Text);
  699.       n:=a;
  700.       a:=power(10,n/10.0);              //dbm to mw
  701.       a:=a*1000.0;                       //mw to uw
  702.       b:=strtofloat(edit15.Text);
  703.       ll:=combobox7.ItemIndex;
  704.       case ll of
  705.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  706.          1:b:= b*1000.0;
  707.          2:b:= b;
  708.          3:b:= b/1000.0
  709.          end;
  710.       c:= b/ a;
  711.   edit14.Text:=formatfloat('0.000',c);
  712.   end;
  713.   if str1='uw' then begin
  714.       a:=strtofloat(edit16.Text);
  715.       n:=a;
  716.      // m:=m;
  717.       b:=strtofloat(edit15.Text);
  718.      ll:=combobox7.ItemIndex;
  719.       case ll of
  720.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  721.          1:b:= b*1000.0;
  722.          2:b:= b;
  723.          3:b:= b/1000.0
  724.          end;
  725.       c:= b/ a;
  726.   edit14.Text:=formatfloat('0.000',c);
  727.       end;
  728.       if str1='nw' then begin
  729.        a:=strtofloat(edit16.Text);
  730.       n:=a;
  731.       a:=a/1000.0;
  732.       b:=strtofloat(edit15.Text);
  733.       ll:=combobox7.ItemIndex;
  734.       case ll of
  735.         0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
  736.          1:b:= b*1000.0;
  737.          2:b:= b;
  738.          3:b:= b/1000.0
  739.          end;
  740.       c:= b/a;
  741.   edit14.Text:=formatfloat('0.000',c);
  742.       end;
  743.       if str1='mw' then begin
  744.         a:=strtofloat(edit16.Text);
  745.       n:=a;
  746.       a:=a*1000;
  747.       b:=strtofloat(edit15.Text);
  748.       ll:=combobox7.ItemIndex;
  749.       case ll of
  750.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  751.          1:b:= b*1000.0;
  752.          2:b:= b;
  753.          3:b:= b/1000.0
  754.          end;
  755.          c:=b/a;
  756.   edit14.Text:=formatfloat('0.000',c);
  757. end;
  758.  // end;
  759.   end
  760.   else
  761.   begin
  762.       showmessage('请先输入正确的值!');
  763.       edit14.SetFocus;
  764.   end;
  765. end;
  766. procedure TForm1.Button18Click(Sender: TObject);
  767. var
  768.   a,b:real;
  769.   c: real;
  770.  m,n:variant;
  771.  str1:string;
  772.  ll:integer;
  773. begin
  774. c:=0.00;
  775.   if (edit3.Text<>'') and (edit4.Text<>'') then
  776.  begin  {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  777.  begin
  778.  showmessage('数值超出合理范围(-45.00~+25.00');
  779.  edit3.Text:='';
  780.   end else begin }
  781.        str1:=label22.Caption;
  782.   if str1='dBm' then  begin
  783.       a:=strtofloat(edit19.Text);
  784.       n:=a;
  785.       a:=power(10,a/10.0);              //dbm to mw
  786.       a:=a*1000.0;                       //mw to uw
  787.       b:=strtofloat(edit18.Text);
  788.       ll:=combobox8.ItemIndex;
  789.       case ll of
  790.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  791.          1:b:= b*1000.0;
  792.          2:b:= b;
  793.          3:b:= b/1000.0
  794.          end;
  795.       c:= b/a;
  796.   edit17.Text:=formatfloat('0.000',c);
  797.   end;
  798.   if str1='uw' then begin
  799.       a:=strtofloat(edit19.Text);
  800.       n:=a;
  801.      // m:=m;
  802.       b:=strtofloat(edit18.Text);
  803.      ll:=combobox8.ItemIndex;
  804.       case ll of
  805.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  806.          1:b:= b*1000.0;
  807.          2:b:= b;
  808.          3:b:= b/1000.0
  809.          end;
  810.       c:= b/ a;
  811.   edit17.Text:=formatfloat('0.000',c);
  812.       end;
  813.       if str1='nw' then begin
  814.        a:=strtofloat(edit19.Text);
  815.       n:=a;
  816.       a:=a/1000.0;
  817.       b:=strtofloat(edit18.Text);
  818.       ll:=combobox8.ItemIndex;
  819.       case ll of
  820.         0:begin b:=power(10,b/10.0); b:=b/1000.0; end;
  821.          1:b:= b*1000.0;
  822.          2:b:= b;
  823.          3:b:= b/1000.0
  824.          end;
  825.       c:= b/a;
  826.   edit17.Text:=formatfloat('0.000',c);
  827.       end;
  828.       if str1='mw' then begin
  829.         a:=strtofloat(edit19.Text);
  830.       n:=a;
  831.       a:=a*1000;
  832.       b:=strtofloat(edit18.Text);
  833.       ll:=combobox8.ItemIndex;
  834.       case ll of
  835.         0:begin b:=power(10,b/10.0); b:=b*1000.0; end;
  836.          1:b:= b*1000.0;
  837.          2:b:= b;
  838.          3:b:= b/1000.0
  839.          end;
  840.          c:=b/a;
  841.   edit17.Text:=formatfloat('0.000',c);
  842. end;
  843.  // end;
  844.   end
  845.   else
  846.   begin
  847.       showmessage('请先输入正确的值!');
  848.   end;
  849. end;
  850. procedure TForm1.Button2Click(Sender: TObject);
  851. var
  852.  v,len,i,count:integer;
  853.    tmpstr:string;
  854.    tmpvar:variant;
  855.    xornum:byte;
  856.    arr:array of byte;
  857.     f:real;
  858. begin
  859. arr:=nil;
  860.  if (edit2.Text='') then
  861.   begin
  862.   showmessage('无设定值!');
  863.   end
  864.  else begin if not mscomm1.PortOpen then begin
  865.     showmessage('串口没有打开!');
  866.      end else begin
  867.            //hao add
  868.   if not TsInputVal(edit2.Text) then
  869.     begin
  870.      edit2.SetFocus;
  871.      exit
  872.     end;
  873.   //hao add end
  874.   
  875.      setlength(arr,9);
  876.         f:=strtofloat(edit2.text)*1000.0;
  877.         tmpstr:=floattostr(f);
  878.          v:=strtoint(tmpstr);
  879.             arr[0]:=$7e;   //soi
  880.            arr[1]:=$10;   //ver
  881.             arr[2]:= $04;    //length
  882.             arr[3]:=$a1;     //cid
  883.            arr[4]:=$00;      //datainfo
  884.            arr[5]:=v div 256;
  885.             arr[6]:= v mod 256   ;
  886.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  887.             arr[7]:=xornum;
  888.             arr[8]:=$0d;
  889.   // send data
  890.               len:=length(arr);
  891.            i:=0;
  892.             count:=0;
  893.             tmpvar:=vararraycreate([0,0],varbyte);
  894.             //tmpvar[count]:=arr[i];
  895.             //inc(count);
  896.             //inc(i);
  897.              while(count<=len-1)do begin
  898.                         tmpvar[count]:=arr[i];
  899.                         inc(count);
  900.                         inc(i);
  901.                         vararrayredim(tmpvar,count);
  902.                     end;
  903.       MSComm1.Output:=tmpvar;
  904.       timer1.Enabled:=true;
  905.  end;
  906.      //while mscomm1.InBufferCount
  907.     end;
  908. end;
  909. procedure TForm1.Timer1Timer(Sender: TObject);
  910. var
  911. i,n,m,chksum:integer;  //,timesum
  912. arr:array of byte;
  913. tmpvar:variant;
  914. begin
  915.      arr:=nil;
  916.      chksum:=$00;
  917.     timesum:=timesum+integer(timer1.Interval)+10;
  918.      if timesum<900 then
  919.       begin
  920.         if mscomm1.InBufferCount>0 then begin
  921.         timer1.Enabled:=false;
  922.         timesum:=100;
  923.           n:=mscomm1.InBufferCount;
  924.           setlength(arr,n);
  925.           tmpvar:=mscomm1.input;
  926.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  927.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  928.         begin
  929.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  930.            if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
  931.                //edit4.Text:=inttostr(arr[4]*256+arr[5]);
  932.                if arr[n-3]=$0cc  then begin
  933.                 showmessage('设置成功!') ;
  934.                 //tag:=true;
  935.                 end
  936.                 else  if arr[n-3]=$66 then begin  //success:=true;
  937.                 timer1.Enabled:=false;
  938.                     showmessage('设置失败!');
  939.                     end else begin timer1.Enabled:=false;
  940.                     showmessage('数据包错误!');
  941.                       end;
  942.              end else
  943.              begin
  944.              timer1.Enabled:=false;
  945.              showmessage('帧校验错误!'); //帧校验错误
  946.               //success:=true;
  947.               end;
  948.        end else begin
  949.        timer1.Enabled:=false;
  950.       showmessage('响应数据错误!');
  951.            //success:=true;
  952.            end;
  953.     end else begin
  954.         sleep(10);
  955.       timer1.Enabled:=true;
  956.              end;
  957.              end else begin
  958.              //success:=true;
  959.              timer1.Enabled:=false;
  960.              timesum:=100;
  961.              showmessage('通道0参数设定时响应超时!');
  962.              end;
  963. end;
  964. procedure TForm1.FormCreate(Sender: TObject);
  965. begin
  966. tindexnum:=-1;
  967. timesum:=100;
  968. flag:=false;
  969. success:=0;
  970. zuhao:=-1;
  971. tag:=0;
  972. tagc:=0;
  973. pc:=0;
  974. p:=0;
  975. //edit4.Enabled:=false;
  976. //edit7.Enabled:=false;
  977. //edit10.Enabled:=false;
  978. //edit13.Enabled:=false;
  979. //edit16.Enabled:=false;
  980. //edit19.Enabled:=false;
  981. edit20.Enabled:=false;
  982. edit21.Enabled:=false;
  983. edit22.Enabled:=false;
  984. edit23.Enabled:=false;
  985. edit24.Enabled:=false;
  986. edit25.Enabled:=false;
  987. edit26.Enabled:=false;
  988. edit27.Enabled:=false;
  989. edit28.Enabled:=false;
  990. edit29.Enabled:=false;
  991. edit30.Enabled:=false;
  992. edit31.Visible:=false;
  993. label8.Visible:=false;
  994. label9.Visible:=false;
  995. label10.Visible:=false;
  996. label11.Visible:=false;
  997. label12.Visible:=false;
  998. label13.Visible:=false;
  999. label14.Visible:=false;
  1000. label15.Visible:=false;
  1001. label16.Visible:=false;
  1002. edit29.Visible:=false;
  1003. edit30.Visible:=false;
  1004. edit27.Visible:=false;
  1005. edit28.Visible:=false;
  1006. button23.Visible:=false;
  1007. end;
  1008. procedure TForm1.Button26Click(Sender: TObject);
  1009. begin
  1010.  if messagedlg('你确定要退出吗?',mtConfirmation,[mbyes,mbno],0)=mryes then
  1011.     begin
  1012.     if mscomm1.PortOpen then begin
  1013.     mscomm1.PortOpen:=false;
  1014.     shape1.Brush.Color:=clred;
  1015.      end;
  1016.      application.Terminate;
  1017.     end;
  1018. end ;
  1019. procedure TForm1.Button27Click(Sender: TObject);
  1020.   var
  1021.   pt:boolean;
  1022.     filename,s,ed:string;
  1023.   i:integer;
  1024.    text:textfile;
  1025.    dataarr:array[1..6] of string;
  1026.   begin
  1027.       pt:=false;
  1028.     if opendialog1.Execute then
  1029.     begin  filename:=opendialog1.FileName;
  1030.        filename:=extractfilename(filename);
  1031.              if fileexists(filename)  then begin
  1032.         if edit1.Text='' then ed:='""' else ed:=edit1.Text;
  1033.          assignfile(text,filename);
  1034.          reset(text);
  1035.          try
  1036.             while not eof(text)  do
  1037.              begin
  1038.                readln(text,s);
  1039.                if s=ed  then  begin
  1040.                pt:=true;
  1041.                for i:=1 to 6 do begin
  1042.                   readln(text,s) ;
  1043.                 dataarr[i]:=s ;
  1044.                   end;
  1045.           edit20.Text:=dataarr[1];
  1046.           edit21.Text:=dataarr[2];
  1047.           edit22.Text:=dataarr[3];
  1048.           edit23.Text:=dataarr[4];
  1049.           edit24.Text:=dataarr[5];
  1050.           edit25.Text:=dataarr[6];
  1051.          if edit20.Text= edit2.Text then
  1052.             checkbox1.Checked:=true  else  checkbox1.Checked:=false;
  1053.          if edit21.Text= edit5.Text then
  1054.             checkbox2.Checked:=true  else  checkbox2.Checked:=false;
  1055.             if edit22.Text= edit8.Text then
  1056.             checkbox3.Checked:=true  else  checkbox3.Checked:=false;
  1057.             if edit23.Text= edit11.Text then
  1058.             checkbox4.Checked:=true  else  checkbox4.Checked:=false;
  1059.             if edit24.Text= edit14.Text then
  1060.             checkbox5.Checked:=true  else  checkbox5.Checked:=false;
  1061.             if edit25.Text= edit17.Text then
  1062.             checkbox6.Checked:=true  else  checkbox6.Checked:=false;
  1063.          
  1064.                 end ;
  1065.                end;
  1066.          finally
  1067.                closefile(text);
  1068.                end;
  1069.                 if pt=false then begin
  1070.                   edit20.Text:='';
  1071.                 edit21.Text:='';
  1072.                 edit22.Text:='';
  1073.                 edit23.Text:='';
  1074.                 edit24.Text:='';
  1075.                 edit25.Text:='';
  1076.                  showmessage('文件中无匹配记录!');
  1077.                  end;
  1078.             end else
  1079.             begin
  1080.                 edit20.Text:='';
  1081.                 edit21.Text:='';
  1082.                 edit22.Text:='';
  1083.                 edit23.Text:='';
  1084.                 edit24.Text:='';
  1085.                 edit25.Text:='';
  1086.                  showmessage('没有找到指定文件!');
  1087.             end;
  1088.      end;
  1089.      end;
  1090. procedure TForm1.Button5Click(Sender: TObject);
  1091. var
  1092.  v,len,i,count:integer;
  1093.    tmpstr:string;
  1094.    tmpvar:variant;
  1095.    xornum:byte;
  1096.    arr:array of byte;
  1097.     f:real;
  1098. begin
  1099. arr:=nil;
  1100.  if (edit5.Text='') then
  1101.   begin
  1102.   showmessage('无设定值!');
  1103.   end
  1104.  else begin if not mscomm1.PortOpen then begin
  1105.     showmessage('串口没有打开!');
  1106.      end else begin
  1107.            //hao add
  1108.   if not TsInputVal(edit5.Text) then
  1109.     begin
  1110.      edit5.SetFocus;
  1111.      exit
  1112.     end;
  1113.   //hao add end
  1114.      setlength(arr,9);
  1115.         f:=strtofloat(edit5.text)*1000.0;
  1116.         tmpstr:=floattostr(f);
  1117.          v:=strtoint(tmpstr);
  1118.             arr[0]:=$7e;   //soi
  1119.            arr[1]:=$10;   //ver
  1120.             arr[2]:= $04;    //length
  1121.             arr[3]:=$a1;     //cid
  1122.            arr[4]:=$01;      //datainfo
  1123.            arr[5]:=v div 256;
  1124.             arr[6]:= v mod 256   ;
  1125.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  1126.             arr[7]:=xornum;
  1127.             arr[8]:=$0d;
  1128.   // send data
  1129.               len:=length(arr);
  1130.            i:=0;
  1131.             count:=0;
  1132.             tmpvar:=vararraycreate([0,0],varbyte);
  1133.             //tmpvar[count]:=arr[i];
  1134.             //inc(count);
  1135.             //inc(i);
  1136.              while(count<=len-1)do begin
  1137.                         tmpvar[count]:=arr[i];
  1138.                         inc(count);
  1139.                         inc(i);
  1140.                         vararrayredim(tmpvar,count);
  1141.                     end;
  1142.       MSComm1.Output:=tmpvar;
  1143.       timer2.Enabled:=true;
  1144.  end;
  1145.      //while mscomm1.InBufferCount
  1146.     end;
  1147. end;
  1148. procedure TForm1.Button8Click(Sender: TObject);
  1149. var
  1150.  v,len,i,count:integer;
  1151.    tmpstr:string;
  1152.    tmpvar:variant;
  1153.    xornum:byte;
  1154.    arr:array of byte;
  1155.     f:real;
  1156. begin
  1157. arr:=nil;
  1158.  if (edit8.Text='') then
  1159.   begin
  1160.   showmessage('无设定值!');
  1161.   end
  1162.  else begin if not mscomm1.PortOpen then begin
  1163.     showmessage('串口没有打开!');
  1164.      end else begin
  1165.            //hao add
  1166.   if not TsInputVal(edit8.Text) then
  1167.     begin
  1168.      edit8.SetFocus;
  1169.      exit
  1170.     end;
  1171.   //hao add end
  1172.      setlength(arr,9);
  1173.         f:=strtofloat(edit8.text)*1000.0;
  1174.         tmpstr:=floattostr(f);
  1175.          v:=strtoint(tmpstr);
  1176.             arr[0]:=$7e;   //soi
  1177.            arr[1]:=$10;   //ver
  1178.             arr[2]:= $04;    //length
  1179.             arr[3]:=$a1;     //cid
  1180.            arr[4]:=$02;      //datainfo
  1181.            arr[5]:=v div 256;
  1182.             arr[6]:= v mod 256   ;
  1183.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  1184.             arr[7]:=xornum;
  1185.             arr[8]:=$0d;
  1186.   // send data
  1187.               len:=length(arr);
  1188.            i:=0;
  1189.             count:=0;
  1190.             tmpvar:=vararraycreate([0,0],varbyte);
  1191.             //tmpvar[count]:=arr[i];
  1192.             //inc(count);
  1193.             //inc(i);
  1194.              while(count<=len-1)do begin
  1195.                         tmpvar[count]:=arr[i];
  1196.                         inc(count);
  1197.                         inc(i);
  1198.                         vararrayredim(tmpvar,count);
  1199.                     end;
  1200.       MSComm1.Output:=tmpvar;
  1201.       timer3.Enabled:=true;
  1202.  end;
  1203.      //while mscomm1.InBufferCount
  1204.     end;
  1205. end;
  1206. procedure TForm1.Button11Click(Sender: TObject);
  1207. var
  1208.  v,len,i,count:integer;
  1209.    tmpstr:string;
  1210.    tmpvar:variant;
  1211.    xornum:byte;
  1212.    arr:array of byte;
  1213.     f:real;
  1214. begin
  1215. arr:=nil;
  1216.  if (edit11.Text='') then
  1217.   begin
  1218.   showmessage('无设定值!');
  1219.   end
  1220.  else begin if not mscomm1.PortOpen then begin
  1221.     showmessage('串口没有打开!');
  1222.      end else begin
  1223.            //hao add
  1224.   if not TsInputVal(edit11.Text) then
  1225.     begin
  1226.      edit11.SetFocus;
  1227.      exit
  1228.     end;
  1229.   //hao add end
  1230.      setlength(arr,9);
  1231.         f:=strtofloat(edit11.text)*1000.0;
  1232.         tmpstr:=floattostr(f);
  1233.          v:=strtoint(tmpstr);
  1234.             arr[0]:=$7e;   //soi
  1235.            arr[1]:=$10;   //ver
  1236.             arr[2]:= $04;    //length
  1237.             arr[3]:=$a1;     //cid
  1238.            arr[4]:=$03;      //datainfo
  1239.            arr[5]:=v div 256;
  1240.             arr[6]:= v mod 256   ;
  1241.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  1242.             arr[7]:=xornum;
  1243.             arr[8]:=$0d;
  1244.   // send data
  1245.               len:=length(arr);
  1246.            i:=0;
  1247.             count:=0;
  1248.             tmpvar:=vararraycreate([0,0],varbyte);
  1249.             //tmpvar[count]:=arr[i];
  1250.             //inc(count);
  1251.             //inc(i);
  1252.              while(count<=len-1)do begin
  1253.                         tmpvar[count]:=arr[i];
  1254.                         inc(count);
  1255.                         inc(i);
  1256.                         vararrayredim(tmpvar,count);
  1257.                     end;
  1258.       MSComm1.Output:=tmpvar;
  1259.       timer4.Enabled:=true;
  1260.  end;
  1261.      //while mscomm1.InBufferCount
  1262.     end;
  1263. end;
  1264. procedure TForm1.Button14Click(Sender: TObject);
  1265. var
  1266.  v,len,i,count:integer;
  1267.    tmpstr:string;
  1268.    tmpvar:variant;
  1269.    xornum:byte;
  1270.    arr:array of byte;
  1271.     f:real;
  1272. begin
  1273. arr:=nil;
  1274.  if (edit14.Text='') then
  1275.   begin
  1276.   showmessage('无设定值!');
  1277.   end
  1278.  else begin if not mscomm1.PortOpen then begin
  1279.     showmessage('串口没有打开!');
  1280.      end else begin
  1281.            //hao add
  1282.   if not TsInputVal(edit14.Text) then
  1283.     begin
  1284.      edit14.SetFocus;
  1285.      exit
  1286.     end;
  1287.   //hao add end
  1288.      setlength(arr,9);
  1289.         f:=strtofloat(edit14.text)*1000.0;
  1290.         tmpstr:=floattostr(f);
  1291.          v:=strtoint(tmpstr);
  1292.             arr[0]:=$7e;   //soi
  1293.            arr[1]:=$10;   //ver
  1294.             arr[2]:= $04;    //length
  1295.             arr[3]:=$a1;     //cid
  1296.            arr[4]:=$04;      //datainfo
  1297.            arr[5]:=v div 256;
  1298.             arr[6]:= v mod 256   ;
  1299.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  1300.             arr[7]:=xornum;
  1301.             arr[8]:=$0d;
  1302.   // send data
  1303.               len:=length(arr);
  1304.            i:=0;
  1305.             count:=0;
  1306.             tmpvar:=vararraycreate([0,0],varbyte);
  1307.             //tmpvar[count]:=arr[i];
  1308.             //inc(count);
  1309.             //inc(i);
  1310.              while(count<=len-1)do begin
  1311.                         tmpvar[count]:=arr[i];
  1312.                         inc(count);
  1313.                         inc(i);
  1314.                         vararrayredim(tmpvar,count);
  1315.                     end;
  1316.       MSComm1.Output:=tmpvar;
  1317.       timer5.Enabled:=true;
  1318.  end;
  1319.      //while mscomm1.InBufferCount
  1320.     end;
  1321. end;
  1322. procedure TForm1.Button17Click(Sender: TObject);
  1323. var
  1324.  v,len,i,count:integer;
  1325.    tmpstr:string;
  1326.    tmpvar:variant;
  1327.    xornum:byte;
  1328.    arr:array of byte;
  1329.     f:real;
  1330. begin
  1331. arr:=nil;
  1332.  if (edit17.Text='') then
  1333.   begin
  1334.   showmessage('无设定值!');
  1335.   end
  1336.  else begin if not mscomm1.PortOpen then begin
  1337.     showmessage('串口没有打开!');
  1338.      end else begin
  1339.            //hao add
  1340.   if not TsInputVal(edit17.Text) then
  1341.     begin
  1342.      edit17.SetFocus;
  1343.      exit
  1344.     end;
  1345.   //hao add end
  1346.      setlength(arr,9);
  1347.         f:=strtofloat(edit17.text)*1000.0;
  1348.         tmpstr:=floattostr(f);
  1349.          v:=strtoint(tmpstr);
  1350.             arr[0]:=$7e;   //soi
  1351.            arr[1]:=$10;   //ver
  1352.             arr[2]:= $04;    //length
  1353.             arr[3]:=$a1;     //cid
  1354.            arr[4]:=$05;      //datainfo
  1355.            arr[5]:=v div 256;
  1356.             arr[6]:= v mod 256   ;
  1357.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  1358.             arr[7]:=xornum;
  1359.             arr[8]:=$0d;
  1360.   // send data
  1361.               len:=length(arr);
  1362.            i:=0;
  1363.             count:=0;
  1364.             tmpvar:=vararraycreate([0,0],varbyte);
  1365.             //tmpvar[count]:=arr[i];
  1366.             //inc(count);
  1367.             //inc(i);
  1368.              while(count<=len-1)do begin
  1369.                         tmpvar[count]:=arr[i];
  1370.                         inc(count);
  1371.                         inc(i);
  1372.                         vararrayredim(tmpvar,count);
  1373.                     end;
  1374.       MSComm1.Output:=tmpvar;
  1375.       timer6.Enabled:=true;
  1376.  end;
  1377.      //while mscomm1.InBufferCount
  1378.     end;
  1379. end;
  1380. procedure TForm1.Timer2Timer(Sender: TObject);
  1381. var
  1382. i,n,m,chksum:integer;  //,timesum
  1383. arr:array of byte;
  1384. tmpvar:variant;
  1385. begin
  1386.      arr:=nil;
  1387.      chksum:=$00;
  1388.     timesum:=timesum+integer(timer2.Interval)+10;
  1389.      if timesum<900 then
  1390.       begin
  1391.         if mscomm1.InBufferCount>0 then begin
  1392.         timer2.Enabled:=false;
  1393.         timesum:=100;
  1394.           n:=mscomm1.InBufferCount;
  1395.           setlength(arr,n);
  1396.           tmpvar:=mscomm1.input;
  1397.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  1398.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  1399.         begin
  1400.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  1401.            if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
  1402.                //edit4.Text:=inttostr(arr[4]*256+arr[5]);
  1403.                  if arr[n-3]=$0cc  then begin
  1404.                 showmessage('设置成功!') ;
  1405.                 //tag:=true;
  1406.                 end
  1407.                 else if arr[n-3]=$66 then begin  //success:=true;
  1408.                 timer2.Enabled:=false;
  1409.                     showmessage('设置失败!');
  1410.                     end else begin  timer1.Enabled:=false;
  1411.                       showmessage('数据包错误!');
  1412.                       end;
  1413.              end else  begin
  1414.              timer2.Enabled:=false;
  1415.              showmessage('数据错误!'); //帧校验错误
  1416.              end;
  1417.        end else  begin
  1418.        timer2.Enabled:=false;
  1419.       showmessage('响应数据错误!');
  1420.          end;
  1421.     end else begin
  1422.         sleep(10);
  1423.       timer2.Enabled:=true;
  1424.              end;
  1425.              end else begin
  1426.               timesum:=100;
  1427.              timer2.Enabled:=false;
  1428.              showmessage('通道5参数设定响应超时!');
  1429.              end;
  1430. end;
  1431. procedure TForm1.Timer3Timer(Sender: TObject);
  1432. var
  1433. i,n,m,chksum:integer;  //,timesum
  1434. arr:array of byte;
  1435. tmpvar:variant;
  1436. begin
  1437.      timer3.Enabled:=false;
  1438.      arr:=nil;
  1439.      chksum:=$00;
  1440.     timesum:=timesum+integer(timer3.Interval)+10;
  1441.      if timesum<900 then
  1442.       begin
  1443.         if mscomm1.InBufferCount>0 then begin
  1444.          timer3.Enabled:=false;
  1445.          timesum:=100;
  1446.           n:=mscomm1.InBufferCount;
  1447.           setlength(arr,n);
  1448.           tmpvar:=mscomm1.input;
  1449.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  1450.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  1451.         begin
  1452.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  1453.            if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
  1454.                //edit4.Text:=inttostr(arr[4]*256+arr[5]);
  1455.                  if arr[n-3]=$0cc  then begin
  1456.                 showmessage('设置成功!') ;
  1457.                 //tag:=true;
  1458.                 end
  1459.                 else if arr[n-3]=$66 then begin  //success:=true;
  1460.                 timer3.Enabled:=false;
  1461.                     showmessage('设置失败!');
  1462.                     end else begin timer1.Enabled:=false;
  1463.                         showmessage('数据包错误!');
  1464.                         end;
  1465.              end else   begin
  1466.              timer3.Enabled:=false;
  1467.              showmessage('数据错误!'); //帧校验错误
  1468.              end;
  1469.        end else begin
  1470.        timer3.Enabled:=false;
  1471.       showmessage('响应数据错误!');
  1472.            end;
  1473.     end else begin
  1474.         sleep(10);
  1475.       timer3.Enabled:=true;
  1476.              end;
  1477.              end else begin
  1478.              timesum:=100;
  1479.              timer3.Enabled:=false;
  1480.              showmessage('1310nm校正参数设定响应超时!');
  1481.              end;
  1482. end;
  1483. procedure TForm1.Timer4Timer(Sender: TObject);
  1484. var
  1485. i,n,m,chksum:integer;  //,timesum
  1486. arr:array of byte;
  1487. tmpvar:variant;
  1488. begin
  1489.      timer4.Enabled:=false;
  1490.      arr:=nil;
  1491.      chksum:=$00;
  1492.     timesum:=timesum+integer(timer4.Interval)+10;
  1493.      if timesum<900 then
  1494.       begin
  1495.         if mscomm1.InBufferCount>0 then begin
  1496.          timer4.Enabled:=false;
  1497.          timesum:=100;
  1498.           n:=mscomm1.InBufferCount;
  1499.           setlength(arr,n);
  1500.           tmpvar:=mscomm1.input;
  1501.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  1502.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  1503.         begin
  1504.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  1505.            if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
  1506.                //edit4.Text:=inttostr(arr[4]*256+arr[5]);
  1507.                       if arr[n-3]=$0cc  then begin
  1508.                 showmessage('设置成功!') ;
  1509.                 //tag:=true;
  1510.                 end
  1511.                 else if arr[n-3]=$66 then begin  //success:=true;
  1512.                 timer4.Enabled:=false;
  1513.                     showmessage('设置失败!');
  1514.                     end else   begin
  1515.                     timer4.Enabled:=false;
  1516.                     showmessage('数据包错误!');
  1517.                     end;
  1518.              end else  begin
  1519.              timer4.Enabled:=false;
  1520.              showmessage('数据错误!'); //帧校验错误
  1521.              end;
  1522.        end else  begin
  1523.        timer4.Enabled:=false;
  1524.       showmessage('响应数据错误!');
  1525.           end;
  1526.     end else begin
  1527.         sleep(10);
  1528.       timer4.Enabled:=true;
  1529.              end;
  1530.              end else begin
  1531.              timesum:=100;
  1532.              timer4.Enabled:=false;
  1533.              showmessage('1550nm校正参数设定响应超时!');
  1534.              end;
  1535. end;
  1536. procedure TForm1.Timer5Timer(Sender: TObject);
  1537. var
  1538. i,n,m,chksum:integer;  //,timesum
  1539. arr:array of byte;
  1540. tmpvar:variant;
  1541. begin
  1542.      arr:=nil;
  1543.      chksum:=$00;
  1544.     timesum:=timesum+integer(timer5.Interval)+10;
  1545.      if timesum<900 then
  1546.       begin
  1547.         if mscomm1.InBufferCount>0 then begin
  1548.          timer5.Enabled:=false;
  1549.          timesum:=100;
  1550.           n:=mscomm1.InBufferCount;
  1551.           setlength(arr,n);
  1552.           tmpvar:=mscomm1.input;
  1553.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  1554.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  1555.         begin
  1556.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  1557.            if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
  1558.                //edit4.Text:=inttostr(arr[4]*256+arr[5]);
  1559.                       if arr[n-3]=$0cc  then begin
  1560.                 showmessage('设置成功!') ;
  1561.                 //tag:=true;
  1562.                 end
  1563.                 else if arr[n-3]=$66 then begin  //success:=true;
  1564.                 timer5.Enabled:=false;
  1565.                     showmessage('设置失败!');
  1566.                     end else
  1567.                     begin
  1568.                     timer5.Enabled:=false;
  1569.                     showmessage('数据包错误!');
  1570.                     end;
  1571.              end else   begin
  1572.              timer5.Enabled:=false;
  1573.              showmessage('数据错误!'); //帧校验错误
  1574.              end;
  1575.        end else  begin
  1576.        timer5.Enabled:=false;
  1577.       showmessage('响应数据错误!');
  1578.            end;
  1579.     end else begin
  1580.         sleep(10);
  1581.       timer5.Enabled:=true;
  1582.              end;
  1583.              end else begin
  1584.              timesum:=100;
  1585.              timer5.Enabled:=false;
  1586.              showmessage('850nm校正参数设定响应超时!');
  1587.              end;
  1588. end;
  1589. procedure TForm1.Timer6Timer(Sender: TObject);
  1590. var
  1591. i,n,m,chksum:integer;  //,timesum
  1592. arr:array of byte;
  1593. tmpvar:variant;
  1594. begin
  1595.      arr:=nil;
  1596.      chksum:=$00;
  1597.     timesum:=timesum+integer(timer6.Interval)+10;
  1598.      if timesum<900 then
  1599.       begin
  1600.         if mscomm1.InBufferCount>0 then begin
  1601.         timer6.Enabled:=false;
  1602.         timesum:=100;
  1603.           n:=mscomm1.InBufferCount;
  1604.           setlength(arr,n);
  1605.           tmpvar:=mscomm1.input;
  1606.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  1607.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  1608.         begin
  1609.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  1610.            if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
  1611.                //edit4.Text:=inttostr(arr[4]*256+arr[5]);
  1612.                       if arr[n-3]=$0cc  then begin
  1613.                 showmessage('设置成功!') ;
  1614.                 //tag:=true;
  1615.                 end
  1616.                 else if arr[n-3]=$66 then begin  //success:=true;
  1617.                 timer6.Enabled:=false;
  1618.                     showmessage('设置失败!');
  1619.                     end else begin
  1620.                     timer6.Enabled:=false;
  1621.                      showmessage('数据包错误');
  1622.                      end;
  1623.              end else begin
  1624.              timer6.Enabled:=false;
  1625.              showmessage('数据错误'); //帧校验错误
  1626.              end;
  1627.        end else    begin
  1628.        timer6.Enabled:=false;
  1629.       showmessage('响应数据错误!');
  1630.         end;
  1631.     end else begin
  1632.         sleep(10);
  1633.       timer6.Enabled:=true;
  1634.              end;
  1635.              end else begin
  1636.              timesum:=100;
  1637.              timer6.Enabled:=false;
  1638.              showmessage('980nm校正参数设定响应超时!');
  1639.              end;
  1640. end;
  1641. procedure TForm1.Button21Click(Sender: TObject);
  1642. var
  1643. fl:boolean;
  1644. text:textfile;
  1645.  s,pa,filename:string;
  1646.  i,countlin,c :integer;
  1647. begin
  1648. fl:=false;
  1649.     if(edit2.Text='')or(edit5.Text='')or(edit8.Text='')or(edit11.Text='')or(edit14.Text='')or(edit17.Text='') then
  1650.      showmessage('计算未完成!')
  1651.     else if savedialog1.Execute then begin
  1652.            filename:=opendialog1.FileName;
  1653.            if fileexists(savedialog1.FileName) then
  1654.            begin
  1655.            memo1.Lines.LoadFromFile(savedialog1.FileName);
  1656.          countlin:= memo1.lines.Count ;
  1657.          if edit1.Text='' then s:='""'
  1658.          else s:=edit1.Text;
  1659.           for i:=0  to countlin-1 do    begin
  1660.           if memo1.Lines[i]=s then
  1661.           begin
  1662.               for  c:=0 to 6 do begin
  1663.           memo1.Lines.Delete(i);
  1664.           memo1.Refresh;
  1665.           end;
  1666.               memo1.Lines.Add(s);
  1667.               memo1.Lines.add(edit2.text);
  1668.           memo1.Lines.Add(edit5.Text);
  1669.           memo1.Lines.Add(edit8.Text) ;
  1670.           memo1.Lines.Add(edit11.Text) ;
  1671.           memo1.Lines.Add(edit14.Text);
  1672.           memo1.Lines.Add(edit17.Text);
  1673.               memo1.Lines.SaveToFile(savedialog1.FileName);
  1674.               flag:=true;
  1675.               fl:=true;
  1676.           end;
  1677.             end;
  1678.             if fl=false then   begin
  1679.             memo1.Lines.add(s);
  1680.           memo1.Lines.add(edit2.text);
  1681.           memo1.Lines.Add(edit5.Text);
  1682.           memo1.Lines.Add(edit8.Text) ;
  1683.           memo1.Lines.Add(edit11.Text) ;
  1684.           memo1.Lines.Add(edit14.Text);
  1685.           memo1.Lines.Add(edit17.Text);
  1686.               memo1.Lines.SaveToFile(savedialog1.FileName);
  1687.               end;
  1688.            end else begin   //file is not exist
  1689.                assignfile(text,savedialog1.FileName);
  1690.                rewrite(text);
  1691.                  if edit1.Text='' then pa:='""' else pa:=edit1.Text ;
  1692.                try
  1693.                writeln(text,pa);
  1694.                 writeln(text,edit2.text);
  1695.                 writeln(text,edit5.text);
  1696.                 writeln(text,edit8.text);
  1697.                 writeln(text,edit11.text);
  1698.                 writeln(text,edit14.text);
  1699.                 writeln(text,edit17.text);
  1700.                finally
  1701.                  closefile(text);
  1702.                end;
  1703.                flag:=true;
  1704.            end;
  1705.            end ;
  1706.    end;
  1707. procedure TForm1.Button1Click(Sender: TObject);
  1708. var
  1709.  len,i,count:integer;
  1710.    //tmpstr:string;
  1711.    tmpvar:variant;
  1712.    xornum:byte;
  1713.    arr:array of byte;
  1714. begin
  1715. arr:=nil;
  1716.  if not mscomm1.PortOpen then begin
  1717.     showmessage('串口没有打开!');
  1718.      end else begin
  1719.      setlength(arr,7);
  1720.         // f:=strtoint(edit2.text);
  1721.             arr[0]:=$7e;   //soi
  1722.            arr[1]:=$10;   //ver
  1723.             arr[2]:= $02;    //length
  1724.             arr[3]:=$a3;     //cid
  1725.            arr[4]:=$00;      //datainfo
  1726.           // arr[5]:=f div 255;
  1727.            // arr[6]:= f mod 255   ;
  1728.             xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
  1729.             arr[5]:=xornum;
  1730.             arr[6]:=$0d;
  1731.   // send data
  1732.               len:=length(arr);
  1733.            i:=0;
  1734.             count:=0;
  1735.             tmpvar:=vararraycreate([0,0],varbyte);
  1736.              while(count<=len-1)do begin
  1737.                         tmpvar[count]:=arr[i];
  1738.                         inc(count);
  1739.                         inc(i);
  1740.                         vararrayredim(tmpvar,count);
  1741.                     end;
  1742.       MSComm1.Output:=tmpvar;
  1743.       timer7.Enabled:=true;
  1744.      // button23.Click;
  1745.  end;
  1746.     end;
  1747. procedure TForm1.Timer7Timer(Sender: TObject);
  1748. var
  1749. i,n,m,chksum,tp,tph,tpl:integer;  //,timesum
  1750. arr:array of byte;
  1751. tmpvar:variant;
  1752. xy:real;
  1753. str:string;
  1754. begin
  1755. str:='';
  1756.      arr:=nil;
  1757.      chksum:=$00;
  1758.     timesum:=timesum+integer(timer7.Interval)+10;
  1759.      if timesum<900 then
  1760.       begin
  1761.         if mscomm1.InBufferCount>0 then begin
  1762.              timer7.Enabled:=false;
  1763.              timesum:=100;
  1764.           n:=mscomm1.InBufferCount;
  1765.           setlength(arr,n);
  1766.           tmpvar:=mscomm1.input;
  1767.        for i:=0 to n-1 do begin
  1768.        arr[i]:=tmpvar[i];
  1769.        str:=str+inttostr(arr[i]);
  1770.        end;
  1771.        // showmessage(inttostr(arr[i]));
  1772.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then     //头校验
  1773.         begin if arr[2]<>n-5 then showmessage('长度错误!') else     //长度校验
  1774.          begin
  1775.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  1776.            if (arr[n-2]=chksum)and(arr[3]=$a3) then begin           //帧校验
  1777.                tp:=arr[4] and $f0 ;
  1778.                tph:=strtoint(floattostr(tp/16));
  1779.                tpl:=arr[4] and $0f;
  1780.                case tph of
  1781.                0:begin label17.Caption:='mw';
  1782.                if arr[6]<127 then begin
  1783.                            xy := (arr[6]*256+arr[7]) ;
  1784.                  case tpl of
  1785.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  1786.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  1787.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  1788.                  3: edit4.Text:=formatfloat('0.000',xy);
  1789.                  end;
  1790.                  end else begin
  1791.                          xy := -((arr[6]-128)*256+arr[7]) ;
  1792.                    case tpl of
  1793.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  1794.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  1795.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  1796.                  3: edit4.Text:=formatfloat('0.000',xy);
  1797.                  end;
  1798.                  end;
  1799.                  end;
  1800.                1: begin label17.Caption:='uw';if arr[6]<127 then begin
  1801.                            xy := (arr[6]*256+arr[7]) ;
  1802.                  case tpl of
  1803.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  1804.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  1805.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  1806.                  3: edit4.Text:=formatfloat('0.000',xy);
  1807.                  end;
  1808.                  end else begin
  1809.                          xy := -((arr[6]-128)*256+arr[7]) ;
  1810.                    case tpl of
  1811.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  1812.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  1813.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  1814.                  3: edit4.Text:=formatfloat('0.000',xy);
  1815.                  end;
  1816.                  end;
  1817.                  end;
  1818.                2: begin label17.Caption:='nw';if arr[6]<127 then begin
  1819.                            xy := (arr[6]*256+arr[7]) ;
  1820.                  case tpl of
  1821.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  1822.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  1823.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  1824.                  3: edit4.Text:=formatfloat('0.000',xy);
  1825.                  end;
  1826.                  end else begin
  1827.                          xy := -((arr[6]-128)*256+arr[7]) ;
  1828.                    case tpl of
  1829.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  1830.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  1831.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  1832.                  3: edit4.Text:=formatfloat('0.000',xy);
  1833.                  end;
  1834.                  end;
  1835.                  end;
  1836.                4: begin label17.Caption:='dBm'; if arr[6]<127 then begin
  1837.                            xy := (arr[6]*256+arr[7]) ;
  1838.                  case tpl of
  1839.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  1840.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  1841.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  1842.                  3: edit4.Text:=formatfloat('0.000',xy);
  1843.                  end;
  1844.                  end else begin
  1845.                          xy := -((arr[6]-128)*256+arr[7]) ;
  1846.                    case tpl of
  1847.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  1848.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  1849.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  1850.                  3: edit4.Text:=formatfloat('0.000',xy);
  1851.                  end;
  1852.                  end;
  1853.                  end;
  1854.                8:  showmessage('测量单位不能是dB。');
  1855.                9:   showmessage('超范围!');
  1856.                end;
  1857.               { if arr[6]<127 then begin
  1858.                            xy := (arr[6]*256+arr[7]) ;
  1859.                  case tpl of
  1860.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  1861.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  1862.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  1863.                  3: edit4.Text:=formatfloat('0.000',xy);
  1864.                  end;
  1865.                  end else begin
  1866.                          xy := -((arr[6]-128)*256+arr[7]) ;
  1867.                    case tpl of
  1868.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  1869.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  1870.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  1871.                  3: edit4.Text:=formatfloat('0.000',xy);
  1872.                  end;
  1873.                  end; }
  1874.              end else   begin
  1875.              timer7.Enabled:=false;
  1876.              showmessage('帧校验错误!'); //帧校验错误
  1877.              end;
  1878.              end;
  1879.        end else  begin
  1880.        timer7.Enabled:=false;
  1881.       showmessage('响应数据错误!');
  1882.         end;
  1883.     end else begin
  1884.         sleep(10);
  1885.       timer7.Enabled:=true;
  1886.              end;
  1887.              end else begin
  1888.               timesum:=100;
  1889.               timer7.Enabled:=false;
  1890.              showmessage('响应超时!');
  1891.              end;
  1892. end;
  1893. procedure TForm1.Button4Click(Sender: TObject);
  1894. var
  1895.  len,i,count:integer;
  1896.    //tmpstr:string;
  1897.    tmpvar:variant;
  1898.    xornum:byte;
  1899.    arr:array of byte;
  1900. begin
  1901. arr:=nil;
  1902.  if not mscomm1.PortOpen then begin
  1903.     showmessage('串口没有打开!');
  1904.      end else begin
  1905.      setlength(arr,7);
  1906.         // f:=strtoint(edit2.text);
  1907.             arr[0]:=$7e;   //soi
  1908.            arr[1]:=$10;   //ver
  1909.             arr[2]:= $02;    //length
  1910.             arr[3]:=$a3;     //cid
  1911.            arr[4]:=$00;      //datainfo
  1912.           // arr[5]:=f div 255;
  1913.            // arr[6]:= f mod 255   ;
  1914.             xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
  1915.             arr[5]:=xornum;
  1916.             arr[6]:=$0d;
  1917.   // send data
  1918.               len:=length(arr);
  1919.            i:=0;
  1920.             count:=0;
  1921.             tmpvar:=vararraycreate([0,0],varbyte);
  1922.             //tmpvar[count]:=arr[i];
  1923.             //inc(count);
  1924.             //inc(i);
  1925.              while(count<=len-1)do begin
  1926.                         tmpvar[count]:=arr[i];
  1927.                         inc(count);
  1928.                         inc(i);
  1929.                         vararrayredim(tmpvar,count);
  1930.                     end;
  1931.       MSComm1.Output:=tmpvar;
  1932.       timer8.Enabled:=true;
  1933.  end;
  1934.      //while mscomm1.InBufferCount
  1935.     end;
  1936. procedure TForm1.Button7Click(Sender: TObject);
  1937. var
  1938.  len,i,count:integer;
  1939.    //tmpstr:string;
  1940.    tmpvar:variant;
  1941.    xornum:byte;
  1942.    arr:array of byte;
  1943. begin
  1944. arr:=nil;
  1945.  if not mscomm1.PortOpen then begin
  1946.     showmessage('串口没有打开!');
  1947.      end else begin
  1948.      setlength(arr,7);
  1949.         // f:=strtoint(edit2.text);
  1950.             arr[0]:=$7e;   //soi
  1951.            arr[1]:=$10;   //ver
  1952.             arr[2]:= $02;    //length
  1953.             arr[3]:=$a3;     //cid
  1954.            arr[4]:=$00;      //datainfo
  1955.           // arr[5]:=f div 255;
  1956.            // arr[6]:= f mod 255   ;
  1957.             xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
  1958.             arr[5]:=xornum;
  1959.             arr[6]:=$0d;
  1960.   // send data
  1961.               len:=length(arr);
  1962.            i:=0;
  1963.             count:=0;
  1964.             tmpvar:=vararraycreate([0,0],varbyte);
  1965.             //tmpvar[count]:=arr[i];
  1966.             //inc(count);
  1967.             //inc(i);
  1968.              while(count<=len-1)do begin
  1969.                         tmpvar[count]:=arr[i];
  1970.                         inc(count);
  1971.                         inc(i);
  1972.                         vararrayredim(tmpvar,count);
  1973.                     end;
  1974.       MSComm1.Output:=tmpvar;
  1975.       timer9.Enabled:=true;
  1976.  end;
  1977.      //while mscomm1.InBufferCount
  1978.     end;
  1979. procedure TForm1.Button10Click(Sender: TObject);
  1980. var
  1981.  len,i,count:integer;
  1982.    //tmpstr:string;
  1983.    tmpvar:variant;
  1984.    xornum:byte;
  1985.    arr:array of byte;
  1986. begin
  1987. arr:=nil;
  1988.  if not mscomm1.PortOpen then begin
  1989.     showmessage('串口没有打开!');
  1990.      end else begin
  1991.      setlength(arr,7);
  1992.         // f:=strtoint(edit2.text);
  1993.             arr[0]:=$7e;   //soi
  1994.            arr[1]:=$10;   //ver
  1995.             arr[2]:= $02;    //length
  1996.             arr[3]:=$a3;     //cid
  1997.            arr[4]:=$00;      //datainfo
  1998.           // arr[5]:=f div 255;
  1999.            // arr[6]:= f mod 255   ;
  2000.             xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
  2001.             arr[5]:=xornum;
  2002.             arr[6]:=$0d;
  2003.   // send data
  2004.               len:=length(arr);
  2005.            i:=0;
  2006.             count:=0;
  2007.             tmpvar:=vararraycreate([0,0],varbyte);
  2008.             //tmpvar[count]:=arr[i];
  2009.             //inc(count);
  2010.             //inc(i);
  2011.              while(count<=len-1)do begin
  2012.                         tmpvar[count]:=arr[i];
  2013.                         inc(count);
  2014.                         inc(i);
  2015.                         vararrayredim(tmpvar,count);
  2016.                     end;
  2017.       MSComm1.Output:=tmpvar;
  2018.       timer10.Enabled:=true;
  2019.  end;
  2020.      //while mscomm1.InBufferCount
  2021.     end;
  2022. procedure TForm1.Button13Click(Sender: TObject);
  2023. var
  2024.  len,i,count:integer;
  2025.    //tmpstr:string;
  2026.    tmpvar:variant;
  2027.    xornum:byte;
  2028.    arr:array of byte;
  2029. begin
  2030. arr:=nil;
  2031.  if not mscomm1.PortOpen then begin
  2032.     showmessage('串口没有打开!');
  2033.      end else begin
  2034.      setlength(arr,7);
  2035.         // f:=strtoint(edit2.text);
  2036.             arr[0]:=$7e;   //soi
  2037.            arr[1]:=$10;   //ver
  2038.             arr[2]:= $02;    //length
  2039.             arr[3]:=$a3;     //cid
  2040.            arr[4]:=$00;      //datainfo
  2041.           // arr[5]:=f div 255;
  2042.            // arr[6]:= f mod 255   ;
  2043.             xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
  2044.             arr[5]:=xornum;
  2045.             arr[6]:=$0d;
  2046.   // send data
  2047.               len:=length(arr);
  2048.            i:=0;
  2049.             count:=0;
  2050.             tmpvar:=vararraycreate([0,0],varbyte);
  2051.             //tmpvar[count]:=arr[i];
  2052.             //inc(count);
  2053.             //inc(i);
  2054.              while(count<=len-1)do begin
  2055.                         tmpvar[count]:=arr[i];
  2056.                         inc(count);
  2057.                         inc(i);
  2058.                         vararrayredim(tmpvar,count);
  2059.                     end;
  2060.       MSComm1.Output:=tmpvar;
  2061.       timer11.Enabled:=true;
  2062.  end;
  2063.      //while mscomm1.InBufferCount
  2064.     end;
  2065. procedure TForm1.Button16Click(Sender: TObject);
  2066. var
  2067.  len,i,count:integer;
  2068.    //tmpstr:string;
  2069.    tmpvar:variant;
  2070.    xornum:byte;
  2071.    arr:array of byte;
  2072. begin
  2073. arr:=nil;
  2074.  if not mscomm1.PortOpen then begin
  2075.     showmessage('串口没有打开!');
  2076.      end else begin
  2077.      setlength(arr,7);
  2078.         // f:=strtoint(edit2.text);
  2079.             arr[0]:=$7e;   //soi
  2080.            arr[1]:=$10;   //ver
  2081.             arr[2]:= $02;    //length
  2082.             arr[3]:=$a3;     //cid
  2083.            arr[4]:=$00;      //datainfo
  2084.           // arr[5]:=f div 255;
  2085.            // arr[6]:= f mod 255   ;
  2086.             xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
  2087.             arr[5]:=xornum;
  2088.             arr[6]:=$0d;
  2089.   // send data
  2090.               len:=length(arr);
  2091.            i:=0;
  2092.             count:=0;
  2093.             tmpvar:=vararraycreate([0,0],varbyte);
  2094.             //tmpvar[count]:=arr[i];
  2095.             //inc(count);
  2096.             //inc(i);
  2097.              while(count<=len-1)do begin
  2098.                         tmpvar[count]:=arr[i];
  2099.                         inc(count);
  2100.                         inc(i);
  2101.                         vararrayredim(tmpvar,count);
  2102.                     end;
  2103.       MSComm1.Output:=tmpvar;
  2104.       timer12.Enabled:=true;
  2105.  end;
  2106.      //while mscomm1.InBufferCount
  2107.     end;
  2108. procedure TForm1.Timer8Timer(Sender: TObject);
  2109. var
  2110. i,n,m,chksum,tp,tph,tpl:integer;  //,timesum
  2111. arr:array of byte;
  2112. tmpvar:variant;
  2113. xy:real;
  2114. str:string;
  2115. begin
  2116. str:='';
  2117.      arr:=nil;
  2118.      chksum:=$00;
  2119.     timesum:=timesum+integer(timer8.Interval)+10;
  2120.      if timesum<900 then
  2121.       begin
  2122.         if mscomm1.InBufferCount>0 then begin
  2123.              timer8.Enabled:=false;
  2124.              timesum:=100;
  2125.           n:=mscomm1.InBufferCount;
  2126.           setlength(arr,n);
  2127.           tmpvar:=mscomm1.input;
  2128.        for i:=0 to n-1 do begin
  2129.        arr[i]:=tmpvar[i];
  2130.        str:=str+inttostr(arr[i]);
  2131.        end;
  2132.        // showmessage(inttostr(arr[i]));
  2133.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then     //头校验
  2134.         begin if arr[2]<>n-5 then showmessage('长度错误!') else     //长度校验
  2135.          begin
  2136.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  2137.            if (arr[n-2]=chksum)and(arr[3]=$a3) then begin           //帧校验
  2138.                tp:=arr[4] and $f0 ;
  2139.                tph:=strtoint(floattostr(tp/16));
  2140.                tpl:=arr[4] and $0f;
  2141.                case tph of
  2142.                0:begin label18.Caption:='mw';
  2143.                if arr[6]<127 then begin
  2144.                            xy := (arr[6]*256+arr[7]) ;
  2145.                  case tpl of
  2146.                  0: edit7.Text:=formatfloat('0.000',xy/1000.0);
  2147.                  1: edit7.Text:=formatfloat('0.000',xy/100.0);
  2148.                  2: edit7.Text:=formatfloat('0.000',xy/10.0);
  2149.                  3: edit7.Text:=formatfloat('0.000',xy);
  2150.                  end;
  2151.                  end else begin
  2152.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2153.                    case tpl of
  2154.                  0: edit7.Text:=formatfloat('0.000',xy/1000.0);
  2155.                  1: edit7.Text:=formatfloat('0.000',xy/100.0);
  2156.                  2: edit7.Text:=formatfloat('0.000',xy/10.0);
  2157.                  3: edit7.Text:=formatfloat('0.000',xy);
  2158.                  end;
  2159.                  end;
  2160.                  end;
  2161.                1: begin label18.Caption:='uw';
  2162.                if arr[6]<127 then begin
  2163.                            xy := (arr[6]*256+arr[7]) ;
  2164.                  case tpl of
  2165.                  0: edit7.Text:=formatfloat('0.000',xy/1000.0);
  2166.                  1: edit7.Text:=formatfloat('0.000',xy/100.0);
  2167.                  2: edit7.Text:=formatfloat('0.000',xy/10.0);
  2168.                  3: edit7.Text:=formatfloat('0.000',xy);
  2169.                  end;
  2170.                  end else begin
  2171.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2172.                    case tpl of
  2173.                  0: edit7.Text:=formatfloat('0.000',xy/1000.0);
  2174.                  1: edit7.Text:=formatfloat('0.000',xy/100.0);
  2175.                  2: edit7.Text:=formatfloat('0.000',xy/10.0);
  2176.                  3: edit7.Text:=formatfloat('0.000',xy);
  2177.                  end;
  2178.                  end;
  2179.                  end;
  2180.                2: begin label18.Caption:='nw';
  2181.                if arr[6]<127 then begin
  2182.                            xy := (arr[6]*256+arr[7]) ;
  2183.                  case tpl of
  2184.                  0: edit7.Text:=formatfloat('0.000',xy/1000.0);
  2185.                  1: edit7.Text:=formatfloat('0.000',xy/100.0);
  2186.                  2: edit7.Text:=formatfloat('0.000',xy/10.0);
  2187.                  3: edit7.Text:=formatfloat('0.000',xy);
  2188.                  end;
  2189.                  end else begin
  2190.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2191.                    case tpl of
  2192.                  0: edit7.Text:=formatfloat('0.000',xy/1000.0);
  2193.                  1: edit7.Text:=formatfloat('0.000',xy/100.0);
  2194.                  2: edit7.Text:=formatfloat('0.000',xy/10.0);
  2195.                  3: edit7.Text:=formatfloat('0.000',xy);
  2196.                  end;
  2197.                  end;
  2198.                  end;
  2199.                4: begin label18.Caption:='dBm';
  2200.                 if arr[6]<127 then begin
  2201.                            xy := (arr[6]*256+arr[7]) ;
  2202.                  case tpl of
  2203.                  0: edit7.Text:=formatfloat('0.000',xy/1000.0);
  2204.                  1: edit7.Text:=formatfloat('0.000',xy/100.0);
  2205.                  2: edit7.Text:=formatfloat('0.000',xy/10.0);
  2206.                  3: edit7.Text:=formatfloat('0.000',xy);
  2207.                  end;
  2208.                  end else begin
  2209.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2210.                    case tpl of
  2211.                  0: edit7.Text:=formatfloat('0.000',xy/1000.0);
  2212.                  1: edit7.Text:=formatfloat('0.000',xy/100.0);
  2213.                  2: edit7.Text:=formatfloat('0.000',xy/10.0);
  2214.                  3: edit7.Text:=formatfloat('0.000',xy);
  2215.                  end;
  2216.                  end;
  2217.                  end;
  2218.                8:  showmessage('测量单位不能是dB。');
  2219.                9:   showmessage('超范围!');
  2220.                end;
  2221.               { if arr[6]<127 then begin
  2222.                            xy := (arr[6]*256+arr[7]) ;
  2223.                  case tpl of
  2224.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  2225.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  2226.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  2227.                  3: edit4.Text:=formatfloat('0.000',xy);
  2228.                  end;
  2229.                  end else begin
  2230.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2231.                    case tpl of
  2232.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  2233.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  2234.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  2235.                  3: edit4.Text:=formatfloat('0.000',xy);
  2236.                  end;
  2237.                  end; }
  2238.              end else   begin
  2239.              timer8.Enabled:=false;
  2240.              showmessage('帧校验错误!'); //帧校验错误
  2241.              end;
  2242.              end;
  2243.        end else  begin
  2244.        timer8.Enabled:=false;
  2245.       showmessage('响应数据错误!');
  2246.         end;
  2247.     end else begin
  2248.         sleep(10);
  2249.       timer8.Enabled:=true;
  2250.              end;
  2251.              end else begin
  2252.               timesum:=100;
  2253.               timer8.Enabled:=false;
  2254.              showmessage('响应超时!');
  2255.              end;
  2256. end;
  2257. procedure TForm1.Timer9Timer(Sender: TObject);
  2258. var
  2259. i,n,m,chksum,tp,tph,tpl:integer;  //,timesum
  2260. arr:array of byte;
  2261. tmpvar:variant;
  2262. xy:real;
  2263. str:string;
  2264. begin
  2265. str:='';
  2266.      arr:=nil;
  2267.      chksum:=$00;
  2268.     timesum:=timesum+integer(timer9.Interval)+10;
  2269.      if timesum<900 then
  2270.       begin
  2271.         if mscomm1.InBufferCount>0 then begin
  2272.              timer9.Enabled:=false;
  2273.              timesum:=100;
  2274.           n:=mscomm1.InBufferCount;
  2275.           setlength(arr,n);
  2276.           tmpvar:=mscomm1.input;
  2277.        for i:=0 to n-1 do begin
  2278.        arr[i]:=tmpvar[i];
  2279.        str:=str+inttostr(arr[i]);
  2280.        end;
  2281.        // showmessage(inttostr(arr[i]));
  2282.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then     //头校验
  2283.         begin if arr[2]<>n-5 then showmessage('长度错误!') else     //长度校验
  2284.          begin
  2285.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  2286.            if (arr[n-2]=chksum)and(arr[3]=$a3) then begin           //帧校验
  2287.                tp:=arr[4] and $f0 ;
  2288.                tph:=strtoint(floattostr(tp/16));
  2289.                tpl:=arr[4] and $0f;
  2290.                case tph of
  2291.                0:begin label19.Caption:='mw';
  2292.                if arr[6]<127 then begin
  2293.                            xy := (arr[6]*256+arr[7]) ;
  2294.                  case tpl of
  2295.                  0: edit10.Text:=formatfloat('0.000',xy/1000.0);
  2296.                  1: edit10.Text:=formatfloat('0.000',xy/100.0);
  2297.                  2: edit10.Text:=formatfloat('0.000',xy/10.0);
  2298.                  3: edit10.Text:=formatfloat('0.000',xy);
  2299.                  end;
  2300.                  end else begin
  2301.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2302.                    case tpl of
  2303.                  0: edit10.Text:=formatfloat('0.000',xy/1000.0);
  2304.                  1: edit10.Text:=formatfloat('0.000',xy/100.0);
  2305.                  2: edit10.Text:=formatfloat('0.000',xy/10.0);
  2306.                  3: edit10.Text:=formatfloat('0.000',xy);
  2307.                  end;
  2308.                  end;
  2309.                  end;
  2310.                1: begin label19.Caption:='uw';if arr[6]<127 then begin
  2311.                            xy := (arr[6]*256+arr[7]) ;
  2312.                  case tpl of
  2313.                  0: edit10.Text:=formatfloat('0.000',xy/1000.0);
  2314.                  1: edit10.Text:=formatfloat('0.000',xy/100.0);
  2315.                  2: edit10.Text:=formatfloat('0.000',xy/10.0);
  2316.                  3: edit10.Text:=formatfloat('0.000',xy);
  2317.                  end;
  2318.                  end else begin
  2319.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2320.                    case tpl of
  2321.                  0: edit10.Text:=formatfloat('0.000',xy/1000.0);
  2322.                  1: edit10.Text:=formatfloat('0.000',xy/100.0);
  2323.                  2: edit10.Text:=formatfloat('0.000',xy/10.0);
  2324.                  3: edit10.Text:=formatfloat('0.000',xy);
  2325.                  end;
  2326.                  end;
  2327.                  end;
  2328.                2: begin label19.Caption:='nw';if arr[6]<127 then begin
  2329.                            xy := (arr[6]*256+arr[7]) ;
  2330.                  case tpl of
  2331.                  0: edit10.Text:=formatfloat('0.000',xy/1000.0);
  2332.                  1: edit10.Text:=formatfloat('0.000',xy/100.0);
  2333.                  2: edit10.Text:=formatfloat('0.000',xy/10.0);
  2334.                  3: edit10.Text:=formatfloat('0.000',xy);
  2335.                  end;
  2336.                  end else begin
  2337.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2338.                    case tpl of
  2339.                  0: edit10.Text:=formatfloat('0.000',xy/1000.0);
  2340.                  1: edit10.Text:=formatfloat('0.000',xy/100.0);
  2341.                  2: edit10.Text:=formatfloat('0.000',xy/10.0);
  2342.                  3: edit10.Text:=formatfloat('0.000',xy);
  2343.                  end;
  2344.                  end;
  2345.                  end;
  2346.                4: begin label19.Caption:='dBm'; if arr[6]<127 then begin
  2347.                            xy := (arr[6]*256+arr[7]) ;
  2348.                  case tpl of
  2349.                  0: edit10.Text:=formatfloat('0.000',xy/1000.0);
  2350.                  1: edit10.Text:=formatfloat('0.000',xy/100.0);
  2351.                  2: edit10.Text:=formatfloat('0.000',xy/10.0);
  2352.                  3: edit10.Text:=formatfloat('0.000',xy);
  2353.                  end;
  2354.                  end else begin
  2355.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2356.                    case tpl of
  2357.                  0: edit10.Text:=formatfloat('0.000',xy/1000.0);
  2358.                  1: edit10.Text:=formatfloat('0.000',xy/100.0);
  2359.                  2: edit10.Text:=formatfloat('0.000',xy/10.0);
  2360.                  3: edit10.Text:=formatfloat('0.000',xy);
  2361.                  end;
  2362.                  end;
  2363.                  end;
  2364.                8:  showmessage('测量单位不能是dB。');
  2365.                9:   showmessage('超范围!');
  2366.                end;
  2367.               { if arr[6]<127 then begin
  2368.                            xy := (arr[6]*256+arr[7]) ;
  2369.                  case tpl of
  2370.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  2371.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  2372.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  2373.                  3: edit4.Text:=formatfloat('0.000',xy);
  2374.                  end;
  2375.                  end else begin
  2376.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2377.                    case tpl of
  2378.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  2379.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  2380.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  2381.                  3: edit4.Text:=formatfloat('0.000',xy);
  2382.                  end;
  2383.                  end; }
  2384.              end else   begin
  2385.              timer9.Enabled:=false;
  2386.              showmessage('帧校验错误!'); //帧校验错误
  2387.              end;
  2388.              end;
  2389.        end else  begin
  2390.        timer9.Enabled:=false;
  2391.       showmessage('响应数据错误!');
  2392.         end;
  2393.     end else begin
  2394.         sleep(10);
  2395.       timer9.Enabled:=true;
  2396.              end;
  2397.              end else begin
  2398.               timesum:=100;
  2399.               timer9.Enabled:=false;
  2400.              showmessage('响应超时!');
  2401.              end;
  2402. end;
  2403. procedure TForm1.Timer10Timer(Sender: TObject);
  2404. var
  2405. i,n,m,chksum,tp,tph,tpl:integer;  //,timesum
  2406. arr:array of byte;
  2407. tmpvar:variant;
  2408. xy:real;
  2409. str:string;
  2410. begin
  2411. str:='';
  2412.      arr:=nil;
  2413.      chksum:=$00;
  2414.     timesum:=timesum+integer(timer10.Interval)+10;
  2415.      if timesum<900 then
  2416.       begin
  2417.         if mscomm1.InBufferCount>0 then begin
  2418.              timer10.Enabled:=false;
  2419.              timesum:=100;
  2420.           n:=mscomm1.InBufferCount;
  2421.           setlength(arr,n);
  2422.           tmpvar:=mscomm1.input;
  2423.        for i:=0 to n-1 do begin
  2424.        arr[i]:=tmpvar[i];
  2425.        str:=str+inttostr(arr[i]);
  2426.        end;
  2427.        // showmessage(inttostr(arr[i]));
  2428.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then     //头校验
  2429.         begin if arr[2]<>n-5 then showmessage('长度错误!') else     //长度校验
  2430.          begin
  2431.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  2432.            if (arr[n-2]=chksum)and(arr[3]=$a3) then begin           //帧校验
  2433.                tp:=arr[4] and $f0 ;
  2434.                tph:=strtoint(floattostr(tp/16));
  2435.                tpl:=arr[4] and $0f;
  2436.                case tph of
  2437.                0:begin label20.Caption:='mw';
  2438.                if arr[6]<127 then begin
  2439.                            xy := (arr[6]*256+arr[7]) ;
  2440.                  case tpl of
  2441.                  0: edit13.Text:=formatfloat('0.000',xy/1000.0);
  2442.                  1: edit13.Text:=formatfloat('0.000',xy/100.0);
  2443.                  2: edit13.Text:=formatfloat('0.000',xy/10.0);
  2444.                  3: edit13.Text:=formatfloat('0.000',xy);
  2445.                  end;
  2446.                  end else begin
  2447.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2448.                    case tpl of
  2449.                  0: edit13.Text:=formatfloat('0.000',xy/1000.0);
  2450.                  1: edit13.Text:=formatfloat('0.000',xy/100.0);
  2451.                  2: edit13.Text:=formatfloat('0.000',xy/10.0);
  2452.                  3: edit13.Text:=formatfloat('0.000',xy);
  2453.                  end;
  2454.                  end;
  2455.                  end;
  2456.                1: begin label20.Caption:='uw';if arr[6]<127 then begin
  2457.                            xy := (arr[6]*256+arr[7]) ;
  2458.                  case tpl of
  2459.                  0: edit13.Text:=formatfloat('0.000',xy/1000.0);
  2460.                  1: edit13.Text:=formatfloat('0.000',xy/100.0);
  2461.                  2: edit13.Text:=formatfloat('0.000',xy/10.0);
  2462.                  3: edit13.Text:=formatfloat('0.000',xy);
  2463.                  end;
  2464.                  end else begin
  2465.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2466.                    case tpl of
  2467.                  0: edit13.Text:=formatfloat('0.000',xy/1000.0);
  2468.                  1: edit13.Text:=formatfloat('0.000',xy/100.0);
  2469.                  2: edit13.Text:=formatfloat('0.000',xy/10.0);
  2470.                  3: edit13.Text:=formatfloat('0.000',xy);
  2471.                  end;
  2472.                  end;
  2473.                  end;
  2474.                2: begin label20.Caption:='nw';if arr[6]<127 then begin
  2475.                            xy := (arr[6]*256+arr[7]) ;
  2476.                  case tpl of
  2477.                  0: edit13.Text:=formatfloat('0.000',xy/1000.0);
  2478.                  1: edit13.Text:=formatfloat('0.000',xy/100.0);
  2479.                  2: edit13.Text:=formatfloat('0.000',xy/10.0);
  2480.                  3: edit13.Text:=formatfloat('0.000',xy);
  2481.                  end;
  2482.                  end else begin
  2483.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2484.                    case tpl of
  2485.                  0: edit13.Text:=formatfloat('0.000',xy/1000.0);
  2486.                  1: edit13.Text:=formatfloat('0.000',xy/100.0);
  2487.                  2: edit13.Text:=formatfloat('0.000',xy/10.0);
  2488.                  3: edit13.Text:=formatfloat('0.000',xy);
  2489.                  end;
  2490.                  end;
  2491.                  end;
  2492.                4: begin label20.Caption:='dBm'; if arr[6]<127 then begin
  2493.                            xy := (arr[6]*256+arr[7]) ;
  2494.                  case tpl of
  2495.                  0: edit13.Text:=formatfloat('0.000',xy/1000.0);
  2496.                  1: edit13.Text:=formatfloat('0.000',xy/100.0);
  2497.                  2: edit13.Text:=formatfloat('0.000',xy/10.0);
  2498.                  3: edit13.Text:=formatfloat('0.000',xy);
  2499.                  end;
  2500.                  end else begin
  2501.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2502.                    case tpl of
  2503.                  0: edit13.Text:=formatfloat('0.000',xy/1000.0);
  2504.                  1: edit13.Text:=formatfloat('0.000',xy/100.0);
  2505.                  2: edit13.Text:=formatfloat('0.000',xy/10.0);
  2506.                  3: edit13.Text:=formatfloat('0.000',xy);
  2507.                  end;
  2508.                  end;
  2509.                  end;
  2510.                8:  showmessage('测量单位不能是dB。');
  2511.                9:   showmessage('超范围!');
  2512.                end;
  2513.               { if arr[6]<127 then begin
  2514.                            xy := (arr[6]*256+arr[7]) ;
  2515.                  case tpl of
  2516.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  2517.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  2518.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  2519.                  3: edit4.Text:=formatfloat('0.000',xy);
  2520.                  end;
  2521.                  end else begin
  2522.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2523.                    case tpl of
  2524.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  2525.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  2526.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  2527.                  3: edit4.Text:=formatfloat('0.000',xy);
  2528.                  end;
  2529.                  end; }
  2530.              end else   begin
  2531.              timer10.Enabled:=false;
  2532.              showmessage('帧校验错误!'); //帧校验错误
  2533.              end;
  2534.              end;
  2535.        end else  begin
  2536.        timer10.Enabled:=false;
  2537.       showmessage('响应数据错误!');
  2538.         end;
  2539.     end else begin
  2540.         sleep(10);
  2541.       timer10.Enabled:=true;
  2542.              end;
  2543.              end else begin
  2544.               timesum:=100;
  2545.               timer10.Enabled:=false;
  2546.              showmessage('响应超时!');
  2547.              end;
  2548. end;
  2549. procedure TForm1.Timer11Timer(Sender: TObject);
  2550. var
  2551. i,n,m,chksum,tp,tph,tpl:integer;  //,timesum
  2552. arr:array of byte;
  2553. tmpvar:variant;
  2554. xy:real;
  2555. str:string;
  2556. begin
  2557. str:='';
  2558.      arr:=nil;
  2559.      chksum:=$00;
  2560.     timesum:=timesum+integer(timer11.Interval)+10;
  2561.      if timesum<900 then
  2562.       begin
  2563.         if mscomm1.InBufferCount>0 then begin
  2564.              timer11.Enabled:=false;
  2565.              timesum:=100;
  2566.           n:=mscomm1.InBufferCount;
  2567.           setlength(arr,n);
  2568.           tmpvar:=mscomm1.input;
  2569.        for i:=0 to n-1 do begin
  2570.        arr[i]:=tmpvar[i];
  2571.        str:=str+inttostr(arr[i]);
  2572.        end;
  2573.        // showmessage(inttostr(arr[i]));
  2574.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then     //头校验
  2575.         begin if arr[2]<>n-5 then showmessage('长度错误!') else     //长度校验
  2576.          begin
  2577.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  2578.            if (arr[n-2]=chksum)and(arr[3]=$a3) then begin           //帧校验
  2579.                tp:=arr[4] and $f0 ;
  2580.                tph:=strtoint(floattostr(tp/16));
  2581.                tpl:=arr[4] and $0f;
  2582.                case tph of
  2583.                0:begin label21.Caption:='mw';
  2584.                if arr[6]<127 then begin
  2585.                            xy := (arr[6]*256+arr[7]) ;
  2586.                  case tpl of
  2587.                  0: edit16.Text:=formatfloat('0.000',xy/1000.0);
  2588.                  1: edit16.Text:=formatfloat('0.000',xy/100.0);
  2589.                  2: edit16.Text:=formatfloat('0.000',xy/10.0);
  2590.                  3: edit16.Text:=formatfloat('0.000',xy);
  2591.                  end;
  2592.                  end else begin
  2593.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2594.                    case tpl of
  2595.                  0: edit16.Text:=formatfloat('0.000',xy/1000.0);
  2596.                  1: edit16.Text:=formatfloat('0.000',xy/100.0);
  2597.                  2: edit16.Text:=formatfloat('0.000',xy/10.0);
  2598.                  3: edit16.Text:=formatfloat('0.000',xy);
  2599.                  end;
  2600.                  end;
  2601.                  end;
  2602.                1: begin label21.Caption:='uw';if arr[6]<127 then begin
  2603.                            xy := (arr[6]*256+arr[7]) ;
  2604.                  case tpl of
  2605.                  0: edit16.Text:=formatfloat('0.000',xy/1000.0);
  2606.                  1: edit16.Text:=formatfloat('0.000',xy/100.0);
  2607.                  2: edit16.Text:=formatfloat('0.000',xy/10.0);
  2608.                  3: edit16.Text:=formatfloat('0.000',xy);
  2609.                  end;
  2610.                  end else begin
  2611.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2612.                    case tpl of
  2613.                  0: edit16.Text:=formatfloat('0.000',xy/1000.0);
  2614.                  1: edit16.Text:=formatfloat('0.000',xy/100.0);
  2615.                  2: edit16.Text:=formatfloat('0.000',xy/10.0);
  2616.                  3: edit16.Text:=formatfloat('0.000',xy);
  2617.                  end;
  2618.                  end;
  2619.                  end;
  2620.                2: begin label21.Caption:='nw';if arr[6]<127 then begin
  2621.                            xy := (arr[6]*256+arr[7]) ;
  2622.                  case tpl of
  2623.                  0: edit16.Text:=formatfloat('0.000',xy/1000.0);
  2624.                  1: edit16.Text:=formatfloat('0.000',xy/100.0);
  2625.                  2: edit16.Text:=formatfloat('0.000',xy/10.0);
  2626.                  3: edit16.Text:=formatfloat('0.000',xy);
  2627.                  end;
  2628.                  end else begin
  2629.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2630.                    case tpl of
  2631.                  0: edit16.Text:=formatfloat('0.000',xy/1000.0);
  2632.                  1: edit16.Text:=formatfloat('0.000',xy/100.0);
  2633.                  2: edit16.Text:=formatfloat('0.000',xy/10.0);
  2634.                  3: edit16.Text:=formatfloat('0.000',xy);
  2635.                  end;
  2636.                  end;
  2637.                  end;
  2638.                4: begin label21.Caption:='dBm'; if arr[6]<127 then begin
  2639.                            xy := (arr[6]*256+arr[7]) ;
  2640.                  case tpl of
  2641.                  0: edit16.Text:=formatfloat('0.000',xy/1000.0);
  2642.                  1: edit16.Text:=formatfloat('0.000',xy/100.0);
  2643.                  2: edit16.Text:=formatfloat('0.000',xy/10.0);
  2644.                  3: edit16.Text:=formatfloat('0.000',xy);
  2645.                  end;
  2646.                  end else begin
  2647.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2648.                    case tpl of
  2649.                  0: edit16.Text:=formatfloat('0.000',xy/1000.0);
  2650.                  1: edit16.Text:=formatfloat('0.000',xy/100.0);
  2651.                  2: edit16.Text:=formatfloat('0.000',xy/10.0);
  2652.                  3: edit16.Text:=formatfloat('0.000',xy);
  2653.                  end;
  2654.                  end;
  2655.                  end;
  2656.                8:  showmessage('测量单位不能是dB。');
  2657.                9:   showmessage('超范围!');
  2658.                end;
  2659.               { if arr[6]<127 then begin
  2660.                            xy := (arr[6]*256+arr[7]) ;
  2661.                  case tpl of
  2662.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  2663.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  2664.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  2665.                  3: edit4.Text:=formatfloat('0.000',xy);
  2666.                  end;
  2667.                  end else begin
  2668.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2669.                    case tpl of
  2670.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  2671.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  2672.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  2673.                  3: edit4.Text:=formatfloat('0.000',xy);
  2674.                  end;
  2675.                  end; }
  2676.              end else   begin
  2677.              timer11.Enabled:=false;
  2678.              showmessage('帧校验错误!'); //帧校验错误
  2679.              end;
  2680.              end;
  2681.        end else  begin
  2682.        timer11.Enabled:=false;
  2683.       showmessage('响应数据错误!');
  2684.         end;
  2685.     end else begin
  2686.         sleep(10);
  2687.       timer11.Enabled:=true;
  2688.              end;
  2689.              end else begin
  2690.               timesum:=100;
  2691.               timer11.Enabled:=false;
  2692.              showmessage('响应超时!');
  2693.              end;
  2694. end;
  2695. procedure TForm1.Timer12Timer(Sender: TObject);
  2696. var
  2697. i,n,m,chksum,tp,tph,tpl:integer;  //,timesum
  2698. arr:array of byte;
  2699. tmpvar:variant;
  2700. xy:real;
  2701. str:string;
  2702. begin
  2703. str:='';
  2704.      arr:=nil;
  2705.      chksum:=$00;
  2706.     timesum:=timesum+integer(timer12.Interval)+10;
  2707.      if timesum<900 then
  2708.       begin
  2709.         if mscomm1.InBufferCount>0 then begin
  2710.              timer12.Enabled:=false;
  2711.              timesum:=100;
  2712.           n:=mscomm1.InBufferCount;
  2713.           setlength(arr,n);
  2714.           tmpvar:=mscomm1.input;
  2715.        for i:=0 to n-1 do begin
  2716.        arr[i]:=tmpvar[i];
  2717.        str:=str+inttostr(arr[i]);
  2718.        end;
  2719.        // showmessage(inttostr(arr[i]));
  2720.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then     //头校验
  2721.         begin if arr[2]<>n-5 then showmessage('长度错误!') else     //长度校验
  2722.          begin
  2723.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  2724.            if (arr[n-2]=chksum)and(arr[3]=$a3) then begin           //帧校验
  2725.                tp:=arr[4] and $f0 ;
  2726.                tph:=strtoint(floattostr(tp/16));
  2727.                tpl:=arr[4] and $0f;
  2728.                case tph of
  2729.                0:begin label22.Caption:='mw';
  2730.                if arr[6]<127 then begin
  2731.                            xy := (arr[6]*256+arr[7]) ;
  2732.                  case tpl of
  2733.                  0: edit19.Text:=formatfloat('0.000',xy/1000.0);
  2734.                  1: edit19.Text:=formatfloat('0.000',xy/100.0);
  2735.                  2: edit19.Text:=formatfloat('0.000',xy/10.0);
  2736.                  3: edit19.Text:=formatfloat('0.000',xy);
  2737.                  end;
  2738.                  end else begin
  2739.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2740.                    case tpl of
  2741.                  0: edit19.Text:=formatfloat('0.000',xy/1000.0);
  2742.                  1: edit19.Text:=formatfloat('0.000',xy/100.0);
  2743.                  2: edit19.Text:=formatfloat('0.000',xy/10.0);
  2744.                  3: edit19.Text:=formatfloat('0.000',xy);
  2745.                  end;
  2746.                  end;
  2747.                  end;
  2748.                1: begin label22.Caption:='uw';if arr[6]<127 then begin
  2749.                            xy := (arr[6]*256+arr[7]) ;
  2750.                  case tpl of
  2751.                  0: edit19.Text:=formatfloat('0.000',xy/1000.0);
  2752.                  1: edit19.Text:=formatfloat('0.000',xy/100.0);
  2753.                  2: edit19.Text:=formatfloat('0.000',xy/10.0);
  2754.                  3: edit19.Text:=formatfloat('0.000',xy);
  2755.                  end;
  2756.                  end else begin
  2757.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2758.                    case tpl of
  2759.                  0: edit19.Text:=formatfloat('0.000',xy/1000.0);
  2760.                  1: edit19.Text:=formatfloat('0.000',xy/100.0);
  2761.                  2: edit19.Text:=formatfloat('0.000',xy/10.0);
  2762.                  3: edit19.Text:=formatfloat('0.000',xy);
  2763.                  end;
  2764.                  end;
  2765.                  end;
  2766.                2: begin label22.Caption:='nw';if arr[6]<127 then begin
  2767.                            xy := (arr[6]*256+arr[7]) ;
  2768.                  case tpl of
  2769.                  0: edit19.Text:=formatfloat('0.000',xy/1000.0);
  2770.                  1: edit19.Text:=formatfloat('0.000',xy/100.0);
  2771.                  2: edit19.Text:=formatfloat('0.000',xy/10.0);
  2772.                  3: edit19.Text:=formatfloat('0.000',xy);
  2773.                  end;
  2774.                  end else begin
  2775.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2776.                    case tpl of
  2777.                  0: edit19.Text:=formatfloat('0.000',xy/1000.0);
  2778.                  1: edit19.Text:=formatfloat('0.000',xy/100.0);
  2779.                  2: edit19.Text:=formatfloat('0.000',xy/10.0);
  2780.                  3: edit19.Text:=formatfloat('0.000',xy);
  2781.                  end;
  2782.                  end;
  2783.                  end;
  2784.                4: begin label22.Caption:='dBm'; if arr[6]<127 then begin
  2785.                            xy := (arr[6]*256+arr[7]) ;
  2786.                  case tpl of
  2787.                  0: edit19.Text:=formatfloat('0.000',xy/1000.0);
  2788.                  1: edit19.Text:=formatfloat('0.000',xy/100.0);
  2789.                  2: edit19.Text:=formatfloat('0.000',xy/10.0);
  2790.                  3: edit19.Text:=formatfloat('0.000',xy);
  2791.                  end;
  2792.                  end else begin
  2793.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2794.                    case tpl of
  2795.                  0: edit19.Text:=formatfloat('0.000',xy/1000.0);
  2796.                  1: edit19.Text:=formatfloat('0.000',xy/100.0);
  2797.                  2: edit19.Text:=formatfloat('0.000',xy/10.0);
  2798.                  3: edit19.Text:=formatfloat('0.000',xy);
  2799.                  end;
  2800.                  end;
  2801.                  end;
  2802.                8:  showmessage('测量单位不能是dB。');
  2803.                9:   showmessage('超范围!');
  2804.                end;
  2805.               { if arr[6]<127 then begin
  2806.                            xy := (arr[6]*256+arr[7]) ;
  2807.                  case tpl of
  2808.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  2809.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  2810.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  2811.                  3: edit4.Text:=formatfloat('0.000',xy);
  2812.                  end;
  2813.                  end else begin
  2814.                          xy := -((arr[6]-128)*256+arr[7]) ;
  2815.                    case tpl of
  2816.                  0: edit4.Text:=formatfloat('0.000',xy/1000.0);
  2817.                  1: edit4.Text:=formatfloat('0.000',xy/100.0);
  2818.                  2: edit4.Text:=formatfloat('0.000',xy/10.0);
  2819.                  3: edit4.Text:=formatfloat('0.000',xy);
  2820.                  end;
  2821.                  end; }
  2822.              end else   begin
  2823.              timer12.Enabled:=false;
  2824.              showmessage('帧校验错误!'); //帧校验错误
  2825.              end;
  2826.              end;
  2827.        end else  begin
  2828.        timer12.Enabled:=false;
  2829.       showmessage('响应数据错误!');
  2830.         end;
  2831.     end else begin
  2832.         sleep(10);
  2833.       timer12.Enabled:=true;
  2834.              end;
  2835.              end else begin
  2836.               timesum:=100;
  2837.               timer12.Enabled:=false;
  2838.              showmessage('响应超时!');
  2839.              end;
  2840. end;
  2841. procedure TForm1.Button24Click(Sender: TObject);
  2842. var
  2843.   len,i,count:integer;
  2844.    //tmpstr:string;
  2845.    tmpvar:variant;
  2846.    xornum:byte;
  2847.    arr:array of byte;
  2848. begin
  2849. arr:=nil;
  2850.   begin if not mscomm1.PortOpen then begin
  2851.     showmessage('serials is not open!');
  2852.      end else begin
  2853.      setlength(arr,7);
  2854.         // f:=strtoint(edit2.text);
  2855.             arr[0]:=$7e;   //soi
  2856.            arr[1]:=$10;   //ver
  2857.             arr[2]:= $02;    //length
  2858.             arr[3]:=$a3;     //cid
  2859.            arr[4]:=$0ff;      //datainfo
  2860.           // arr[5]:=f div 255;
  2861.           //  arr[6]:= f mod 255   ;
  2862.             xornum:= arr[2] xor arr[3] xor arr[4] ;//xor arr[5]xor arr[6];
  2863.             arr[5]:=xornum;
  2864.             arr[6]:=$0d;
  2865.   // send data
  2866.               len:=length(arr);
  2867.               //showmessage('hex:point'+inttostr(len));
  2868.            i:=0;
  2869.             count:=0;
  2870.             tmpvar:=vararraycreate([0,0],varbyte);
  2871.             //tmpvar[count]:=arr[i];
  2872.             //inc(count);
  2873.             //inc(i);
  2874.              while(count<=len-1)do begin
  2875.                         tmpvar[count]:=arr[i];
  2876.                         inc(count);
  2877.                         inc(i);
  2878.                         vararrayredim(tmpvar,count);
  2879.                     end;
  2880.       MSComm1.Output:=tmpvar;
  2881.       timer13.Enabled:=true;
  2882.  end;
  2883.    
  2884.     end;
  2885. end;
  2886. procedure TForm1.Timer13Timer(Sender: TObject);
  2887. var
  2888. i,n,m,chksum:integer;
  2889. arr:array of byte;
  2890. tmpvar:variant;
  2891. begin
  2892.      timer13.Enabled:=false;
  2893.      arr:=nil;
  2894.      chksum:=0;
  2895.     timesum:=timesum+integer(timer13.Interval)+10;
  2896.      if timesum<900 then
  2897.       begin
  2898.         if mscomm1.InBufferCount>0 then begin
  2899.           n:=mscomm1.InBufferCount;
  2900.           setlength(arr,n);
  2901.           tmpvar:=mscomm1.Input;
  2902.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  2903.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  2904.         begin
  2905.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  2906.            if (chksum=arr[n-2])and(arr[3]=$a3) then begin
  2907.                edit30.Text:=inttostr(arr[4]);
  2908.                edit29.Clear;
  2909.                  edit28.Clear;
  2910.                  edit27.Clear;
  2911.             { if  (arr[4]=$0cc)or(arr[4]=$66) then
  2912.                  showmessage('参数设定成功!')
  2913.                else   showmessage('参数设定失败!');}
  2914.              end else begin
  2915.              timer13.Enabled:=false;
  2916.              showmessage('帧校验错误!'); //帧校验错误
  2917.              end;
  2918.          end else
  2919.          begin
  2920.          timer13.Enabled:=false;
  2921.          showmessage('回应帧错误!');
  2922.        //showmessage('响应数据错误!');
  2923.        end;
  2924.          end else begin
  2925.         sleep(10);
  2926.        timer13.Enabled:=true;
  2927.          end;
  2928.       end else begin
  2929.       timesum:=100;
  2930.              timer13.Enabled:=false;
  2931.              showmessage('响应超时!');
  2932.              end;
  2933. end;
  2934. procedure TForm1.Button25Click(Sender: TObject);
  2935. var
  2936.  point,len,i,p,count:integer;
  2937.  // f:string;
  2938.    tmpvar:variant;
  2939.    xornum:byte;
  2940.    arr:array of byte;
  2941. begin
  2942. arr:=nil;
  2943. point:=0;
  2944.    if not mscomm1.PortOpen then begin
  2945.     showmessage('serials is not open!');
  2946.      end else begin
  2947.       if combobox2.ItemIndex=0 then showmessage('请选择上传类型!')
  2948.       else begin
  2949.                  if   combobox2.ItemIndex=3  then  begin
  2950.                   if edit31.Text='' then showmessage(' 输入上传数组号!')
  2951.                    else    begin
  2952.                     point:=strtoint(edit31.Text);
  2953.                    zuhao:=point;
  2954.                  button24.Click;
  2955.                 TIMEDELAY(1000);
  2956.                   if edit30.Text='' then showmessage('数组数目上传失败!')
  2957.                   else begin
  2958.                 p:=strtoint(edit30.text);
  2959.                // f:= inputbox('输入','输入数组号','0');
  2960.                 //point:=strtoint(inputbox('输入','输入数组号','0'));
  2961.                   if (zuhao<0  )and (zuhao>100) then showmessage('数组号输入非法!')
  2962.                   else begin
  2963.                   if zuhao>p then showmessage('目前有'+inttostr(p)+'组数,请重新输入!')
  2964.                   else begin //send data
  2965.         setlength(arr,7);
  2966.             arr[0]:=$7e;   //soi
  2967.            arr[1]:=$10;   //ver
  2968.             arr[2]:= $02;    //length
  2969.             arr[3]:=$a3;     //cid
  2970.            arr[4]:=point;      //datainfo
  2971.             xornum:= arr[2] xor arr[3] xor arr[4];
  2972.             arr[5]:=xornum;
  2973.             arr[6]:=$0d;
  2974.   // send data
  2975.               len:=length(arr);
  2976.            i:=0;
  2977.             count:=0;
  2978.             tmpvar:=vararraycreate([0,0],varbyte);
  2979.              while(count<=len-1)do begin
  2980.                         tmpvar[count]:=arr[i];
  2981.                         inc(count);
  2982.                         inc(i);
  2983.                         vararrayredim(tmpvar,count);
  2984.                     end;
  2985.       MSComm1.Output:=tmpvar;
  2986.       timer14.Enabled:=true;
  2987.       end ;
  2988.      // end;
  2989.      end ;
  2990.       end ;
  2991.        end;
  2992.       //showmessage('hex:point'+f);
  2993.       //end;
  2994.       end else begin
  2995.       if combobox2.ItemIndex=1 then
  2996.       begin
  2997.          point:=$00;
  2998.          edit30.Clear;
  2999.          edit29.Clear;
  3000.          end;
  3001.        if combobox2.ItemIndex=2  then point:=$0ff ;
  3002.          setlength(arr,7);
  3003.             arr[0]:=$7e;   //soi
  3004.            arr[1]:=$10;   //ver
  3005.             arr[2]:= $02;    //length
  3006.             arr[3]:=$a3;     //cid
  3007.            arr[4]:=point;      //datainfo
  3008.             xornum:= arr[2] xor arr[3] xor arr[4];
  3009.             arr[5]:=xornum;
  3010.             arr[6]:=$0d;
  3011.   // send data
  3012.               len:=length(arr);
  3013.            i:=0;
  3014.             count:=0;
  3015.             tmpvar:=vararraycreate([0,0],varbyte);
  3016.              while(count<=len-1)do begin
  3017.                         tmpvar[count]:=arr[i];
  3018.                         inc(count);
  3019.                         inc(i);
  3020.                         vararrayredim(tmpvar,count);
  3021.                     end;
  3022.       MSComm1.Output:=tmpvar;
  3023.       timer14.Enabled:=true;
  3024.       end;
  3025.  end;
  3026.  end;
  3027.   end;
  3028. //end;
  3029. procedure TForm1.Timer14Timer(Sender: TObject);
  3030. var
  3031. i,n,m,chksum:integer;  
  3032. arr:array of byte;
  3033. tmpvar:variant;
  3034. tp,tph,tpl:integer;
  3035. begin
  3036.      arr:=nil;
  3037.      chksum:=0;
  3038.     timesum:=timesum+integer(timer14.Interval)+10;
  3039.      if timesum<900 then
  3040.       begin
  3041.         if mscomm1.InBufferCount>0 then begin
  3042.         timer14.Enabled:=false;
  3043.         timesum:=100;
  3044.           n:=mscomm1.InBufferCount;
  3045.           setlength(arr,n);
  3046.           tmpvar:=mscomm1.Input;
  3047.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  3048.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  3049.         begin
  3050.         if arr[2]<>n-5 then showmessage('长度错误!') else     //长度校验
  3051.          begin
  3052.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  3053.            if (chksum=arr[n-2])and(arr[3]=$a3) then begin
  3054.           if combobox2.ItemIndex=2 then   begin
  3055.                   edit27.Clear;
  3056.                   edit28.Clear;
  3057.                   edit29.Clear;
  3058.                   edit30.Clear;
  3059.                  edit30.Text:=inttostr(arr[4]);
  3060.            end else begin
  3061.              tp:=arr[4] and $f0 ;
  3062.                tph:=strtoint(floattostr(tp/16));
  3063.                tpl:=arr[4]and $0f;
  3064.               case tph of
  3065.                    0: begin label11.Caption:='mw';
  3066.                    if arr[6]>127 then  begin
  3067.                   case tpl of
  3068.                   0: edit28.text:=formatfloat('0.000', -((arr[6]-128)*256+arr[7])/1000.0);
  3069.                   1: edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
  3070.                   2:edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/10.0);
  3071.                   3: edit28.text:=formatfloat('0.00', -(arr[6]-128)*256+arr[7]);
  3072.                   end;
  3073.                  // edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
  3074.                    timesum:=100;
  3075.                     end
  3076.                     else begin
  3077.                      case tpl of
  3078.                   0: edit28.text:=formatfloat('0.000', (arr[6]*256+arr[7])/1000.0);
  3079.                   1: edit28.text:=formatfloat('0.00', (arr[6]*256+arr[7])/100.0);
  3080.                   2:edit28.text:=formatfloat('0.00',(arr[6]*256+arr[7])/10.0);
  3081.                   3: edit28.text:=formatfloat('0.00',arr[6]*256+arr[7]);
  3082.                      end;
  3083.                   end;
  3084.                   end;
  3085.                    1: begin label11.Caption:='uw'; if arr[6]>127 then  begin
  3086.                   case tpl of
  3087.                   0: edit28.text:=formatfloat('0.000', -((arr[6]-128)*256+arr[7])/1000.0);
  3088.                   1: edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
  3089.                   2:edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/10.0);
  3090.                   3: edit28.text:=formatfloat('0.00', -(arr[6]-128)*256+arr[7]);
  3091.                   end;
  3092.                  // edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
  3093.                    timesum:=100;
  3094.                     end
  3095.                     else begin
  3096.                      case tpl of
  3097.                   0: edit28.text:=formatfloat('0.000', (arr[6]*256+arr[7])/1000.0);
  3098.                   1: edit28.text:=formatfloat('0.00', (arr[6]*256+arr[7])/100.0);
  3099.                   2:edit28.text:=formatfloat('0.00',(arr[6]*256+arr[7])/10.0);
  3100.                   3: edit28.text:=formatfloat('0.00',arr[6]*256+arr[7]);
  3101.                      end;
  3102.                   end;
  3103.                   end;
  3104.                    2:begin label11.Caption:='nw'; if arr[6]>127 then  begin
  3105.                   case tpl of
  3106.                   0: edit28.text:=formatfloat('0.000', -((arr[6]-128)*256+arr[7])/1000.0);
  3107.                   1: edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
  3108.                   2:edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/10.0);
  3109.                   3: edit28.text:=formatfloat('0.00', -(arr[6]-128)*256+arr[7]);
  3110.                   end;
  3111.                  // edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
  3112.                    timesum:=100;
  3113.                     end
  3114.                     else begin
  3115.                      case tpl of
  3116.                   0: edit28.text:=formatfloat('0.000', (arr[6]*256+arr[7])/1000.0);
  3117.                   1: edit28.text:=formatfloat('0.00', (arr[6]*256+arr[7])/100.0);
  3118.                   2:edit28.text:=formatfloat('0.00',(arr[6]*256+arr[7])/10.0);
  3119.                   3: edit28.text:=formatfloat('0.00',arr[6]*256+arr[7]);
  3120.                      end;
  3121.                   end;
  3122.                   end;
  3123.                    4: begin label11.Caption:='dBm';  if arr[6]>127 then  begin
  3124.                   case tpl of
  3125.                   0: edit28.text:=formatfloat('0.000', -((arr[6]-128)*256+arr[7])/1000.0);
  3126.                   1: edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
  3127.                   2:edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/10.0);
  3128.                   3: edit28.text:=formatfloat('0.00', -(arr[6]-128)*256+arr[7]);
  3129.                   end;
  3130.                  // edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
  3131.                    timesum:=100;
  3132.                     end
  3133.                     else begin
  3134.                      case tpl of
  3135.                   0: edit28.text:=formatfloat('0.000', (arr[6]*256+arr[7])/1000.0);
  3136.                   1: edit28.text:=formatfloat('0.00', (arr[6]*256+arr[7])/100.0);
  3137.                   2:edit28.text:=formatfloat('0.00',(arr[6]*256+arr[7])/10.0);
  3138.                   3: edit28.text:=formatfloat('0.00',arr[6]*256+arr[7]);
  3139.                      end;
  3140.                   end;
  3141.                   end;
  3142.                    8: showmessage('单位为dB,请调整单位!');
  3143.                    9: showmessage('超范围!');
  3144.                    end;
  3145.                   case arr[5] of
  3146.                  0:  edit27.text:='1310';
  3147.                  1:  edit27.Text:='1550';
  3148.            2: edit27.Text:='850';
  3149.                   3:edit27.Text:='980';
  3150.                   end;
  3151.                  { if arr[6]>127 then  begin
  3152.                   case tpl of
  3153.                   0: edit28.text:=formatfloat('0.000', -((arr[6]-128)*256+arr[7])/1000.0);
  3154.                   1: edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
  3155.                   2:edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/10.0);
  3156.                   3: edit28.text:=formatfloat('0.00', -(arr[6]-128)*256+arr[7]);
  3157.                   end;
  3158.                  // edit28.text:=formatfloat('0.00', -((arr[6]-128)*256+arr[7])/100.0);
  3159.                    timesum:=100;
  3160.                     end
  3161.                     else begin
  3162.                      case tpl of
  3163.                   0: edit28.text:=formatfloat('0.000', (arr[6]*256+arr[7])/1000.0);
  3164.                   1: edit28.text:=formatfloat('0.00', (arr[6]*256+arr[7])/100.0);
  3165.                   2:edit28.text:=formatfloat('0.00',(arr[6]*256+arr[7])/10.0);
  3166.                   3: edit28.text:=formatfloat('0.00',arr[6]*256+arr[7]);
  3167.                      end;
  3168.                   end; }
  3169.                    if combobox2.ItemIndex=3 then begin
  3170.                    edit29.Clear;
  3171.                    edit29.text:=inttostr(zuhao);
  3172.                    //edit31.Visible:=false;
  3173.                    //label16.Visible:=false;
  3174.                    end;
  3175.                   end;
  3176.                   //end;
  3177.                    //end;
  3178.              end else     begin
  3179.                timer14.Enabled:=false;
  3180.              showmessage('帧校验错误!');
  3181.              end;
  3182.              end;
  3183.         end else   begin
  3184.         timer14.Enabled:=false;
  3185.        showmessage('响应数据错误!');
  3186.        end;
  3187.     end else begin
  3188.         sleep(10);
  3189.       timer14.Enabled:=true;
  3190.              end;
  3191.              end else begin
  3192.               timesum:=100;
  3193.              timer14.Enabled:=false;
  3194.              showmessage('响应超时!');
  3195.              end;
  3196. end;
  3197. procedure TForm1.Button28Click(Sender: TObject);
  3198. var
  3199. text:textfile;
  3200. begin
  3201. if edit1.Text<>'' then begin
  3202.         if zuhao<>-1 then begin
  3203.      if savedialog1.Execute then begin
  3204.           savedialog1.FileName:=edit1.Text+'上传参数存储'+'.txt';
  3205.           if fileexists(savedialog1.FileName) then
  3206.        begin
  3207.           assignfile(text,savedialog1.FileName);
  3208.           append(text);
  3209.          try
  3210.          writeln(text,'第',zuhao,'组','           ',edit27.text,'       ',edit28.text,'     ');
  3211.             flush(text);
  3212.          finally
  3213.            closefile(text);
  3214.          end;
  3215.          flag:=true;
  3216.         end
  3217.        else begin
  3218.           assignfile(text,savedialog1.FileName);
  3219.           rewrite(text);
  3220.          try
  3221.          writeln(text,'存储数据组号   '+'通道0  '+'  通道5'+'  1310nm'+'  1550nm'+'  850nm'+'  980nm');
  3222.          writeln(text,'第',zuhao,'组','           ',edit27.text,'       ',edit28.text,'     ');
  3223.          finally
  3224.            closefile(text);
  3225.          end;
  3226.          flag:=true;
  3227.          end;
  3228.     end ;
  3229.     end else begin
  3230.           showmessage('未选择数据组号!');
  3231.      end;
  3232.      end else begin
  3233.          showmessage('先输入机器编号!');
  3234.     end;
  3235.     end;
  3236. procedure TForm1.Button19Click(Sender: TObject);
  3237.   var
  3238.     v,len,i,count:integer;
  3239.    tmpvar:variant;
  3240.    xornum:byte;
  3241.    arr:array of byte;
  3242.    f:real;
  3243.    p:string;
  3244. begin
  3245. //P:=0;
  3246.     arr:=nil;
  3247.     f:=0;
  3248.    if not  mscomm1.PortOpen   then
  3249.       begin
  3250.          showmessage('串口没有打开!');
  3251.          exit;
  3252.       end;
  3253.   if (edit2.Text='')or(edit5.Text='')or(edit8.Text='')or(edit11.Text='')or(edit14.Text='')or(edit17.Text='') then
  3254.     begin
  3255.         showmessage('请先计算设定值');
  3256.         exit;
  3257.     end
  3258.     else
  3259.       begin
  3260.      ////////////////////////////////////////
  3261.      //hao add
  3262.     if not TsInputVal(edit2.Text) then
  3263.     begin
  3264.      edit2.SetFocus;
  3265.      exit
  3266.     end;
  3267.       if not TsInputVal(edit5.Text) then
  3268.     begin
  3269.      edit5.SetFocus;
  3270.      exit
  3271.     end;
  3272.       if not TsInputVal(edit8.Text) then
  3273.     begin
  3274.      edit8.SetFocus;
  3275.      exit
  3276.     end;
  3277.       if not TsInputVal(edit11.Text) then
  3278.     begin
  3279.      edit11.SetFocus;
  3280.      exit
  3281.     end;
  3282.       if not TsInputVal(edit14.Text) then
  3283.     begin
  3284.      edit14.SetFocus;
  3285.      exit
  3286.     end;
  3287.       if not TsInputVal(edit17.Text) then
  3288.     begin
  3289.      edit17.SetFocus;
  3290.      exit
  3291.     end;
  3292.   //hao add end
  3293.       setlength(arr,9);
  3294.       if tag=0 then begin
  3295.          f:=strtofloat(edit2.text);
  3296.            success:=$00;
  3297.          end;
  3298.       if tag=1 then begin
  3299.          f:=strtofloat(edit5.text);
  3300.            success:=$01;
  3301.          end;
  3302.          if tag=2 then begin
  3303.          f:=strtofloat(edit8.text);
  3304.            success:=$02;
  3305.          end;
  3306.          if tag=3 then begin
  3307.          f:=strtofloat(edit11.text);
  3308.            success:=$03;
  3309.          end;
  3310.          if tag=4 then begin
  3311.          f:=strtofloat(edit14.text);
  3312.            success:=$04;
  3313.          end;
  3314.          if tag=5 then begin
  3315.          f:=strtofloat(edit17.text);
  3316.            success:=$05;
  3317.          end;
  3318.             arr[0]:=$7e;   //soi
  3319.            arr[1]:=$10;   //ver
  3320.             arr[2]:= $04;    //length
  3321.             arr[3]:=$a1;     //cid
  3322.          
  3323.            arr[4]:=success;
  3324.            p:=floattostr(f*1000);
  3325.            v:=strtoint(p);    //datainfo
  3326.            arr[5]:=v div 256;
  3327.             arr[6]:= v mod 256   ;
  3328.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  3329.             arr[7]:=xornum;
  3330.             arr[8]:=$0d;
  3331.   // send data
  3332.               len:=length(arr);
  3333.            i:=0;
  3334.             count:=0;
  3335.             tmpvar:=vararraycreate([0,0],varbyte);
  3336.              while(count<=len-1)do begin
  3337.                         tmpvar[count]:=arr[i];
  3338.                         inc(count);
  3339.                         inc(i);
  3340.                         vararrayredim(tmpvar,count);
  3341.                     end;
  3342.       MSComm1.Output:=tmpvar;
  3343.       timer15.Enabled:=true;
  3344.  end;
  3345.     ///////////////////////////////////////
  3346.  end;
  3347. procedure TForm1.Timer15Timer(Sender: TObject);
  3348. var
  3349. i,n,m,chksum:integer;
  3350. arr:array of byte;
  3351. tmpvar:variant;
  3352. begin
  3353.      arr:=nil;
  3354.      chksum:=$00;
  3355.     timesum:=timesum+integer(timer15.Interval)+10;
  3356.      if timesum<900 then
  3357.       begin
  3358.       //application.ProcessMessages;
  3359.         if mscomm1.InBufferCount>0 then begin
  3360.         timer15.Enabled:=false;
  3361.         timesum:=100;
  3362.           n:=mscomm1.InBufferCount;
  3363.           setlength(arr,n);
  3364.           tmpvar:=mscomm1.input;
  3365.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  3366.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  3367.         begin
  3368.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  3369.            if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
  3370.                if arr[n-3]=$0cc  then begin
  3371.                  {if tag>6 then begin
  3372.                    tag:=0;
  3373.                    showmessage('参数设定成功!');
  3374.                    end  else begin }
  3375.                      tag:=tag+1;
  3376.                      if tag>5 then begin
  3377.                    tag:=0;
  3378.                    showmessage('参数设定成功!');
  3379.                     timer15.Enabled:=false;
  3380.                    end  else begin
  3381.                      //timer15.Enabled:=false;
  3382.                 button19.Click;
  3383.                end;
  3384.                 end
  3385.                 else if arr[n-3]=$66 then begin
  3386.                  timer15.Enabled:=false;
  3387.                  showmessage('设置失败!');
  3388.                     //p:=p+1;
  3389.                     end ;
  3390.              end else
  3391.              begin
  3392.            showmessage('帧校验错误!'); //帧校验错误
  3393.             timer15.Enabled:=false;
  3394.              //p:=p+1;
  3395.               end;
  3396.        end else begin
  3397.       showmessage('响应数据头错误!');
  3398.        timer15.Enabled:=false;
  3399.       //P:=p+1;
  3400.            end;
  3401.     end else begin
  3402.         sleep(10);
  3403.       timer15.Enabled:=true;
  3404.              end;
  3405.              end else begin
  3406.              timesum:=100;
  3407.               timer15.Enabled:=false;
  3408.             // P:=p+1;
  3409.            // button19.Click;
  3410.             // showmessage('通道0参数设定时响应超时!');
  3411.             showmessage('参数设定失败!,请重试!');
  3412.    end;
  3413.       {if tag>6 then begin
  3414.                    tag:=0;
  3415.                    /showmessage('参数设定成功!');
  3416.                    end  ;  }
  3417. end;
  3418. procedure TForm1.Button20Click(Sender: TObject);
  3419. var
  3420.     //f,
  3421.     len,i,count:integer;
  3422.    tmpvar:variant;
  3423.    xornum:byte;
  3424.    arr:array of byte;
  3425. begin
  3426.     arr:=nil;
  3427.     if not  mscomm1.PortOpen   then
  3428.     begin
  3429.          showmessage('串口没有打开!');
  3430.     end else begin
  3431.      ////////////////////////////////////////
  3432.       setlength(arr,7);
  3433.       if tagc=0 then begin
  3434.         // f:=strtoint(edit2.text);
  3435.            success:=$00;
  3436.          end;
  3437.       if tagc=1 then begin
  3438.          //f:=strtoint(edit5.text);
  3439.            success:=$01;
  3440.          end;
  3441.          if tagc=2 then begin
  3442.         // f:=strtoint(edit8.text);
  3443.            success:=$02;
  3444.          end;
  3445.          if tagc=3 then begin
  3446.         // f:=strtoint(edit11.text);
  3447.            success:=$03;
  3448.          end;
  3449.          if tagc=4 then begin
  3450.         // f:=strtoint(edit14.text);
  3451.            success:=$04;
  3452.          end;
  3453.          if tagc=5 then begin
  3454.         // f:=strtoint(edit17.text);
  3455.            success:=$05;
  3456.          end;
  3457.             arr[0]:=$7e;   //soi
  3458.            arr[1]:=$10;   //ver
  3459.             arr[2]:= $02;    //length
  3460.             arr[3]:=$a2;     //cid
  3461.          
  3462.            arr[4]:=success;      //datainfo
  3463.           // arr[5]:=f div 256;
  3464.            // arr[6]:= f mod 256   ;
  3465.             xornum:= arr[2] xor arr[3] xor arr[4];// xor arr[5]xor arr[6];
  3466.             arr[5]:=xornum;
  3467.             arr[6]:=$0d;
  3468.   // send data
  3469.               len:=length(arr);
  3470.            i:=0;
  3471.             count:=0;
  3472.             tmpvar:=vararraycreate([0,0],varbyte);
  3473.              while(count<=len-1)do begin
  3474.                         tmpvar[count]:=arr[i];
  3475.                         inc(count);
  3476.                         inc(i);
  3477.                         vararrayredim(tmpvar,count);
  3478.                     end;
  3479.       MSComm1.Output:=tmpvar;
  3480.       timer16.Enabled:=true;
  3481.  end;
  3482.     ///////////////////////////////////////
  3483.     //end else begin
  3484.         //showmessage('请先计算设定值!');
  3485.     //end;
  3486.  end;
  3487. procedure TForm1.Timer16Timer(Sender: TObject);
  3488. var
  3489. i,n,m,chksum:integer;  //,timesum
  3490. arr:array of byte;
  3491. tmpvar:variant;
  3492. a:real;
  3493. begin
  3494.      arr:=nil;
  3495.      chksum:=$00;
  3496.     timesum:=timesum+integer(timer16.Interval)+10;
  3497.      if timesum<900 then
  3498.       begin
  3499.         if mscomm1.InBufferCount>0 then begin
  3500.         timer16.Enabled:=false;
  3501.         timesum:=100;
  3502.           n:=mscomm1.InBufferCount;
  3503.           setlength(arr,n);
  3504.           tmpvar:=mscomm1.input;
  3505.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  3506.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  3507.         begin
  3508.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  3509.            if (arr[n-2]=chksum)and(arr[3]=$a2) then begin
  3510.                //edit4.Text:=inttostr(arr[4]*256+arr[5]);
  3511.                //if (arr[n-3]=$0cc)or(arr[n-3]=$66)  then begin
  3512.                 //showmessage('设置成功!') ;
  3513.                 if arr[4]>127 then begin
  3514.                   a:=-((arr[4]-128)*256+arr[5])/1000.0;
  3515.                        end else begin
  3516.                        a:=(arr[4]*256+arr[5])/1000.0;
  3517.                        end;
  3518.                 case tagc of
  3519.                   $00:edit2.Text:=formatfloat('0.000',a);
  3520.                    $01:edit5.Text:=formatfloat('0.000',a);
  3521.                     $02:edit8.Text:=formatfloat('0.000',a);
  3522.                      $03:edit11.Text:=formatfloat('0.000',a);
  3523.                       $04:edit14.Text:=formatfloat('0.000',a);
  3524.                        $05:edit17.Text:=formatfloat('0.000',a);
  3525.                   end;
  3526.                // pc:=0 ;
  3527.                //tagc:=tagc+1;
  3528.                if tagc>5 then begin
  3529.                tagc:=0;
  3530.                showmessage('参数回读完毕!');
  3531.                if edit20.Text= edit2.Text then
  3532.             checkbox1.Checked:=true  else  checkbox1.Checked:=false;
  3533.          if edit21.Text= edit5.Text then
  3534.             checkbox2.Checked:=true  else  checkbox2.Checked:=false;
  3535.             if edit22.Text= edit8.Text then
  3536.             checkbox3.Checked:=true  else  checkbox3.Checked:=false;
  3537.             if edit23.Text= edit11.Text then
  3538.             checkbox4.Checked:=true  else  checkbox4.Checked:=false;
  3539.             if edit24.Text= edit14.Text then
  3540.             checkbox5.Checked:=true  else  checkbox5.Checked:=false;
  3541.             if edit25.Text= edit17.Text then
  3542.             checkbox6.Checked:=true  else  checkbox6.Checked:=false;
  3543.          
  3544.                end else begin
  3545.                 tagc:=tagc+1;
  3546.                 button20.Click;
  3547.                 end ;
  3548.                     end;
  3549.              end else
  3550.              begin
  3551.              end;
  3552.     end else begin
  3553.         sleep(10);
  3554.       timer16.Enabled:=true;
  3555.              end;
  3556.              end else begin
  3557.              timesum:=100;
  3558.              timer16.Enabled:=false;
  3559.              showmessage('参数回读失败,请重试!');
  3560.                end;
  3561. end;
  3562. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  3563. var
  3564. closeconfirm:integer;
  3565. begin
  3566.  closeconfirm:=messagedlg('您确定要退出吗?',mtconfirmation,[mbyes,mbno],0);
  3567.    canclose:=(closeconfirm=mryes);
  3568.  end;
  3569.  procedure TForm1.ComboBox1Change(Sender: TObject);
  3570. begin
  3571.    if mscomm1.PortOpen then
  3572.     begin
  3573.            //mscomm1.PortOpen:=false;
  3574.            //shape1.Brush.Color:=clred;
  3575.            //button22.Caption:='连接';
  3576.            //if tstr=combobox1.Items.Text then
  3577.        if tindexnum<>combobox1.ItemIndex then   begin
  3578.             mscomm1.PortOpen:=false;
  3579.            shape1.Brush.Color:=clred;
  3580.            button22.Caption:='连接';
  3581.            statusbar1.Panels[0].Text:='串口com'+inttostr(tindexnum+1)+'已断开';
  3582.            combobox2.ItemIndex:=0;
  3583.            label8.Visible:=false;
  3584. label9.Visible:=false;
  3585. label10.Visible:=false;
  3586. label11.Visible:=false;
  3587. label12.Visible:=false;
  3588. label13.Visible:=false;
  3589. label14.Visible:=false;
  3590. label15.Visible:=false;
  3591. label16.Visible:=false;
  3592. edit29.Visible:=false;
  3593. edit30.Visible:=false;
  3594. edit27.Visible:=false;
  3595. edit28.Visible:=false;
  3596.           // else  statusbar1.Panels[0].Text:='串口com'+inttostr(combobox1.ItemIndex+1)+'已断开';
  3597.    end ;
  3598.      end   else  statusbar1.Panels[0].Text:='';
  3599. end;
  3600. procedure TForm1.ComboBox2Change(Sender: TObject);
  3601. begin
  3602. if combobox2.ItemIndex=1 then begin
  3603.  label8.Visible:=true;
  3604.  label9.Visible:=true;
  3605.  label10.Visible:=true;
  3606. label11.Visible:=true;
  3607.  label12.Visible:=false;
  3608.  label13.Visible:=false;
  3609.  label14.Visible:=false;
  3610.  label15.Visible:=false;
  3611.  label16.Visible:=false;
  3612.  edit27.Visible:=true;
  3613.  edit27.Clear;
  3614.  edit28.Visible:=true;
  3615.  edit28.Clear;
  3616.  edit29.Visible:=false;
  3617.  edit29.Clear;
  3618.  edit30.Clear;
  3619.  edit30.Visible:=false;
  3620.  edit31.Clear;
  3621.   edit31.Visible:=false;
  3622.  end;
  3623. if combobox2.ItemIndex=2 then begin
  3624.    label14.Visible:=true;
  3625.    label15.Visible:=true;
  3626.      edit30.Visible:=true;
  3627.      label8.Visible:=false;
  3628.  label9.Visible:=false;
  3629.  label10.Visible:=false;
  3630. label11.Visible:=false;
  3631.  label12.Visible:=false;
  3632.  label13.Visible:=false;
  3633.  edit27.Clear;
  3634.  edit28.Clear;
  3635.  edit29.Clear;
  3636.  edit30.Clear;
  3637.   edit31.Clear;
  3638.    edit27.Visible:=false;
  3639.  edit28.Visible:=false;
  3640.  edit29.Visible:=false;
  3641.   edit31.Visible:=false;
  3642.   label16.Visible:=false;
  3643.      end;
  3644.      if combobox2.ItemIndex=3 then begin
  3645.          edit31.Visible:=true;
  3646.                   label16.Visible:=true;
  3647.                 label8.Visible:=true;
  3648.  label9.Visible:=true;
  3649.  label10.Visible:=true;
  3650.  label11.Visible:=true;
  3651.  label12.Visible:=false;
  3652.  label13.Visible:=false;
  3653.   edit27.Clear;
  3654.  edit28.Clear;
  3655.  edit29.Clear;
  3656.  edit30.Clear;
  3657.   edit31.Clear;
  3658.  edit27.Visible:=true;
  3659.  edit28.Visible:=true;
  3660.   label14.Visible:=true;
  3661.    label15.Visible:=true;
  3662.      edit30.Visible:=true;
  3663.          end;
  3664.          if combobox2.ItemIndex=0 then begin
  3665.          label8.Visible:=false;
  3666.  label9.Visible:=false;
  3667.  label10.Visible:=false;
  3668.  label11.Visible:=false;
  3669.  label12.Visible:=false;
  3670.  label13.Visible:=false;
  3671.          label14.Visible:=false;
  3672.    label15.Visible:=false;
  3673.    label16.Visible:=false;
  3674.     edit27.Clear;
  3675.  edit28.Clear;
  3676.  edit29.Clear;
  3677.  edit30.Clear;
  3678.   edit31.Clear;
  3679.    edit27.Visible:=false;
  3680.  edit28.Visible:=false;
  3681.  edit29.Visible:=false;
  3682.   edit30.Visible:=false;
  3683.   edit31.Visible:=false;
  3684.    end;
  3685. end;
  3686. procedure TForm1.Button23Click(Sender: TObject);
  3687. var
  3688.  len,i,count:integer;
  3689.    //tmpstr:string;
  3690.    tmpvar:variant;
  3691.    xornum:byte;
  3692.    arr:array of byte;
  3693. begin
  3694. arr:=nil;
  3695.  if not mscomm1.PortOpen then begin
  3696.     showmessage('串口没有打开!');
  3697.      end else begin
  3698.      setlength(arr,7);
  3699.     // f:=strtoint(edit2.text);
  3700.             arr[0]:=$7e;   //soi
  3701.            arr[1]:=$10;   //ver
  3702.             arr[2]:= $07;    //length
  3703.             arr[3]:=$a3;     //cid
  3704.            arr[4]:=$80;      //datainfo
  3705.            arr[5]:=$00;
  3706.           arr[6]:=230 ;//div 255
  3707.            arr[7]:=201 ; //f mod 255   ;
  3708.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5] xor arr[6] xor arr[7];// xor arr[5]xor arr[6];
  3709.             arr[8]:=xornum;
  3710.             arr[9]:=$0d;
  3711.   // send data
  3712.               len:=length(arr);
  3713.            i:=0;
  3714.             count:=0;
  3715.             tmpvar:=vararraycreate([0,0],varbyte);
  3716.             //tmpvar[count]:=arr[i];
  3717.             //inc(count);
  3718.             //inc(i);
  3719.              while(count<=len-1)do begin
  3720.                         tmpvar[count]:=arr[i];
  3721.                         inc(count);
  3722.                         inc(i);
  3723.                         vararrayredim(tmpvar,count);
  3724.                     end;
  3725.       MSComm1.Output:=tmpvar;
  3726.       timer7.Enabled:=true;
  3727.  end;
  3728.        {if mscomm1.InBufferCount>0 then begin
  3729.        timer7.Enabled:=false;
  3730.           n:=mscomm1.InBufferCount;
  3731.           setlength(arr,n);
  3732.           tmpvar:=mscomm1.input;
  3733.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  3734.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  3735.         begin
  3736.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  3737.            if (arr[n-2]=chksum)and(arr[3]=$a3) then begin
  3738.                if arr[5]<127 then begin
  3739.                            xy := (arr[5]*256+arr[6])/100.0 ;
  3740.                edit4.Text:=floattostr(xy);//inttostr(arr[5]*256+arr[6]);
  3741.                showmessage('回读成功!');
  3742.                //tag:=true;
  3743.                  end else begin
  3744.                          xy := -((arr[5]-128)*256+arr[6])/100.0 ;
  3745.                  edit4.Text:=floattostr(xy);//inttostr(-((arr[5]-128)*256+arr[6]));
  3746.                   showmessage('回读成功!');
  3747.                //tag:=true;
  3748.                  end;
  3749.              end else
  3750.              showmessage('帧校验错误!'); //帧校验错误
  3751.        end else
  3752.       showmessage('响应数据错误!');
  3753.     end else begin
  3754.         sleep(10);
  3755.       timer7.Enabled:=true;
  3756.              end;
  3757.              end else begin
  3758.              showmessage('响应超时!');
  3759.              timesum:=100;
  3760.              end; }
  3761.      //while mscomm1.InBufferCount
  3762.     end;
  3763. end.