⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filedefine.~pas

📁 Delphi编写的ModBus协议上位机软件
💻 ~PAS
📖 第 1 页 / 共 4 页
字号:
        k := pos(temp, temstr);
        if k>0 then
        begin
          j := i;
          break;
          end;
    end;

    if ((i<>j)or(k=0)) then
    begin
      fileerr(NOTFIND + temp);
      exit;
      end;

    i := i + 1;
    temstr := Lines.Strings[i];
    k := pos('---', temstr);
    j := 0;

    while k=0 do
    begin
      temp := '[功能码]';
      if pos(temp, temstr)=0 then
      begin
        i := i + 1;
        temstr := Lines.Strings[i];
        k := pos('---', temstr);
        continue;
        end;

      temp1 := getdata(temp, i, tempmemo);
      temp1 := inttohex(strtointdef(temp1, 0), 2);
      if strtointdef(temp1, 300)>25 then
      begin
        fileerr(temp + '值大于[功能码]');
        exit;
        end;

      temp := '[起始地址]';
      if pos(temp, temstr)=0 then
      begin
        i := i + 1;
        temstr := Lines.Strings[i];
        k := pos('---', temstr);
        continue;
        end;

      temp := getdata(temp, i, tempmemo);
      temp1 := temp1 + inttohex(strtointdef(temp, 1), 4);

      temp := '[读取点数]';
      if pos(temp,temstr)=0 then
      begin
        i := i + 1;
        temstr := Lines.Strings[i];
        k := pos('---', temstr);
        continue;
      end;

      temp := getdata(temp, i, tempmemo);
      temp1 := temp1 + inttohex(strtointdef(temp, 1), 4);

      econfile.comm.sendbuffer1.buffer[j] := temp1;

      i := i + 1;
      temstr := Lines.Strings[i];
      k := pos('---', temstr);

      j := j + 1;
      if j>=15 then
      begin
//        fileerr(inttostr(j)+'超过[事件类型数]的值');
        exit;
      end;

    end;
  end;
end;

procedure getdatafromfile(var tempmemo: tmemo; filename: string; econfile: Teconfile);
var
  tempstr, temp: string;
begin
  tempmemo.Lines.LoadFromFile(filename);
  with tempmemo do
  begin
    temp := '[文件名]';
    tempstr := getdata(temp, 0, tempmemo);
    if tempstr='xx' then
    begin
      fileerr(NOTFIND + temp);
      exit;
      end;
      econfile.changfilename(tempstr);

      temp := '[输入开关量数]';
      tempstr := getdata(temp, 0, tempmemo);
      if tempstr='xx' then
      begin
        //fileerr(NOTFIND + temp);
        //exit;
        econfile.changinputstatetotal(0);
        end
      else
      begin
        if strtointdef(tempstr, 300)>INPUTSTATEMAX then
        begin
          fileerr(temp + TOOBIG);
          exit;
        end;
        econfile.changinputstatetotal(strtointdef(tempstr, 0));
      end;

      temp := '[输出开关量数]';
      tempstr := getdata(temp, 0, tempmemo);
      if tempstr='xx' then
      begin
        //fileerr(NOTFIND + temp);
        //exit;
        econfile.changcoilstatetotal(0);
      end
      else
      begin
        if strtointdef(tempstr, 300)>COILMAX then
        begin
          fileerr(temp + TOOBIG);
          exit;
        end;
        econfile.changcoilstatetotal(strtointdef(tempstr, 0));
      end;

      temp := '[保持寄存器数]';
      tempstr:=getdata(temp, 0, tempmemo);
      if tempstr='xx' then
      begin
        //fileerr(NOTFIND + temp);
        //exit;
        econfile.changholdregistertotal(0);
      end
      else
      begin
        if strtointdef(tempstr,300)>HOLDREGISTERMAX then
        begin
          fileerr(temp + TOOBIG);
          exit;
        end;
        econfile.changholdregistertotal(strtointdef(tempstr,0));
      end;

      temp := '[输入寄存器数]';
      tempstr := getdata(temp, 0, tempmemo);
      if tempstr='xx' then
      begin
        //fileerr(NOTFIND + temp);
        //exit;
        econfile.changinputregistertotal(0);
      end
      else
      begin
        if strtointdef(tempstr,300)>INPUTREGISTERMAX then
        begin
          fileerr(temp + TOOBIG);
          exit;
        end;
        econfile.changinputregistertotal(strtointdef(tempstr, 0));
      end;

      temp := '[保护类型数]';
      tempstr := getdata(temp, 0, tempmemo);
      if tempstr='xx' then
      begin
        //fileerr(NOTFIND + temp);
        //exit;
        econfile.changsetprotecttotal(0);
      end
      else
      begin
        if strtointdef(tempstr, 300)>SETPROTECTMAX then
        begin
          fileerr(temp + TOOBIG);
          exit;
        end;
        econfile.changsetprotecttotal(strtointdef(tempstr, 0));
      end;

      temp := '[电度类型数]';
      tempstr := getdata(temp, 0, tempmemo);
      if tempstr='xx' then
      begin
        //fileerr(NOTFIND + temp);
        //exit;
        econfile.changsetpowertotal(0);
      end
      else
      begin
        if strtointdef(tempstr, 300)>SETPOWERMAX then
        begin
          fileerr(temp + TOOBIG);
          exit;
        end;
        econfile.changsetpowertotal(strtointdef(tempstr, 0));
      end;

      temp := '[事件类型数]';
      tempstr := getdata(temp, 0, tempmemo);
      if tempstr='xx' then
      begin
        //fileerr(NOTFIND + temp);
        //exit;
        econfile.changeventtypetotal(0);
      end
      else
      begin
        if strtointdef(tempstr, 300)>EVENTTYPEMAX then
        begin
          fileerr(temp + TOOBIG);
          exit;
        end;
        econfile.changeventtypetotal(strtointdef(tempstr, 0));
      end;

      temp := '[生成相量图]';          //2004.5.26
      tempstr := getdata(temp, 0, tempmemo);
      if tempstr='xx' then
      begin
        //fileerr(NOTFIND+temp);
        //exit;
      end;
      econfile.changxiangliangtotal(strtointdef(tempstr, 0));

      temp := '[谐波显示]';          //2004.5.26
      tempstr := getdata(temp, 0, tempmemo);
      if tempstr='xx' then
      begin
//        fileerr(NOTFIND+temp);
//        exit;
      end;
      econfile.changxiebototal(strtointdef(tempstr, 0));

      temp := '[输入寄存器与保持寄存器关联数]';
      tempstr := getdata(temp, 0, tempmemo);
      if tempstr='xx' then
      begin
        //fileerr(NOTFIND + temp);
        //exit;
        econfile.changsetpartotal(0);
      end
      else
      begin
        if strtointdef(tempstr,300)>SETPARMAX then
        begin
          fileerr(temp + TOOBIG);
          exit;
        end;
        econfile.changsetpartotal(strtointdef(tempstr, 0));
      end;

      if econfile.coilstatetotal>0 then getcoilstatedata(tempmemo, econfile);
      if econfile.inputstatetotal>0 then getinputstatedata(tempmemo, econfile);
      if econfile.holdregistertotal>0 then getholdregisterdata(tempmemo, econfile);
      if econfile.inputregistertotal>0 then getinputregisterdata(tempmemo, econfile);
      if econfile.setpartotal>0 then getsetpardata(tempmemo, econfile);
      if econfile.setprotecttotal>0 then getsetprotectdata(tempmemo, econfile);
      if econfile.setpowertotal>0 then getsetpowerdata(tempmemo, econfile);
      if econfile.eventtypetotal>0 then geteventtypedata(tempmemo, econfile);
      if econfile.setxiangliangtotal>0 then getxiangliangdata(tempmemo, econfile);
      if econfile.setxiebototal>0 then getxiebodata(tempmemo, econfile);
      getcomdata(tempmemo, econfile);
  end;
end;

procedure displaycoilstate(const econfile: Teconfile; tempgrid: Tstringgrid);
var
  i: integer;
begin
  tempgrid.Rowcount := econfile.coilstatetotal + 1;
  tempgrid.Cells[0,0] := '序号';
  tempgrid.Cells[1,0] := '名称';
  tempgrid.Cells[2,0] := '值 ';

  for i:=1 to econfile.coilstatetotal do
  begin
    tempgrid.Cells[0, i] := inttostr(i);
    tempgrid.Cells[1, i] := econfile.coilstatearray[i].name;
    if (econfile.coilstatearray[i].value=true) then  tempgrid.Cells[2, i] := '1'
    else tempgrid.Cells[2, i] := '0';
    //tmpgrid.Cells[2, i] := inttostr(ord(econfile.coilstatearray[i].value));
  end;
end;

procedure displayinputstate(const econfile: Teconfile; tempgrid: Tstringgrid);
var
  i: integer;
begin
  tempgrid.Rowcount := econfile.inputstatetotal + 1;
  tempgrid.Cells[0, 0] := '序号';
  tempgrid.Cells[1, 0] := '名称';
  tempgrid.Cells[2, 0] := '值 ';

  for i:=1 to econfile.inputstatetotal do
  begin
    tempgrid.Cells[0, i] := inttostr(i);
    tempgrid.Cells[1, i] := econfile.inputstatearray[i].name;
    if (econfile.inputstatearray[i].value=true) then  tempgrid.Cells[2, i] := '1'
    else tempgrid.Cells[2, i] := '0';
    //tempgrid.Cells[2, i] := inttostr(ord(econfile.inputstatearray[i].value));
  end;
end;

procedure displayholdregister(const econfile: Teconfile; tempgrid: Tstringgrid);
var
  i: integer;
begin
  tempgrid.Rowcount := econfile.holdregistertotal + 1;
  tempgrid.Cells[0, 0] := '地址';
  tempgrid.Cells[1, 0] := '名称';
  tempgrid.Cells[2, 0] := '值 ';

  for i:=1 to econfile.holdregistertotal do
  begin
    tempgrid.Cells[0, i] := inttostr(i);
    tempgrid.Cells[1, i] := econfile.holdregisterarray[i].name;
    tempgrid.Cells[2, i] := econfile.holdregisterarray[i].value;
  end;

end;

procedure displayinputregister(const econfile: Teconfile; tempgrid: Tstringgrid);
var
  i: integer;
begin
  tempgrid.Rowcount := econfile.inputregistertotal + 1;
  tempgrid.Cells[0, 0] := '地址';
  tempgrid.Cells[1, 0] := '名称';
  tempgrid.Cells[2, 0] := '值 ';

  for i:=1 to econfile.inputregistertotal do
  begin
    tempgrid.Cells[0, i] := inttostr(i);
    tempgrid.Cells[1, i] := econfile.inputregisterarray[i].name;
    tempgrid.Cells[2, i] := econfile.inputregisterarray[i].value;
  end;
end;

procedure displayprotect(const econfile: Teconfile; tempgrid: Tstringgrid);
var
  i, j: integer;
begin
  tempgrid.Rowcount := econfile.setprotecttotal + 1;
  tempgrid.Cells[0, 0] := '序号';
  tempgrid.Cells[1, 0] := '保护类型';
  tempgrid.Cells[2, 0] := '投退名称';
  tempgrid.Cells[3, 0] := '投退值';
  tempgrid.Cells[4, 0] := '保护定值名称';
  tempgrid.Cells[5, 0] := '保护定值';
  tempgrid.Cells[6, 0] := '时间定值名称';
  tempgrid.Cells[7, 0] := '时间定值';
  tempgrid.Cells[8, 0] := '动作继电器';


  for i:=1 to econfile.setprotecttotal do
  begin
    tempgrid.Cells[0, i] := inttostr(i);
    tempgrid.Cells[1, i] := econfile.setprotectarray[i].name;

    j := strtointdef(econfile.setprotectarray[i].address1, 0);
    tempgrid.Cells[2, i] := econfile.holdregisterarray[j].name;

    j := strtointdef(econfile.holdregisterarray[j].value, 0);
    tempgrid.Cells[3, i] := inttostr(ord(j >= $8000));
    tempgrid.Cells[8, i] := inttostr(j mod $8000 );

    j := strtointdef(econfile.setprotectarray[i].address2, 0);
    tempgrid.Cells[4, i] := econfile.holdregisterarray[j].name;
    tempgrid.Cells[5, i] := econfile.holdregisterarray[j].value;

    j := strtointdef(econfile.setprotectarray[i].address3, 0);
    tempgrid.Cells[6, i] := econfile.holdregisterarray[j].name;
    tempgrid.Cells[7, i] := econfile.holdregisterarray[j].value;
  end;
end;

procedure displaypower(const econfile:Teconfile; tempgrid: Tstringgrid);
var
  i, j, k: longword;
begin
  tempgrid.Rowcount := econfile.setpowertotal + 1;
  tempgrid.Cells[0, 0] :='序号';
  tempgrid.Cells[1, 0] :='名称';
  tempgrid.Cells[2, 0] :='值 ';

  for i:=1 to econfile.setpowertotal do
  begin
    tempgrid.Cells[0, i] := inttostr(i);
    tempgrid.Cells[1, i] := econfile.setpowerarray[i].name;
    j := strtoint64def(econfile.setpowerarray[i].address1,0);
    j := strtoint64def(econfile.holdregisterarray[j].value,0);
    k := strtoint64def(econfile.setpowerarray[i].address2,0);
    k := strtoint64def(econfile.holdregisterarray[k].value,0) * 65536;
    tempgrid.Cells[2, i] := inttostr(k + j);
  end;
end;

procedure displayxiangliang(const econfile: Teconfile; tempgrid: Tstringgrid);
var
  i, j: integer;
begin
  tempgrid.Rowcount := 13;
  tempgrid.Cells[0, 0] := '序号';
  tempgrid.Cells[1, 0] := '地址';
  tempgrid.Cells[2, 0] := '名称';

  for i:=1 to 12 do
  begin
    j := strtointdef(econfile.xiangliangarray[i].address1, 0);
    econfile.xiangliangarray[i].address2
                           := econfile.inputregisterarray[j].value;
    tempgrid.Cells[0, i] := inttostr(i);
    tempgrid.Cells[1, i] := econfile.xiangliangarray[i].name;
    tempgrid.Cells[2, i] := econfile.xiangliangarray[i].address2;
 //address1为相量定义对应于输入寄存器地址,address2为相量定义对应输入寄存器的值
  end;
end;

procedure displayxiebo(const econfile: Teconfile; tempgrid: Tstringgrid);
var
  i: integer;
  j, l, m: cardinal;
  t: real;
begin
  tempgrid.Rowcount := 43;
  tempgrid.Cells[0, 0] := '序号';
  tempgrid.Cells[1, 0] := '地址';
  tempgrid.Cells[2, 0] := '名称';

  for i:=0 to 41 do
  begin
    j := i mod 6;

    l := strtointdef(econfile.xieboarray[i+1].address1, 0); //
    m := l+1;

    l := abs(strtointdef(econfile.inputregisterarray[l].value, 0)); // 取实部
    m := abs(strtointdef(econfile.inputregisterarray[m].value, 0)); // 取虚部

    t := sqrt(l*l + m*m);

    l := strtointdef(econfile.setpararray[j+1].address2, 1);
    m := strtointdef(econfile.holdregisterarray[l].value, 0);

    if j<3 then l :=  StrToInt64Def(xiev, 1)
        else l :=  StrToInt64Def(xiei, 1);
        
    m := trunc(t * m / l);

    tempgrid.Cells[2, i] := inttostr(m);
    tempgrid.Cells[0, i] := inttostr(i+1);
    tempgrid.Cells[1, i] := econfile.xieboarray[i+1].name;
  end;
end;

procedure readholdregister(econfile: Teconfile);
var
  i, j, k: integer;
begin
  i := econfile.holdregistertotal div 8;
  j := econfile.holdregistertotal mod 8;
  for k:=0 to i do
       addsendbuffer2(econfile, '03' + inttohex(k*8, 4) +  '0008');
  if (j > 0) then
       addsendbuffer2(econfile, '03' + inttohex(k*8, 4) + inttohex(j, 4));
end;

procedure settime(econfile: Teconfile);
var t: ttime;
begin
  t := time;
  addsendbuffer2(econfile, '06' + inttohex(0, 4) + IntTohex((Trunc(t*MsecsPerDay) mod 65536),4) );
  addsendbuffer2(econfile, '06' + inttohex(1, 4) + IntTohex((Trunc(t*MsecsPerDay) div 65536),4) );
end;

Procedure datainit;
begin
  fifocount := 0;

  receiveString := ''; //ASCLL 方式接收字符串

  sendflag := false;  //特殊帧标志

  timeoutcount := 0;   //超时计数,大于5,超时发下一帧
  revcount := 0;       //接收字节计数器

  beginaddress := 0;

  cyclesend := 0;
end;

procedure readfifo(econfile: Teconfile);
begin
  addsendbuffer2(econfile, '18'+ '0000');
end;

procedure addsendbuffer2(econfile: teconfile; temp: string);
var
  i: integer;
begin
  for i:=0 to 49 do
  begin
    if econfile.comm.sendbuffer2.buffer[i]='' then
    begin
      econfile.comm.sendbuffer2.buffer[i] := temp;
      exit;
    end;
  end;
end;

end.


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -