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

📄 unit1.pas

📁 program kehuji uses Forms, Unit1 in ..zxcUnit1.pas {Form1}, Unit2 in ..zxcUnit2.pas {Form2
💻 PAS
字号:
unit unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, OleCtrls, MSCommLib_TLB;

type
  Tqianzhiji = class(TForm)
    GroupBox1: TGroupBox;
    GroupBox3: TGroupBox;
    MSComm1: TMSComm;
    Timer1: TTimer;
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Button2: TButton;
    Label5: TLabel;
    Label6: TLabel;
    Button1: TButton;
    Button3: TButton;
    Label3: TLabel;
    Edit5: TEdit;
    Timer2: TTimer;
    Label4: TLabel;
    numberfc: TLabel;
    numberpc: TLabel;
    GroupBox2: TGroupBox;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure MSComm1Comm(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  qianzhiji: Tqianzhiji;
 { kongtiao_wendu:Integer;
  kongtiao_shidu:Integer;
  jiawen:Boolean;
  jiashi:Boolean;       }
  meijilu:array[0..12] of integer;
  dianjilu:array[0..12] of integer;
  shuijilu:array[0..12] of integer;
  numberF:integer;
  numberP:integer;
  count:integer =1;

implementation

{$R *.dfm}
Procedure TimeDelay(DT:DWORD);
var
  TT:DWORD;
begin
  TT:=GetTickCount();
  while GetTickCount()-TT<DT do
    Application.ProcessMessages;
end;

procedure Tqianzhiji.Button1Click(Sender: TObject);
begin
   MSComm1.PortOpen:=False;
   timer1.Enabled := False;
   timer2.Enabled:= false;
   label4.Color:=clwhite;
   close;
end;

procedure Tqianzhiji.FormCreate(Sender: TObject);
var
i:integer;
begin
  if Not MSComm1.PortOpen then
  begin
     MSComm1.PortOpen:=True;
     MSComm1.DTREnable:=True;
     MSComm1.RTSEnable:=True;
  end;
  MSComm1.RThreshold := 1;
  label4.Color:=clwhite;




  for    i:=0 to 12
  do
  begin
  meijilu[i]:=0;
  dianjilu[i]:=0;
  shuijilu[i]:=0;
  end;
end;

procedure Tqianzhiji.Button2Click(Sender: TObject);
begin
   timer1.Enabled := True;
   timer2.Enabled:=True;
   label4.Color:=clyellow;
 {  zht1.Caption :='开机';
   zht2.Caption :='加温';
   zht3.Caption :='加湿';
   zht4.Caption :='开机';
   zht5.Caption :='正常';
   edit3.Text :='220';
   edit4.Text :='10';  }
end;

procedure Tqianzhiji.Timer1Timer(Sender: TObject);
var
   str1:string;
   str2:string;
   i:integer;

begin
for i:=1 to 12
do
begin
meijilu[i]:=meijilu[i]+random(2);
dianjilu[i]:=dianjilu[i]+random(2);
shuijilu[i]:=shuijilu[i]+random(3);
end;


 {
   if jiawen then begin
      zht2.Caption :='加温';
      kongtiao_wendu:=kongtiao_wendu+1;
      str1:=inttostr(kongtiao_wendu);
      if kongtiao_wendu=40 then begin
         jiawen:=False;
      end;
   end
   else begin
      kongtiao_wendu:=kongtiao_wendu-1;
      zht2.Caption :='降温';
      str1:=inttostr(kongtiao_wendu);
      if kongtiao_wendu=-20 then begin
         jiawen:=True;
      end;
   end;
   if jiashi then begin
      zht3.Caption :='加湿';
      kongtiao_shidu:=kongtiao_shidu+1;
      str2:=inttostr(kongtiao_shidu);
      if kongtiao_shidu=80 then begin
         jiashi:=False;
      end;
   end
   else begin
      zht3.Caption :='除湿';
      kongtiao_shidu:=kongtiao_shidu-1;
      str2:=inttostr(kongtiao_shidu);
      if kongtiao_shidu=20 then begin
         jiashi:=True;
      end;
   end;               }
   edit1.Text := str1;
   edit2.Text := str2;
end;

procedure Tqianzhiji.Button3Click(Sender: TObject);
begin
   timer1.Enabled := False;
   timer2.Enabled:=false;
   label4.Color:=clwhite;
   edit1.Text :='  ';
   edit2.Text :='  ';
   edit5.Text:='  ';
  { edit3.Text :='  ';
   edit4.Text :='  ';
   edit5.Text :='  ';  }
end;

procedure Tqianzhiji.MSComm1Comm(Sender: TObject);
var
  ReceBuf:string;
  str1:string;
  i:integer;

begin
  i:=1;
  ReceBuf := Trim(MSComm1.Input);
  if recebuf ='抄表'then
  begin
  if label4.Color<>clwhite
  then
  begin

       for i:=1 to 12
       do
       begin

        MSComm1.Output := inttostr(i)+'&';
        TimeDelay(100);
        str1:=inttostr(meijilu[i])+'&';           //温度
        MSComm1.Output := str1;
        TimeDelay(100);
        str1:=inttostr(dianjilu[i])+'&';          //湿度
        MSComm1.Output := str1;
        TimeDelay(100);
        str1:=inttostr(shuijilu[i])+'&';        //开机/关机
        MSComm1.Output := str1;
        TimeDelay(100);
        end;
   end
   else
   begin
      str1:='*';        //开机/关机
      MSComm1.Output := str1;
      TimeDelay(100);
   end;

     exit;
  end;

{  if ReceBuf='读空调' then begin
     if zht1.Caption='关机' then begin
        str1:='空调'+zht1.Caption;
        MSComm1.Output := str1;
     end
     else begin
        str1:='空调:';
        MSComm1.Output := str1;
        TimeDelay(100);
        str1:=edit1.Text;           //温度
        MSComm1.Output := str1;
        TimeDelay(100);
        str1:=edit2.Text;          //湿度
        MSComm1.Output := str1;
        TimeDelay(100);
        str1:=zht1.Caption;        //开机/关机
        MSComm1.Output := str1;
        TimeDelay(100);
        str1:=zht2.Caption;        //加温/降温
        MSComm1.Output := str1;
        TimeDelay(100);
        str1:=zht3.Caption;        //加湿/除湿
        MSComm1.Output := str1;
     end;
     exit;
  end;
  if ReceBuf='读UPS' then begin
     if zht4.Caption='关机' then begin
        str1:='UPS'+zht4.Caption;
        MSComm1.Output := str1;
     end
     else begin
        str1:='UPS:';           //电压
        MSComm1.Output := str1;
        TimeDelay(50);
        str1:=edit3.Text;           //电压
        MSComm1.Output := str1;
        TimeDelay(50);
        str1:=edit4.Text;          //电流
        MSComm1.Output := str1;
        TimeDelay(50);
        str1:=zht4.Caption;        //开机/关机
        MSComm1.Output := str1;
        TimeDelay(50);
        str1:=zht5.Caption;        //是否过载
        MSComm1.Output := str1;
        exit;
     end;
     exit;
  end;      }
end;

procedure Tqianzhiji.Timer2Timer(Sender: TObject);
var
a:integer;
begin

if count<>13
then
begin
edit1.Text:=inttostr(meijilu[count]);
edit2.Text:=inttostr(dianjilu[count]) ;
edit5.Text:=inttostr(shuijilu[count]);

if  (count<4)
then
begin
numberf:=1;
numberp:=count;

end;

if (count<8)and(count>3)
then
begin
numberf:=2;
numberp:=count-3;

end;

if ((count<13) and(count>7) )
then
begin
numberf:=3;
numberp:=count-7;



end;

numberfc.Caption:=inttostr(numberf);
numberpc.Caption:=inttostr(numberP);

count:=count+1;



end
else count:=1;






end;
end.

⌨️ 快捷键说明

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