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

📄 sendcommand.pas

📁 这是一个正式的项目工程
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  ssAscend,ssDescend,ssNullAsc,ssNullDes:
    begin
      HHeight:=Round(AllExtension[CurrentExtensionID].Height-StartHeight);
      HHeight:=Abs(HHeight);
      if HHeight>StateInfo.Height then
      begin
        HHeight:=0;
        StateInfo.SystemState:=ssNormal;
        PauseSampling;
        SendStopCommand();
        ResumeSampling;
        DisplayInfo('升降过程结束','0');
        StopProgress();
      end
      else
      begin
        SetProgress(HHeight);
      end;
    end;
  ssAscPrepare,ssDesPrepare:
    begin
      if ExtensionPrepareFinish(StateInfo.CurrentOperateExtension) then
      begin
        StateInfo.SystemState:=ssNormal;
        PauseSampling;
        SendStopCommand();
        ResumeSampling;
        StopProgress;
        DisplayInfo('准备过程结束','0');
        CountPrepare:=0;
      end
      else
      begin
        CountPrepare:=CountPrepare+1;
        SetProgress(CountPrepare);
        if CountPrepare>PrepareOverFlow then
        begin
        Str:=ExtensionNotFinish(StateInfo.CurrentOperateExtension);
        StateInfo.SystemState:=ssNormal;
        PauseSampling;
        SendStopCommand();
        ResumeSampling;
        StopProgress;
        DisplayInfo('准备过程超时','1');
        CountPrepare:=0;
        ShowErrorReport('准备超时,分机'+Str+'未到位,可能挂钩未挂好,请检查后再试!');
        //ShowMessage('准备超时,分机'+Str+'未到位,可能挂钩未挂好,请检查后再试!');
        end;
      end;
    end;
  ssDownLoad:
    begin
      if ExtensionDownloadFinish(StateInfo.CurrentOperateExtension) then
      begin
        StateInfo.SystemState:=ssNormal;
        PauseSampling;
        SendStopCommand();
        ResumeSampling;
        StopProgress;
        DisplayInfo('卸载过程结束','0');
        CountDownload:=0;
      end
      else
      begin
        CountDownload:=CountDownload+1;
        SetProgress(CountDownload);
        if CountDownload>DownloadOverFlow then
        begin
        Str:=ExtensionNotFinish(StateInfo.CurrentOperateExtension);
        StateInfo.SystemState:=ssNormal;
        PauseSampling;
        SendStopCommand();
        ResumeSampling;
        StopProgress;
        DisplayInfo('卸载过程超时','1');
        CountDownload:=0;
        ShowErrorReport('卸载超时,分机'+Str+'未到位,可能构件未固定,请检查后再试!');
        //ShowMessage('卸载超时,分机'+Str+'未到位,可能构件未固定,请检查后再试!')
        end;
      end;

    end;
  end;


  if CheckBoxIQ.Checked Then
  begin
  if RadioButtonGravity.Checked then
  begin
    Case StateInfo.SystemState of
    ssAscend:
      begin
        for i:=0 to StateInfo.CurrentGroupCount-1 do
        begin
        if AllGroup[i].GroupID<>'' then
        begin
          MaxMinExtension:=GetMaxMinGrivaty(AllGroup[i].GroupID);
          iExtension:=StrToInt(MaxMinExtension.MaxExtensionID);
          iDExtension:=StrToInt(MaxMinExtension.MinExtensionID);
          if (MustStop(iExtension) or DMustStop(iDExtension)) then
          begin
            AllExtension[iExtension].OverCount:=AllExtension[iExtension].OverCount+1;
            if (AllExtension[iExtension].OverCount>=2) then
            begin
              AllExtension[iExtension].OverCount:=0;
              AllExtension[iExtension].Adjusting:=False;
              if StateInfo.SystemState<>ssNormal then
              begin
                PauseSampling;
                SendStopCommand();
                SaveData;
                ErrorAnalysis(ssAscend);
                ResumeSampling;
                StopProgress;
                DisplayInfo('向所有分机发停止命令','1');
              end;
            end
            else
            begin
              PauseSampling;
              SendAdjustCommand(FormExtensionID(iExtension));
              SaveData;
              AllExtension[iExtension].Adjusting:=True;
              ResumeSampling;
              DisplayInfo('向分机'+MaxMinExtension.MaxExtensionID+'发上升调整命令','0');
            end;
            FlagSaved:=True;
          end
          else if (MustAdjust(iExtension) or DMustAdjust(iDExtension)) then
          begin
            PauseSampling;
            SendAdjustCommand(FormExtensionID(iExtension));
            SaveData;
            AllExtension[iExtension].Adjusting:=True;
            ResumeSampling;
            DisplayInfo('向分机'+MaxMinExtension.MaxExtensionID+'发上升调整命令','0');
            AllExtension[iExtension].OverCount:=0;
            FlagSaved:=True;
          end
          else
          begin
            AllExtension[iExtension].OverCount:=0;
            AllExtension[iExtension].Adjusting:=False;
          end;
        end;
        end;
      end;
    ssDescend:
      begin
        for i:=0 to StateInfo.CurrentGroupCount-1 do
        begin
        if AllGroup[i].GroupID<>'' then
        begin
          MaxMinExtension:=GetMaxMinGrivaty(AllGroup[i].GroupID);
          iExtension:=StrToInt(MaxMinExtension.MaxExtensionID);
          iDExtension:=StrToInt(MaxMinExtension.MinExtensionID);
          if (MustStop(iExtension) or DMustStop(iDExtension)) then
          begin
            AllExtension[iDExtension].OverCount:=AllExtension[iDExtension].OverCount+1;
            if (AllExtension[iDExtension].OverCount>=2) then
            begin
              AllExtension[iDExtension].OverCount:=0;
              AllExtension[iDExtension].Adjusting:=False;
              if StateInfo.SystemState<>ssNormal then
              begin
                PauseSampling;
                SendStopCommand();
                SaveData;
                ErrorAnalysis(ssDescend);
                ResumeSampling;
                StopProgress;
                DisplayInfo('向所有分机发停止命令','1');
              end;
            end
            else
            begin
              PauseSampling;
              SendAdjustCommand(FormExtensionID(iDExtension));
              SaveData;
              AllExtension[iDExtension].Adjusting:=True;
              ResumeSampling;
              DisplayInfo('向分机'+MaxMinExtension.MinExtensionID+'发下降调整命令','0');
            end;
            FlagSaved:=True;
          end
          else if (MustAdjust(iExtension) or DMustAdjust(iDExtension)) then
          begin
            PauseSampling;
            SendAdjustCommand(FormExtensionID(iDExtension));
            SaveData;
            AllExtension[iDExtension].Adjusting:=True;
            ResumeSampling;
            DisplayInfo('向分机'+MaxMinExtension.MinExtensionID+'发下降调整命令','0');
            AllExtension[iDExtension].OverCount:=0;
            FlagSaved:=True;
          end
          else
          begin
            AllExtension[iDExtension].OverCount:=0;
            AllExtension[iDExtension].Adjusting:=False;
          end;
        end;
        end;
      end;
    end;
  end
  else    //Adjust by HoriDiff;
  begin
    Case StateInfo.SystemState of
    ssAscend:
      begin
        for i:=0 to StateInfo.CurrentGroupCount-1 do
        begin
        if AllGroup[i].GroupID<>'' then
        begin
          MaxMinExtension:=GetMaxMinDiff(AllGroup[i].GroupID);
          iExtension:=StrToInt(MaxMinExtension.MaxExtensionID);
          iDExtension:=StrToInt(MaxMinExtension.MinExtensionID);
          if (MustStop(iExtension) or DMustStop(iDExtension)) then
          begin
            AllExtension[iExtension].OverCount:=AllExtension[iExtension].OverCount+1;
            if (AllExtension[iExtension].OverCount>=2) then
            begin
              AllExtension[iExtension].OverCount:=0;
              AllExtension[iExtension].Adjusting:=False;
              if StateInfo.SystemState<>ssNormal then
              begin
                PauseSampling;
                SendStopCommand();
                SaveData;
                ResumeSampling;
                StopProgress;
                DisplayInfo('向所有分机发停止命令','1');
              end;
            end
            else
            begin
              PauseSampling;
              SendAdjustCommand(FormExtensionID(iExtension));
              SaveData;
              AllExtension[iExtension].Adjusting:=True;
              ResumeSampling;
              DisplayInfo('向分机'+MaxMinExtension.MaxExtensionID+'发上升调整命令','0');
            end;
            FlagSaved:=True;
          end
          else if (MustAdjust(iExtension) or DMustAdjust(iDExtension)) then
          begin
            PauseSampling;
            SendAdjustCommand(FormExtensionID(iExtension));
            SaveData;
            AllExtension[iExtension].Adjusting:=True;
            ResumeSampling;
            DisplayInfo('向分机'+MaxMinExtension.MaxExtensionID+'发上升调整命令','0');
            AllExtension[iExtension].OverCount:=0;
            FlagSaved:=True;
          end
          else
          begin
            AllExtension[iExtension].OverCount:=0;
            AllExtension[iExtension].Adjusting:=False;
          end;
        end;
        end;
      end;
    ssDescend:
      begin
        for i:=0 to StateInfo.CurrentGroupCount-1 do
        begin
        if AllGroup[i].GroupID<>'' then
        begin
          MaxMinExtension:=GetMaxMinDiff(AllGroup[i].GroupID);
          iExtension:=StrToInt(MaxMinExtension.MaxExtensionID);
          iDExtension:=StrToInt(MaxMinExtension.MinExtensionID);
          if (MustStop(iExtension) or DMustStop(iDExtension)) then
          begin
            AllExtension[iDExtension].OverCount:=AllExtension[iDExtension].OverCount+1;
            if (AllExtension[iDExtension].OverCount>=2) then
            begin
              AllExtension[iDExtension].OverCount:=0;
              AllExtension[iDExtension].Adjusting:=False;
              if StateInfo.SystemState<>ssNormal then
              begin
                PauseSampling;
                SendStopCommand();
                SaveData;
                ResumeSampling;
                StopProgress;
                DisplayInfo('向所有分机发停止命令','1');
              end;
            end
            else
            begin
              PauseSampling;
              SendAdjustCommand(FormExtensionID(iDExtension));
              SaveData;
              AllExtension[iDExtension].Adjusting:=True;
              ResumeSampling;
              DisplayInfo('向分机'+MaxMinExtension.MinExtensionID+'发下降调整命令','0');
            end;
            FlagSaved:=True;
          end
          else if (MustAdjust(iExtension) or DMustAdjust(iDExtension)) then
          begin
            PauseSampling;
            SendAdjustCommand(FormExtensionID(iDExtension));
            SaveData;
            AllExtension[iDExtension].Adjusting:=True;
            ResumeSampling;
            DisplayInfo('向分机'+MaxMinExtension.MinExtensionID+'发下降调整命令','0');
            AllExtension[iDExtension].OverCount:=0;
            FlagSaved:=True;
          end
          else
          begin
            AllExtension[iDExtension].OverCount:=0;
            AllExtension[iDExtension].Adjusting:=False;
          end;
        end;
        end;
      end;
    end;
  end;
  end;

  if FlagSaved then
  begin
    SaveInterval:=0;
  end
  else
  begin
    for i:=0 to StateInfo.MaxExtensionCount-1 do
    begin
      if AllExtension[i].CommErr then exit; //如果存在通讯错误,不保存数据
        {With ExtensionState1[i] do
        begin
          Gravity:=AllExtension[i].Gravity;
          Height:=AllExtension[i].Height;
          State:=IntToStr(AllExtension[i].Flag);
          HorizonDiff:=AllExtension[i].HorizonDiff;
        end;}
    end;
    SaveInterval:=SaveInterval+1;
    if StateInfo.SystemState=ssNormal then
    begin
      if  SaveInterval>=120 then
      begin
        SaveData();
        SaveInterval:=0;
      end;
    end
    else
    begin
      if SaveInterval>=20 then
      begin
        SaveData();
        SaveInterval:=0;
      end;
    end;
  end;
end;

Function TfrmSendCommand.MustStop(iExtension:Byte):Boolean;
begin
  Result:=(AllExtension[iExtension].Gravity>(StandardG[iExtension].Value*StateInfo.UpperLimit16));
end;

Function TfrmSendCommand.MustAdjust(iExtension:Byte):Boolean;
begin
  Result:=(AllExtension[iExtension].Gravity>(StandardG[iExtension].Value*StateInfo.UpperLimit13)) and (AllExtension[iExtension].Gravity<(StandardG[iExtension].Value*StateInfo.UpperLimit16));
end;
Function TfrmSendCommand.DMustStop(iExtension:Byte):Boolean;
begin
  Result:=((AllExtension[iExtension].Gravity<(StandardG[iExtension].Value*StateInfo.LowLimit04)));
end;

Function TfrmSendCommand.DMustAdjust(iExtension:Byte):Boolean;
begin
  Result:=((AllExtension[iExtension].Gravity<(StandardG[iExtension].Value*StateInfo.LowLimit07)) and (AllExtension[iExtension].Gravity>(StandardG[iExtension].Value*StateInfo.LowLimit04)));
end;

procedure TfrmSendCommand.ComPortAfterClose(Sender: TObject);
begin
  LabelOpen.Caption := '断开';
end;

procedure TfrmSendCommand.ComPortAfterOpen(Sender: TObject);
begin
  LabelOpen.Caption := '开启';
end;

procedure TfrmSendCommand.TreeViewSelectChange(Sender: TObject;
  Node: TTreeNode);
begin
  Node.SelectedIndex:=Node.ImageIndex;
end;

procedure TfrmSendCommand.CheckBoxIQClick(Sender: TObject);
begin
  if not CheckBoxIQ.Checked then
  begin
    ShowMessage('取消该功能,升降架将无法实现自动调节!');
    RadioButtonGravity.Enabled:=False;
    RadioButtonHeight.Enabled:=False;
  end
  else
  begin
    RadioButtonGravity.Enabled:=True;
    RadioButtonHeight.Enabled:=True;
  end;
end;

procedure TfrmSendCommand.SpeedButton1Click(Sender: TObject);
var i:integer;
begin
  MemoStatus.Clear;
  MemoStatus.Color:=clBlue;
  for i:=0 to StateInfo.MaxExtensionCount-1 do
  begin
    if AllExtension[i].CommErr then
      DisplayInfo('分机'+AllExtension[i].ExtensionID+'不在位','1');
  end;
end;

end.

⌨️ 快捷键说明

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