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

📄 tempreader.pas

📁 温度恒温控制,与PLC,工控板通讯,实现炉字过程控制.
💻 PAS
📖 第 1 页 / 共 2 页
字号:
         fedit.Font.Color:=clwhite;
       end
       else
       begin
          bwarn[tempseq*8+i-1]:=false;
         fedit.Font.Color:=$006C6C00;
         if (itemp<100) then
           fedit.color:=$00FFFFE8;
         if (itemp<200) and (itemp>=100) then
           fedit.color:=$00A2FFAB;
         if (itemp<300) and (itemp>=200) then
           fedit.color:=$0080FFFF;
         if (itemp<400) and (itemp>=300) then
           fedit.color:=$00FFA4FF;
         if (itemp<500) and (itemp>=400) then
           fedit.color:=$00977AFC;
         if (itemp<600) and (itemp>=500) then
           fedit.color:=$00547AFC;
         if (itemp<700) and (itemp>=600) then
           fedit.color:=clLime;
       end;
    end;
   end;
   3:
   begin
    for i:=1 to 6 do
    begin
      iheartport:=5;
      lpDioWriteBit.bit:=6-i;
      lpDioWriteBit.port:=iheartport;    //iheartport根据端口要变;
       if strtoint(stemp[i-1])>ipidtemp then
        rpidout:=PIDcalc(tempseq*8+i-2,stemp[i-1])/8000
      else
        rpidout:=ipower/100;
      if rpidout>1 then
      begin
        rpidout:=1;
        pidout[tempseq*8+i-2].state:=true;
      end
      else
        pidout[tempseq*8+i-2].state:=false;
      if (rpidout>0.001) and (rpidout<1)  then
      begin
        Ftime:=TTimer(frmglass.FindComponent('tmtemp'+inttostr(tempseq*8+i-2)));
        Ftime.Interval:=trunc(pid_t*rpidout*1000);
        Ftime.Enabled:=true;
        lpDioWriteBit.state:=1;
        DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //打开PCL-722输出数据,输出占空比时间;
      end
      else
      begin
        if  (rpidout>=1) then
        begin
          lpDioWriteBit.state:=1;
          DRV_DioWriteBit(DeviceHandle,lpDioWriteBit);
        end
        else
        begin
          lpDioWriteBit.state:=0;
          DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //关闭PCL-722输出数据;
        end;
      end;
       Fpanel:=Tpanel(frmglass.FindComponent('pntem'+inttostr(tempseq*8+i-2)));
       Fpanel.Caption:=inttostr(strtoint(stemp[i-1]));
       Fedit:=Tedit(frmglass.FindComponent('edtemp'+inttostr(tempseq*8+i-2)));
       fedit.Text:=inttostr(strtoint(stemp[i-1]));
//       if (strtoint(stemp[i-1])>pidout[tempseq*8+i-2].setpoint) then
       itemp:=strtoint(stemp[i-1]);
       if (itemp>iwarntemp) then
       begin
         bwarn[tempseq*8+i-2]:=true;
         fedit.color:=clred;
         fedit.Font.Color:=clwhite;
       end
       else
       begin
          bwarn[tempseq*8+i-2]:=false;
          fedit.Font.Color:=$006C6C00;
         if (itemp<100) then
           fedit.color:=$00FFFFE8;
         if (itemp<200) and (itemp>=100) then
           fedit.color:=$00A2FFAB;
         if (itemp<300) and (itemp>=200) then
           fedit.color:=$0080FFFF;
         if (itemp<400) and (itemp>=300) then
           fedit.color:=$00FFA4FF;
         if (itemp<500) and (itemp>=400) then
           fedit.color:=$00977AFC;
         if (itemp<600) and (itemp>=500) then
           fedit.color:=$00547AFC;
         if (itemp<700) and (itemp>=600) then
           fedit.color:=clLime;
       end;
    end;
   end;

   4:
   begin
    for i:=1 to 8 do
    begin
      iheartport:=4;
      lpDioWriteBit.bit:=7-i;
      if i=8 then
      begin
          iheartport:=3;
          lpDioWriteBit.bit:=6;
      end;
      lpDioWriteBit.port:=iheartport;    //iheartport根据端口要变;
       if strtoint(stemp[i-1])>ipidtemp then
        rpidout:=PIDcalc(tempseq*8+i-4,stemp[i-1])/8000
      else
        rpidout:=ipower/100;
      if rpidout>1 then
      begin
        rpidout:=1;
        pidout[tempseq*8+i-4].state:=true;
      end
      else
        pidout[tempseq*8+i-4].state:=false;
      if (rpidout>0.001) and (rpidout<1)  then
      begin
        Ftime:=TTimer(frmglass.FindComponent('tmtemp'+inttostr(tempseq*8+i-4)));
        Ftime.Interval:=trunc(pid_t*rpidout*1000);
        Ftime.Enabled:=true;
        lpDioWriteBit.state:=1;
        DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //打开PCL-722输出数据,输出占空比时间;
      end
      else
      begin
        if  (rpidout>=1) then
        begin
          lpDioWriteBit.state:=1;
          DRV_DioWriteBit(DeviceHandle,lpDioWriteBit);
        end
        else
        begin
          lpDioWriteBit.state:=0;
          DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //关闭PCL-722输出数据;
        end;
      end;
       Fpanel:=Tpanel(frmglass.FindComponent('pntem'+inttostr(tempseq*8+i-4)));
       Fpanel.Caption:=inttostr(strtoint(stemp[i-1]));
       Fedit:=Tedit(frmglass.FindComponent('edtemp'+inttostr(tempseq*8+i-4)));
       fedit.Text:=inttostr(strtoint(stemp[i-1]));
//       if (strtoint(stemp[i-1])>pidout[tempseq*8+i-4].setpoint) then
       itemp:=strtoint(stemp[i-1]);
       if (itemp>iwarntemp) then
       begin
         bwarn[tempseq*8+i-4]:=true;
         fedit.color:=clred;
         fedit.Font.Color:=clwhite;
       end
       else
       begin
         bwarn[tempseq*8+i-4]:=false;
         fedit.Font.Color:=$006C6C00;
         if (itemp<100) then
           fedit.color:=$00FFFFE8;
         if (itemp<200) and (itemp>=100) then
           fedit.color:=$00A2FFAB;
         if (itemp<300) and (itemp>=200) then
           fedit.color:=$0080FFFF;
         if (itemp<400) and (itemp>=300) then
           fedit.color:=$00FFA4FF;
         if (itemp<500) and (itemp>=400) then
           fedit.color:=$00977AFC;
         if (itemp<600) and (itemp>=500) then
           fedit.color:=$00547AFC;
         if (itemp<700) and (itemp>=600) then
           fedit.color:=clLime;
       end;
    end;
   end;
   5:
   begin
    for i:=1 to 7 do
    begin
      iheartport:=3;
      lpDioWriteBit.bit:=6-i;
      if i=7 then
      begin
        iheartport:=8;
        lpDioWriteBit.bit:=6;
      end;
      lpDioWriteBit.port:=iheartport;    //iheartport根据端口要变;
      if strtoint(stemp[i-1])>ipidtemp then
        rpidout:=PIDcalc(tempseq*8+i-4,stemp[i-1])/8000
      else
        rpidout:=ipower/100;
      if rpidout>1 then
      begin
        rpidout:=1;
        pidout[tempseq*8+i-4].state:=true;
      end
      else
        pidout[tempseq*8+i-4].state:=false;
      if (rpidout>0.001) and (rpidout<1)  then
      begin
        Ftime:=TTimer(frmglass.FindComponent('tmtemp'+inttostr(tempseq*8+i-4)));
        Ftime.Interval:=trunc(pid_t*rpidout*1000);
        Ftime.Enabled:=true;
        lpDioWriteBit.state:=1;
        DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //打开PCL-722输出数据,输出占空比时间;
      end
      else
      begin
        if  (rpidout>=1) then
        begin
          lpDioWriteBit.state:=1;
          DRV_DioWriteBit(DeviceHandle,lpDioWriteBit);
        end
        else
        begin
          lpDioWriteBit.state:=0;
          DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //关闭PCL-722输出数据;
        end;
      end;
       Fpanel:=Tpanel(frmglass.FindComponent('pntem'+inttostr(tempseq*8+i-4)));
       Fpanel.Caption:=inttostr(strtoint(stemp[i-1]));
       Fedit:=Tedit(frmglass.FindComponent('edtemp'+inttostr(tempseq*8+i-4)));
       fedit.Text:=inttostr(strtoint(stemp[i-1]));
//       if (strtoint(stemp[i-1])>pidout[tempseq*8+i-4].setpoint) then
       itemp:=strtoint(stemp[i-1]);
       if (itemp>iwarntemp) then
       begin
         bwarn[tempseq*8+i-4]:=true;
         fedit.color:=clred;
         fedit.Font.Color:=clwhite;
       end
       else
       begin
         bwarn[tempseq*8+i-4]:=false;
         fedit.Font.Color:=$006C6C00;
         if (itemp<100) then
           fedit.color:=$00FFFFE8;
         if (itemp<200) and (itemp>=100) then
           fedit.color:=$00A2FFAB;
         if (itemp<300) and (itemp>=200) then
           fedit.color:=$0080FFFF;
         if (itemp<400) and (itemp>=300) then
           fedit.color:=$00FFA4FF;
         if (itemp<500) and (itemp>=400) then
           fedit.color:=$00977AFC;
         if (itemp<600) and (itemp>=500) then
           fedit.color:=$00547AFC;
         if (itemp<700) and (itemp>=600) then
           fedit.color:=clLime;
       end;
    end;
   end;
  6:
   begin
    for i:=1 to 7 do
    begin
      iheartport:=8;
      lpDioWriteBit.bit:=6-i;
      if i=7 then
      begin
        iheartport:=7;
        lpDioWriteBit.bit:=6;
      end;
      lpDioWriteBit.port:=iheartport;    //iheartport根据端口要变;
      if strtoint(stemp[i-1])>ipidtemp then
       rpidout:=PIDcalc(tempseq*8+i-5,stemp[i-1])/8000
      else
        rpidout:=ipower/100;
      if rpidout>1 then
      begin
        rpidout:=1;
        pidout[tempseq*8+i-5].state:=true;
      end
      else
        pidout[tempseq*8+i-5].state:=false;
      if (rpidout>0.001) and (rpidout<1)  then
      begin
        Ftime:=TTimer(frmglass.FindComponent('tmtemp'+inttostr(tempseq*8+i-5)));
        Ftime.Interval:=trunc(pid_t*rpidout*1000);
        Ftime.Enabled:=true;
        lpDioWriteBit.state:=1;
        DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //打开PCL-722输出数据,输出占空比时间;
      end
      else
      begin
        if  (rpidout>=1) then
        begin
          lpDioWriteBit.state:=1;
          DRV_DioWriteBit(DeviceHandle,lpDioWriteBit);
        end
        else
        begin
          lpDioWriteBit.state:=0;
          DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //关闭PCL-722输出数据;
        end;
      end;
       Fpanel:=Tpanel(frmglass.FindComponent('pntem'+inttostr(tempseq*8+i-5)));
       Fpanel.Caption:=inttostr(strtoint(stemp[i-1]));
       Fedit:=Tedit(frmglass.FindComponent('edtemp'+inttostr(tempseq*8+i-5)));
       fedit.Text:=inttostr(strtoint(stemp[i-1]));
//       if (strtoint(stemp[i-1])>pidout[tempseq*8+i-5].setpoint) then
       itemp:=strtoint(stemp[i-1]);
       if (itemp>iwarntemp) then
       begin
         bwarn[tempseq*8+i-5]:=true;
         fedit.color:=clred;
         fedit.Font.Color:=clwhite;
       end
       else
       begin
         bwarn[tempseq*8+i-5]:=false;;
         fedit.Font.Color:=$006C6C00;
         if (itemp<100) then
           fedit.color:=$00FFFFE8;
         if (itemp<200) and (itemp>=100) then
           fedit.color:=$00A2FFAB;
         if (itemp<300) and (itemp>=200) then
           fedit.color:=$0080FFFF;
         if (itemp<400) and (itemp>=300) then
           fedit.color:=$00FFA4FF;
         if (itemp<500) and (itemp>=400) then
           fedit.color:=$00977AFC;
         if (itemp<600) and (itemp>=500) then
           fedit.color:=$00547AFC;
         if (itemp<700) and (itemp>=600) then
           fedit.color:=clLime;
       end;
    end;
   end;    //7口空闲;
   7:
   begin
    for i:=1 to 6 do
    begin
      icontrolseq:=tempseq*8+i-6;
      iheartport:=7;
      lpDioWriteBit.bit:=6-i;
      lpDioWriteBit.port:=iheartport;    //iheartport根据端口要变;
      if strtoint(stemp[i-1])>ipidtemp then
        rpidout:=PIDcalc(icontrolseq,stemp[i-1])/8000
      else
        rpidout:=ipower/100;
      if rpidout>1 then
      begin
        rpidout:=1;
        pidout[icontrolseq].state:=true;
      end
      else
        pidout[icontrolseq].state:=false;
      if (rpidout>0.001) and (rpidout<1)  then
      begin
        Ftime:=TTimer(frmglass.FindComponent('tmtemp'+inttostr(icontrolseq)));
        Ftime.Interval:=trunc(pid_t*rpidout*1000);
        Ftime.Enabled:=true;
        lpDioWriteBit.state:=1;
        DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //打开PCL-722输出数据,输出占空比时间;
      end
      else
      begin
        if  (rpidout>=1) then
        begin
          lpDioWriteBit.state:=1;
          DRV_DioWriteBit(DeviceHandle,lpDioWriteBit);
        end
        else
        begin
          lpDioWriteBit.state:=0;
          DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //关闭PCL-722输出数据;
        end;
      end;
       Fpanel:=Tpanel(frmglass.FindComponent('pntem'+inttostr(icontrolseq)));
       Fpanel.Caption:=inttostr(strtoint(stemp[i-1]));
       Fedit:=Tedit(frmglass.FindComponent('edtemp'+inttostr(icontrolseq)));
       fedit.Text:=inttostr(strtoint(stemp[i-1]));
//       if (strtoint(stemp[i-1])>pidout[icontrolseq].setpoint) then
       itemp:=strtoint(stemp[i-1]);
       if (itemp>iwarntemp) then
       begin
         bwarn[icontrolseq]:=true;
         fedit.color:=clred;
         fedit.Font.Color:=clwhite;
       end
       else
       begin
         bwarn[icontrolseq]:=false;
         fedit.Font.Color:=$006C6C00;
         if (itemp<100) then
           fedit.color:=$00FFFFE8;
         if (itemp<200) and (itemp>=100) then
           fedit.color:=$00A2FFAB;
         if (itemp<300) and (itemp>=200) then
           fedit.color:=$0080FFFF;
         if (itemp<400) and (itemp>=300) then
           fedit.color:=$00FFA4FF;
         if (itemp<500) and (itemp>=400) then
           fedit.color:=$00977AFC;
         if (itemp<600) and (itemp>=500) then
           fedit.color:=$00547AFC;
         if (itemp<700) and (itemp>=600) then
           fedit.color:=clLime;
       end;
       if (i=1) or (i=2) then
       begin
         frmglass.Edit8.Text:=floattostr(rpidout);
         frmglass.Edit6.Text:=floattostr(rpidout*8000);
       end;
    end;
     frmglass.edit1.Text:=inttostr(GetTickCount-dwstart); //debug}
   end;    //6,7口空闲;
  end;
 // frmglass.edit1.Text:=inttostr(GetTickCount-dwstart); //debug}
  finally
{     on e:exception do
     begin
        showmessage(e.Message);
     end;}
    tempseq:=tempseq+1;
    if tempseq=8 then
    begin
      tempseq:=0;
    end;
  end;
end;

function Ttempreader.PIDCalc(HeatPort:integer;temp:string):double;
var itemp:integer;
begin
    itemp:=strtoint(temp);
    if heatport=6 then
        heatport:=6;
    pidout[heatport].LastError:=pidout[heatport].setpoint-itemp;
    pidout[heatport].PrevError3:=pidout[heatport].PrevError2;
    pidout[heatport].PrevError2:=pidout[heatport].PrevError1;
    pidout[heatport].PrevError1:=pidout[heatport].LastError;
    pidout[heatport].sumError:=pidout[heatport].LastError+pidout[heatport].PrevError1+
        pidout[heatport].PrevError2+pidout[heatport].PrevError3;
    PIDCalc:=pid_p[itemp]*pidout[heatport].LastError+pid_i[itemp]*pidout[heatport].sumError+
        pid_d[itemp]*(pidout[heatport].LastError-pidout[heatport].PrevError1);
end;

end.

⌨️ 快捷键说明

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