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

📄 installed_simu.~pas

📁 使用Delphi 6.0开发用于控制空调的程序
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
    bBuffer[0] :=$7E;  //起始位
     bBuffer[1] :=$02;  //versiosn
     bBuffer[2] :=$00;
     bBuffer[3] :=$00;  //address
     bBuffer[4] :=$00;//StrToInt(strAdd);
     bBuffer[5] :=$06;  //C1D1
     bBuffer[6] :=$00;
     bBuffer[7] :=$04;  //C1D2
     bBuffer[8] :=$02;
     bBuffer[9] :=$00; //LCJKSUM
     bBuffer[10] :=$00;  //LENID
     bBuffer[11] :=$00;
     bBuffer[12] :=$00;
     for i := 1 to Length(bBuffer) - 5 do
     begin
        sum := sum + Ord(bBuffer[i]);
     end;
     strSum := IntToHex(sum,2);
     ShowMessage('strSum: '+strSum);
     WLen := 0;
     WLen := Length(strSum);
     if WLen = 1 then
     begin
         str4 := '0';
         str3 := '0';
         str2 := '0';
         str1 := Copy(strSum,1,1);
         ShowMessage('1111  str1: '+str4+' '+str3+' '+str2+' '+str1+' ');
     end
     else
     if WLen = 2 then
     begin
         str4 := '0';
         str3 := '0';
         str2 := Copy(strSum,1,1);
         str1 := Copy(strSum,2,1);
         ShowMessage('2222  str1: '+str4+' '+str3+' '+str2+' '+str1+' ');
     end
     else
     if WLen = 3 then
     begin
         str4 := '0';
         str3 := Copy(strSum,1,1);
         str2 := Copy(strSum,2,1);
         str1 := Copy(strSum,3,1);
        ShowMessage('3333  str1: '+str4+' '+str3+' '+str2+' '+str1+' ');
     end
     else
     if WLen = 4 then
     begin
       str4 := Copy(strSum,1,1);
       str3 := Copy(strSum,2,1);
       str2 := Copy(strSum,3,1);
       str1 := Copy(strSum,4,1);
       ShowMessage('4444  str1: '+str4+' '+str3+' '+str2+' '+str1+' ');
     end;

     b4 :=HexToInt(str4);  //高,CHKSUM ,
     b3 :=HexToInt(str3);
     b2 :=HexToInt(str2);  //低
     b1 :=HexToInt(str1);
     ShowMessage('b4:'+IntToHex(b4,2));
     ShowMessage('b3:'+IntToHex(b3,2));
     ShowMessage('b2:'+IntToHex(b2,2));
     ShowMessage('b1:'+IntToHex(b1,2));
     ShowMessage('b1 Len:'+IntToStr(Length(IntToHex(b1,2))));

end;

procedure TSetting.btn1Click(Sender: TObject);
var
  strLines:string;
  command:TControlCommand;
  add:string;
begin
  if dblkcbbAddress.Visible = True then
    add := Trim(dblkcbbAddress.Text)
  else
  if cbbadd.Visible = True then
    add := Trim(cbbadd.Text);
   if Length(add) = 1 then
   begin
     add := '0' + add;
   end;
  command := TControlCommand.Create(24);
  try
      command.RemoteControl(add,'11');
     try
          if not main.frmain.Spcomm1.PortOpen  then
          begin
             try
                 main.frmain.Spcomm1.StartComm;
             except
                ShowMessage('打开串口失败,'+ '当前串口名:'+Main.frmain.Spcomm1.CommName+',波特率为:'+IntToStr(Main.frmain.Spcomm1.BaudRate));
             end;
          end;
          strLines :=command.GetCommandLines;
          if command.GetError = '正常' then
          begin
                  strLines :=command.GetCommandLines;
                  statSetting.SimpleText := strLines;
                  main.frmain.Spcomm1.WriteCommData( PChar(strLines),Length(strLines));
                  iRC :=3;
          end
          else
          begin
                 statSetting.SimpleText := command.GetError;
          end;
        //  main.frmain.Spcomm1.WriteCommData( PChar(strLines),Length(strLines));
     except
       ShowMessage('远程控制命令发生失败');
     end;
  finally
    command.Free;
  end;

end;

procedure TSetting.btnRunClick(Sender: TObject);
var
  strLines:string;
  command:TControlCommand;
  add:string;
begin
   if dblkcbbAddress.Visible = True then
    add := Trim(dblkcbbAddress.Text)
  else
  if cbbadd.Visible = True then
    add := Trim(cbbadd.Text);
   if Length(add) = 1 then
   begin
     add := '0' + add;
   end;
  command := TControlCommand.Create(24);
  try
     command.RemoteControl(add,'10');
     try
          if not main.frmain.Spcomm1.PortOpen  then
          begin
            try
                 main.frmain.Spcomm1.StartComm;
            except
                statSetting.SimpleText :='打开串口失败,'+ '当前串口名:'+Main.frmain.Spcomm1.CommName+',波特率为:'+IntToStr(Main.frmain.Spcomm1.BaudRate);
            end;
          end;  

          strLines :=command.GetCommandLines;
          if command.GetError = '正常' then
          begin
                  strLines :=command.GetCommandLines;
                  statSetting.SimpleText := strLines;
                  main.frmain.Spcomm1.WriteCommData( PChar(strLines),Length(strLines));
                  iRC := 1;
          end
          else
          begin
                 statSetting.SimpleText := command.GetError;
          end;
     except
       statSetting.SimpleText :='远程运行命令发生失败';
     end;
  finally
    command.Free;
  end;

end;

procedure TSetting.dblkcbbACAddressExit(Sender: TObject);
begin
   with ADOqryAQAC do
   begin
     Close;
      SQL.Clear;
      SQL.Add('select * from AC where id=:@iid');
      Parameters.ParamByName('@iid').Value := dblkcbbACAddress.Text;
      Open;
   end;
end;

procedure TSetting.dblkcbbACAddressClick(Sender: TObject);
begin
   if ADOqryID.Active = False then
       ADOqryID.Active := True;
end;

procedure TSetting.dblkcbbAddressClick(Sender: TObject);
begin
    if ADOqryAQAC.Active = False then
       ADOqryAQAC.Active := True ;
end;

procedure TSetting.btnStopClick(Sender: TObject);
var
  strLines:string;
  command:TControlCommand;
  add:string;
begin
   if dblkcbbAddress.Visible = True then
    add := Trim(dblkcbbAddress.Text)
  else
  if cbbadd.Visible = True then
    add := Trim(cbbadd.Text);
   if Length(add) = 1 then
   begin
     add := '0' + add;
   end;
   command := TControlCommand.Create(24);
  try
     command.RemoteControl(add,'1F');
     try
          if not main.frmain.Spcomm1.PortOpen  then
           begin
            try
                 main.frmain.Spcomm1.StartComm;
            except
                statSetting.SimpleText :='打开串口失败,'+ '当前串口名:'+Main.frmain.Spcomm1.CommName+',波特率为:'+IntToStr(Main.frmain.Spcomm1.BaudRate);
            end;
          end;  
          strLines :=command.GetCommandLines;
          if command.GetError = '正常' then
          begin
                  strLines :=command.GetCommandLines;
                  statSetting.SimpleText := strLines;
                  main.frmain.Spcomm1.WriteCommData( PChar(strLines),Length(strLines));
                  iRC := 2;
          end
         else
         begin
                 statSetting.SimpleText := command.GetError;
         end;
     except
       statSetting.SimpleText :='命令发生失败';
     end;
  finally
    command.Free;
  end;

end;

procedure TSetting.dblkcbbACAddressMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
//     if frmain.conAir.Connected then
//     ShowMessage('数据库已经连接连接');
   if ADOqryID.Active = False then
       ADOqryID.Active := True;
end;

procedure TSetting.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   iSet := 99;
   iRC := 99;
   frmain.iClick := 99;
   if btmrs = True then
   begin
     btmrs := False;
     frmain.tmrTC.Enabled := True;
     //ShowMessage('FormClose:true');
   end
   else
   begin
       btmrs := False;
       frmain.tmrTC.Enabled := False;
       //ShowMessage('FormClose:False');
   end;
end;

procedure TSetting.FormPaint(Sender: TObject);
begin
     if frmain.tmrTC.Enabled = True then
   begin
     btmrs := True;
     frmain.tmrTC.Enabled := False;
    // ShowMessage('FormCreate:true');
   end
   else
   begin
       btmrs := False;
       frmain.tmrTC.Enabled := False;
      // ShowMessage('FormCreate:False');
   end;

   if frmain.iClick = 1 then
   begin
     Setting.dblkcbbACAddress.Visible := False;
     Setting.dblkcbbAddress.Visible := False;
     Setting.cbbid.Visible := True;
     Setting.cbbadd.Visible := True;
     Setting.cbbid.Text := '00';
     Setting.cbbadd.Text := '01';
   end
   else
   if frmain.iClick = 2 then
   begin
     Setting.dblkcbbACAddress.Visible := False;
     Setting.dblkcbbAddress.Visible := False;
     Setting.cbbid.Visible := True;
     Setting.cbbadd.Visible := True;
     Setting.cbbid.Text := '00';
     Setting.cbbadd.Text := '02';
   end
   else
   if frmain.iClick = 3 then
   begin
     Setting.dblkcbbACAddress.Visible := False;
     Setting.dblkcbbAddress.Visible := False;
     Setting.cbbid.Visible := True;
     Setting.cbbadd.Visible := True;
     Setting.cbbid.Text := '00';
     Setting.cbbadd.Text := '03';
   end
   else
   if frmain.iClick = 4 then
   begin
     Setting.dblkcbbACAddress.Visible := False;
     Setting.dblkcbbAddress.Visible := False;
     Setting.cbbid.Visible := True;
     Setting.cbbadd.Visible := True;
     Setting.cbbid.Text := '00';
     Setting.cbbadd.Text := '04';
   end
   else
   if frmain.iClick = 5 then
   begin
     Setting.dblkcbbACAddress.Visible := False;
     Setting.dblkcbbAddress.Visible := False;
     Setting.cbbid.Visible := True;
     Setting.cbbadd.Visible := True;
     Setting.cbbid.Text := '00';
     Setting.cbbadd.Text := '05';
   end
   else
   if frmain.iClick = 6 then
   begin
     Setting.dblkcbbACAddress.Visible := False;
     Setting.dblkcbbAddress.Visible := False;
     Setting.cbbid.Visible := True;
     Setting.cbbadd.Visible := True;
     Setting.cbbid.Text := '00';
     Setting.cbbadd.Text := '06';
   end
   else
   if frmain.iClick = 7 then
   begin
     Setting.dblkcbbACAddress.Visible := False;
     Setting.dblkcbbAddress.Visible := False;
     Setting.cbbid.Visible := True;
     Setting.cbbadd.Visible := True;
     Setting.cbbid.Text := '00';
     Setting.cbbadd.Text := '07';
   end
   else
   if frmain.iClick = 8 then
   begin
     Setting.dblkcbbACAddress.Visible := False;
     Setting.dblkcbbAddress.Visible := False;
     Setting.cbbid.Visible := True;
     Setting.cbbadd.Visible := True;
     Setting.cbbid.Text := '00';
     Setting.cbbadd.Text := '08';
   end
   else
   begin
     Setting.dblkcbbACAddress.Visible := True;
     Setting.dblkcbbAddress.Visible := True;
     Setting.cbbid.Visible := False;
     Setting.cbbadd.Visible := False;
     //Setting.cbbid.Text := '00';
    // Setting.cbbadd.Text := '03';
   end;  
end;

end.

⌨️ 快捷键说明

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