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

📄 test.pas

📁 温度恒温控制,与PLC,工控板通讯,实现炉字过程控制.
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    procedure sdmodifyClick(Sender: TObject);
    procedure spcycleChange(Sender: TObject);
    procedure spwarntempChange(Sender: TObject);
    procedure sppowerChange(Sender: TObject);
    procedure bnupgwClick(Sender: TObject);
    procedure bnupdwClick(Sender: TObject);
    procedure bndowngwClick(Sender: TObject);
    procedure bndowndwClick(Sender: TObject);
    procedure udlowrowwc1ChangingEx(Sender: TObject;
      var AllowChange: Boolean; NewValue: Smallint;
      Direction: TUpDownDirection);
    procedure udlowrowwc2ChangingEx(Sender: TObject;
      var AllowChange: Boolean; NewValue: Smallint;
      Direction: TUpDownDirection);
    procedure udlowrowwc3ChangingEx(Sender: TObject;
      var AllowChange: Boolean; NewValue: Smallint;
      Direction: TUpDownDirection);
    procedure udlowrowwc4ChangingEx(Sender: TObject;
      var AllowChange: Boolean; NewValue: Smallint;
      Direction: TUpDownDirection);
    procedure udlowrowwc5ChangingEx(Sender: TObject;
      var AllowChange: Boolean; NewValue: Smallint;
      Direction: TUpDownDirection);
    procedure udlowrowwc6ChangingEx(Sender: TObject;
      var AllowChange: Boolean; NewValue: Smallint;
      Direction: TUpDownDirection);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure spgyfj2djChange(Sender: TObject);
    procedure spgyfj1djChange(Sender: TObject);
    procedure sppidChange(Sender: TObject);
    procedure sppidtmpChange(Sender: TObject);
    procedure spjgsjChange(Sender: TObject);
    procedure bnpid1Click(Sender: TObject);
    procedure bnpid2Click(Sender: TObject);
    procedure bnpid3Click(Sender: TObject);
    procedure bnpid4Click(Sender: TObject);
    procedure bnpid5Click(Sender: TObject);
    procedure bnpid6Click(Sender: TObject);
    procedure bnpid7Click(Sender: TObject);
  private
    fconfig:Tconfig;
    Fomron:Tomron_Fins;
    ftempreader:Ttempreader;
    procedure loadconfig(sfile:string);
    Procedure pcBeep(nFreq,nDura: Word);      
    procedure setcurrent(icurrtab: integer);
    { Private declarations }
  public
    procedure update_artist;  
    { Public declarations }
  end;

var
  frmglass: Tfrmglass;
  I:integer;
implementation

uses dsVariable, Str_Utils, Driver;

{$R *.dfm}

Procedure Tfrmglass.pcBeep(nFreq,nDura: Word);         //pc喇叭发声
var
  VerInfo: TOSVersionInfo;
  nStart: DWord;
begin
  VerInfo.dwOSVersionInfoSize := SizeOf(VerInfo);
  GetVersionEx(VerInfo);
    if VerInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then
      Windows.Beep(nFreq, nDura)
    else
    begin
      Asm
            push    bx
            in      al,     $61
            mov     bl,     al
            and     al,     3
            jne     @@Skip
            mov     al,     bl
            or      al,     3
            out     $61,    al
            mov     al,     $b6
            out     $43,    al
      @@Skip:   
            mov     ax,     nFreq
            out     $42,    al
            mov     AL,     ah
            out     $42,    al
            pop     bx
      end;
      nStart := GetTickCount;
      repeat
        Application.ProcessMessages;
      Until GetTickCount > nStart + nDura;
      asm
            IN      AL,     $61
            AND     AL,     $FC
            OUT     $61,    AL
      end;
    end;
end;
procedure Tfrmglass.update_artist;
begin
 try
   self.pndwsj.Height:=round(self.pndwgd.Height*strtoint(sj_dw)/strtoint(para_dw));
   self.pndwz.Caption:=sj_dw;
   self.pngwsj.Height:=round(self.pngwgd.Height*strtoint(sj_gw)/strtoint(para_gw));
   self.pngwz.Caption:=sj_gw;
   self.pnqhsj.Height:=round(self.pnqhgd.Height*strtoint(sj_qh)/strtoint(para_qh));
   self.pnqhz.Caption:=sj_qh;
   self.pnlqsj.Height:=round(self.pnlqgd.Height*strtoint(sj_lq)/strtoint(para_lq));
   self.pnlqz.Caption:=sj_lq;
   self.pnjgsj.Height:=round(self.pnjggd.Height*strtoint(sj_interval)/strtoint(para_interval));
   self.pnjgz.Caption:=sj_interval;
   self.pnfj1sj.Height:=round(self.pnfj1gd.Height*strtoint(sj_fj1)/1000);
   self.pnfj1sd.Height:=round(self.pnfj1gd.Height*strtoint(para_fj1)/1000);
   self.pnfj1z.Caption:=sj_fj1;
   self.pnfj2sj.Height:=round(self.pnfj2gd.Height*strtoint(sj_fj2)/1000);
   self.pnfj2sd.Height:=round(self.pnfj1gd.Height*strtoint(para_fj2)/1000);
   self.pnfj2z.Caption:=sj_fj2;
   self.pnfj3sj.Height:=round(self.pnfj3gd.Height*strtoint(sj_fj3)/1000);
   self.pnfj3sd.Height:=round(self.pnfj1gd.Height*strtoint(para_fj3)/1000);   
   self.pnfj3z.Caption:=sj_fj3;
 except

 end;
end;

procedure Tfrmglass.tmdateTimer(Sender: TObject);
begin
 lbtime.Caption:=timetostr(now);
end;

procedure Tfrmglass.FormCreate(Sender: TObject);
var sdir1,sdir2,weekname:string;
    ec:Tcanvas;
    hmutex:integer;
    AppName:string;
    PreviousInstanceWindow:Thandle;
    wyear,wMonth,wDay:Word;    
begin
  hmutex:=createmutex(nil,false,'RunOnlyOneInstance_dglass');
  if (hmutex=0) or (ERROR_ALREADY_EXISTS=getlastError) then
  begin
     AppName:=application.Title;
     Application.ShowMainForm:=False;
     Application.Title:='Destory Me';
     PreviousInstanceWindow:=FindWindow(nil,PChar(AppName));
      if PreviousInstanceWindow<>0 then
      begin
         if IsIconic(PreviousInstanceWindow) then
           ShowWindow(PreviousInstanceWindow,SW_RESTORE)
        else
           SetForegroundWindow(PreviousInstanceWindow);
      end;
    application.Terminate;
    exit;
  end;
  sdir1:=ExtractFilePath(Application.ExeName)+'log';
  if not directoryexists(sdir1) then
      ForceDirectories(sdir1);
  self.savedlog.InitialDir:=sdir1;
  sdir2:=ExtractFilePath(Application.ExeName)+'glassfile';
  if not directoryexists(sdir2) then
      ForceDirectories(sdir2);
 self.savedlfile.InitialDir:=sdir2;
 Decodedate(now,wyear,wmonth,wday);
 lbyearmonth.Caption:=format('%s年%s月',[vartostr(wyear),vartostr(wMonth)]);
 lbday.Caption:=format('%s',[vartostr(wDay)]);
 lbtime.Caption:=timetostr(now);
 case dayofweek(now) of
    1:  weekname:='星期日';
    2:  weekname:='星期一';
    3:  weekname:='星期二';
    4:  weekname:='星期三';
    5:  weekname:='星期四';
    6:  weekname:='星期五';
    7:  weekname:='星期六';
 end;
 lbweek.Caption:=weekname;
{ ec:=Tcanvas.Create;
 ec.Handle:=edlt.Handle;
 ec.Font.Color:=$006C6C00;
 ec.TextOut(0,0,edlt.Text); }
{ SetWindowLong(edlt.Handle,GWL_STYLE,GetWindowLong(edlt.Handle,GWL_STYLE) or ES_CENTER);
 SetWindowLong(edfs.Handle,GWL_STYLE,GetWindowLong(edlt.Handle,GWL_STYLE) or ES_CENTER);
 SetWindowLong(edcd.Handle,GWL_STYLE,GetWindowLong(edlt.Handle,GWL_STYLE) or ES_CENTER);
 SetWindowLong(edjl.Handle,GWL_STYLE,GetWindowLong(edlt.Handle,GWL_STYLE) or ES_CENTER);
 SetWindowLong(edlq.Handle,GWL_STYLE,GetWindowLong(edlt.Handle,GWL_STYLE) or ES_CENTER);  }
 fconfig:=Tconfig.Create;
 ftempreader:=TTempreader.create;
 Fomron:=Tomron_Fins.create;
 temp_com:=fconfig.read_ini(GetcurrentDir+'\config.ini','COM','temp','');
 plc_com:=fconfig.read_ini(GetcurrentDir+'\config.ini','COM','PLC','');
 sdefaultfile:=fconfig.read_ini(GetcurrentDir+'\config.ini','玻璃默认配置','filename','');
 tempseq:=0;
    para_dw:=inttostr(splowheat.Value);
    para_gw:=inttostr(sphighheat.Value);
    para_qh:=inttostr(spqh.Value);
    para_lq:=inttostr(splq.Value);
    para_fj1:=inttostr(spfj1qh.Value);
    para_fj2:=inttostr(spfj2qh.Value);
    para_fj3:=inttostr(spfj3lq.Value);
    para_fj1dj:='0';
    para_fj2dj:='0';
//  bwarn:=false;
  iwarn:=0;
  sj_dw:='0';
  sj_gw:='0';
  sj_qh:='0';
  sj_lq:='0';
  sj_fj1:='0';
  sj_fj2:='0';
  sj_fj3:='0';
  swriteerrormessage[1]:='写工艺数据错误';
  swriteerrormessage[2]:='写时间数据错误';
  swriteerrormessage[3]:='写距离数据错误';
  swriteerrormessage[4]:='写速度数据错误';
  swriteerrormessage[5]:='写风机数据错误';
  bstart:=true;
end;

procedure Tfrmglass.tmtemp1Timer(Sender: TObject);
var itmseq:integer;
begin
    itmseq:=(sender as TTimer).Tag;     //timer的编号
    if (itmseq>=1) and (itmseq<=7) then
    begin
       lpDioWriteBit.port:=2;
       lpDioWriteBit.bit:=7-itmseq;
{      if itmseq=1 then
        if pidout[itmseq].state then
          self.Edit7.Text:='ok0-true'+inttostr((sender as TTimer).Interval)
        else
          self.Edit7.Text:='ok0-false'+inttostr((sender as TTimer).Interval);//debug }
    end;
    if (itmseq>=8) and (itmseq<=14) then
    begin
      lpDioWriteBit.port:=1;
      lpDioWriteBit.bit:=14-itmseq;
    end;
    if (itmseq>=15) and (itmseq<=21) then
    begin
      lpDioWriteBit.port:=0;
      lpDioWriteBit.bit:=21-itmseq;
    end;
    if (itmseq>=22) and (itmseq<=28) then
    begin
      lpDioWriteBit.port:=5;
      lpDioWriteBit.bit:=28-itmseq;
    end;
    if (itmseq>=29) and (itmseq<=35) then
    begin
      lpDioWriteBit.port:=4;
      lpDioWriteBit.bit:=35-itmseq;
     end;
    if (itmseq>=36) and (itmseq<=42) then
    begin
      lpDioWriteBit.port:=3;
      lpDioWriteBit.bit:=42-itmseq;
     end;
    if (itmseq>=43) and (itmseq<=49) then
    begin
      lpDioWriteBit.port:=8;
      lpDioWriteBit.bit:=49-itmseq;
    end;
    if (itmseq>=50) and (itmseq<=56) then
    begin
      lpDioWriteBit.port:=7;
      lpDioWriteBit.bit:=56-itmseq;
    end;
//   if not pidout[itmseq].state then
//   begin     {原来为了减少开关动作,设置了state,如果要求一直加热,就不关了...,现在要求按比例加热,保护炉膛,每次加热后都关闭}
      lpDioWriteBit.state:=0;
      DRV_DioWriteBit(DeviceHandle,lpDioWriteBit); //PCL-722输出数据;
{      if itmseq=1 then
      begin
        self.Edit7.Text:=self.Edit7.Text+' 关闭...';
        self.Edit10.Text:=inttostr(gettickcount-starttime);
      end; //debug}
//  end;
{    else
      if itmseq=8 then
        self.Edit8.Text:=self.Edit8.Text+' 继续...'; //debug}
    (sender as TTimer).Enabled:=false;
end;

procedure Tfrmglass.Button1Click(Sender: TObject);
begin
  self.Timer0.Enabled:=true;
  self.Color:=clBtnFace;
end;

procedure Tfrmglass.bbtncloseClick(Sender: TObject);
begin
  self.bnstop.Click;
  fconfig.write_ini(ExtractFilePath(Application.ExeName)+'config.ini','玻璃默认配置','filename',sdefaultfile);
  if self.tmtemp.Enabled then
    self.tmtemp.Enabled:=false;
  if self.tmplc.Enabled then
    self.tmplc.Enabled:=false;
  self.ftempreader.Terminate;
  self.ftempreader.Free;
  self.fconfig.Free;
  self.Fomron.closecomm;
  self.Fomron.Free;
  self.close;
  application.Terminate;
end;

procedure Tfrmglass.bnwarnclearClick(Sender: TObject);
begin
  self.Fomron.CommandsendSignal(15); 
end;

procedure Tfrmglass.bnsavelogClick(Sender: TObject);
var slogname:string;
    f:textfile;
    i:integer;
begin
  if self.memlog.Lines.Count=0 then exit;
  self.savedlog.InitialDir:=extractfilepath(Application.ExeName)+'log';
  slogname:=inttostr(yearof(date))+'-'+rightstr('00'+inttostr(monthof(date)),2)+
      '-'+rightstr('00'+inttostr(dayof(date)),2);
  self.savedlog.FileName:=slogname;
  if self.savedlog.Execute() then
  begin
    slogname:=self.savedlog.FileName;
    assignfile(f,self.savedlog.FileName);
    if not fileexists(slogname) then
       rewrite(f)
    else
       append(f);
    for i:=1 to self.memlog.Lines.Count do
        writeln(f,self.memlog.lines[i]);
    closefile(f);
    messagebox(handle,'日志数据已保存!','系统提示',mb_ok);
  end;
end;

procedure Tfrmglass.bnloadlogClick(Sender: TObject);
var f:textfile;
    instring:string;
begin
  self.opendlog.InitialDir:=extractfilepath(Application.ExeName)+'log';
  if self.opendlog.Execute() then
  begin
    self.memlog.Clear;
    assignfile(f,self.opendlog.FileName);
    reset(f);
    while not eof(f) do
    begin
      readln(f,instring);
      self.memlog.Lines.Add(instring);
    end;
    closefile(f);
  end;
end;

procedure Tfrmglass.bndeletelogClick(Sender: TObject);
begin
  self.memlog.Clear;
end;

procedure Tfrmglass.bnsavefileClick(Sender: TObject);
var ini:Tinifile;
    sfilename,si:string;
    i:integer;
    Fspinedit:Tspinedit;
begin
  if edthick.Text='' then exit;
  self.savedlfile.InitialDir:=extractfilepath(Application.ExeName)+'glassfile';
  sfilename:=trim(edthick.Text);

⌨️ 快捷键说明

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