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

📄 sendcommand.pas

📁 这是一个正式的项目工程
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  end;

end;

procedure TfrmSendCommand.StartSampling(i:Integer);
begin
  if (SamplingThread = nil) or (SamplingThreadActive = false) then   // make sure its not already running
  begin
    if SamplingThread=nil then FirstSamplingEnd:=False;
    SamplingThread := TSamplingThread.CreateIt(3);
    SamplingThreadActive := True;
  end;
end;

Procedure TfrmSendCommand.InitializeFlag();
var
  i   :Integer;
begin
  for i:=0 to MaxExtensionCount-1 do
    AllExtension[i].Flag:=0;
end;

procedure TfrmSendCommand.StartProgress(i:Integer);
begin
  PanelProgress.Visible:=True;
  MHeight:=i;
  ThreadHeight:=0;
  if (GaugeThread = nil) or (GaugeThreadActive = false) then   // make sure its not already running
  begin
    GaugeThread := TGaugeThread.CreateIt(5, i,GaugeProgress);
    GaugeThreadActive := true;
  end;
end;

procedure TfrmSendCommand.StopSampling();
begin
  if (SamplingThread <> nil) and (SamplingThreadActive = True) then  // check to see if it is running
  begin
    SamplingThreadActive:=False;
    //test
    frmSendCommand.LabelCommErr.Visible:=True;
    LabelCommErr.Caption:=frmSendCommand.LabelCommErr.Caption+'StopSampling';
    //test
    SamplingThread.Terminate;
//    SamplingThread.Free;

    SamplingThread.WaitFor;
  end;
end;

procedure TfrmSendCommand.StopProgress();
begin
  PanelProgress.Visible:=False;
  if (GaugeThread <> nil) and (GaugeThreadActive = true) then  // check to see if it is running
  begin
    GaugeThread.Terminate;
    GaugeThread.WaitFor;
    ThreadHeight:=0;
    GaugeThreadActive:=False;
  end;
end;

procedure TfrmSendCommand.SetProgress(i:Integer);
begin
  ThreadHeight:=i;
end;

procedure TfrmSendCommand.PauseSampling();
begin
//  SamplingThread.Terminate;
//  SamplingThread.WaitFor;
  {While True do
  begin

    if not bSampling then
    begin  }
      SamplingThread.Suspend;
      Sleep(100);
{      bSampling:=False;

      Break;
    end;

  end;}
end;

procedure TfrmSendCommand.ResumeSampling();
begin
  SamplingThread.Resume;
{  if (SamplingThread = nil) or (SamplingThreadActive = false) then
  begin
    SamplingThread := TSamplingThread.CreateIt(3);
    SamplingThreadActive := True;
  end;
}
end;

procedure TfrmSendCommand.ActionClearAllExecute(Sender: TObject);
begin
  ListBoxSelect.Clear;
end;

procedure TfrmSendCommand.ActionClearSelectExecute(Sender: TObject);
var
  i,j:Integer;
  iSelectCount:Integer;
begin
  iSelectCount:=ListBoxSelect.SelCount;
  For j:=0 to iSelectCount do
  begin
    for i:=0 to ListBoxSelect.Items.Count-1 do
    begin
      if ListBoxSelect.Selected[i] then
      begin
        ListBoxSelect.Items.Delete(i);
        Break;
      end;
    end;
  end;
end;

procedure TfrmSendCommand.ActionRightExecute(Sender: TObject);
var
  SelectedNode,SecondLayer,ThirdLayer :TTreeNode;
begin
  SelectedNode:=TreeViewSelect.Selected;
  Case SelectedNode.Level of
  0:
    Begin
      SecondLayer:=SelectedNode.getFirstChild;
      While SecondLayer<>nil do
      begin
        ThirdLayer:=SecondLayer.getFirstChild;
        while ThirdLayer<>nil do
        begin
          AppendExtension(ThirdLayer.Text);
          ThirdLayer:=ThirdLayer.getNextSibling;
        end;
        SecondLayer:=SecondLayer.getNextSibling;
      end;
    end;
  1:
    Begin
      ThirdLayer:=SelectedNode.getFirstChild;
      While ThirdLayer<>nil do
      begin
        AppendExtension(ThirdLayer.Text);
        ThirdLayer:=ThirdLayer.getNextSibling;
      end;
    end;
  2:
    Begin
      AppendExtension(SelectedNode.Text);
    end;
  end;
end;

procedure TfrmSendCommand.FormDestroy(Sender: TObject);
begin
  StopProgress;
  StopSampling;
  TimerAutoCountrol.Enabled:=False;
//  TimerSample.Enabled:=False;
  if ComPort.Connected then
    ComPort.Close;
  with dmMainDB  do
  begin
    if ViewProjectID.State<>dsInactive then
      ViewProjectID.Close;
    if ViewPH.State<>dsInactive then
      ViewPH.Close;
    if ViewGroupID.State<>dsInactive then
      ViewGroupID.Close;
    if ViewExtensionID.State<>dsInactive then
      ViewExtensionID.Close;
    if ViewGEMaster.State<>dsInactive then
      ViewGEMaster.Close;
    if ViewGEDetail.State<>dsInactive then
      ViewGEDetail.Close;
    if tbOriginData.State=dsInactive then
      tbOriginData.Close;
    qryPublic.Close;
  end;
end;

procedure TfrmSendCommand.ActionStopExecute(Sender: TObject);
begin
 try
   PauseSampling;
   try
     SendStopCommand();
   except
   end;
 finally
   DisplayInfo('发送停机命令','0');
   StopProgress;
   ResumeSampling;
   LogInfo.UserName:=UserInfo.UserName;
   Loginfo.Operation:=OperationType[6];
   Loginfo.DDate:=Date();
   Loginfo.DTime:=Time();
   Loginfo.Remark:='success';
   WriteLog(dmMainDB.qryPublic,LogInfo);
 end;
end;

procedure TfrmSendCommand.MaskEditHeightChange(Sender: TObject);
begin
  SpinEditHeight.Text:=StringReplace(SpinEditHeight.Text,' ','',[rfReplaceAll]);
  if trim(SPinEditHeight.Text)<>'' then
    StateInfo.Height:=StrToInt(Trim(SpinEditHeight.Text))
  else
    StateInfo.Height:=0;
end;

procedure TfrmSendCommand.RadioGroupOperationClick(Sender: TObject);
begin
  DisplayState(RadioGroupOperation.ItemIndex);
end;

procedure TfrmSendCommand.DisplayState(i:Integer);
begin
  Case i of
    0: LabelProgress.Caption:='提升准备进度';
    1: LabelProgress.Caption:='直接提升进度';
    2: LabelProgress.Caption:='吊点上移进度';
    3: LabelProgress.Caption:='下降准备进度';
    4: LabelProgress.Caption:='直接下降进度';
    5: LabelProgress.Caption:='吊点下移进度';
    6: LabelProgress.Caption:='分机卸载进度';
  end;
end;

Procedure TfrmSendCommand.DisplayInfo(StatusInfo:String;StatusID:String);
begin
  if StatusID='0' then
    MemoStatus.Color:=clBlue
  else
    MemoStatus.Color:=clRed;
  if MemoStatus.Lines.Count>=MaxLineCount then
  begin
    MemoStatus.Lines.Delete(0);
  end;
  MemoStatus.Lines.Add(StatusInfo+' '+TimeToStr(Time()));
end;

{procedure TfrmSendCommand.TimerSampleTimer(Sender: TObject);
var
  i:Integer;
begin
  for i:=0 to StateInfo.MaxExtensionCount-1 do
  begin
    if AllExtension[i].CommErr=1 then exit; //如果存在通讯错误,不保存数据
      With ExtensionState1[i] do
      begin
        Gravity:=AllExtension[i].Gravity;
        Height:=AllExtension[i].Height;
        State:=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>=2 then
    begin
      SaveData();
      SaveInterval:=0;
    end;
  end;
end;}

function TfrmSendCommand.ExtensionPrepareFinish(ExtensionGroup:TCurrentOperationExtension):Boolean;
var i,j,count:integer;
begin
  Result:=False;
  j:=ExtensionGroup[0];
  count:=0;
  for i:=1 to j do
  begin
    if AllExtension[ExtensionGroup[i]].Flag=$52 then
    begin
      AllExtension[ExtensionGroup[i]].Status:=ssNormal;
      count:=count+1;
    end;
  end;
  if count=j then Result:=True;
end;

function TfrmSendCommand.ExtensionDownloadFinish(ExtensionGroup:TCurrentOperationExtension):Boolean;
var i,j,count:integer;
begin
  Result:=False;
  j:=ExtensionGroup[0];
  count:=0;
  for i:=1 to j do
  begin
    if AllExtension[ExtensionGroup[i]].Flag=$72 then
    begin
      AllExtension[ExtensionGroup[i]].Status:=ssNormal;
      count:=count+1;
    end;
  end;
  if count=j then Result:=True;
end;

function TfrmSendCommand.IsExtensionReset(ExtensionGroup:TCurrentOperationExtension):Boolean;
var i,j:integer;
begin
  Result:=False;
  j:=ExtensionGroup[0];
  for i:=1 to j do
  begin
    if AllExtension[ExtensionGroup[i]].FirstComm and (AllExtension[ExtensionGroup[i]].Flag=$FF) then
    begin
    Result:=True;
    DisplayInfo('分机'+AllExtension[ExtensionGroup[i]].ExtensionID+'复位','1');
    end;
  end;
end;

function TfrmSendCommand.ExtensionNotFinish(ExtensionGroup:TCurrentOperationExtension):string;
var i,j,c:integer;
begin
  Result:='';
  j:=ExtensionGroup[0];
  c:=0;
  for i:=1 to j do
  begin
    if AllExtension[ExtensionGroup[i]].Status<>ssNormal then
      begin
        c:=c+1;
        if c>1 then Result:=Result+'、';
        Result:=Result+AllExtension[ExtensionGroup[i]].ExtensionID;
      end;
  end;
end;

procedure TfrmSendCommand.ErrorAnalysis(Status:TSystemState);
var i:integer;
    ErrorExtensions:string;
begin
  ErrorExtensions:='';
  case status of
  ssAscend:
    begin
      for i:=0 to StateInfo.CurrentExtensionCount-1 do
      begin
        if AllExtension[i].Gravity>StandardG[i].Value*StateInfo.UpperLimit16 then
          ErrorExtensions:=ErrorExtensions+AllExtension[i].ExtensionID+' ';
      end;
      ShowErrorReport('分机'+ErrorExtensions+'在上升过程中遇到障碍,请排除故障后再试!');
    end;
  ssDescend:
    begin
      for i:=0 to StateInfo.CurrentExtensionCount-1 do
      begin
        if AllExtension[i].Gravity<StandardG[i].Value*StateInfo.LowLimit04 then
          ErrorExtensions:=ErrorExtensions+AllExtension[i].ExtensionID+' ';
      end;
      ShowErrorReport('分机'+ErrorExtensions+'在下降过程中遇到障碍,请排除故障后再试!');
    end;
  end;
end;

procedure TfrmSendCommand.TimerAutoCountrolTimer(Sender: TObject);
var
  i,iExtension,iDExtension  :Integer;
  MaxMinExtension :TMaxMinExtension;
  FlagSaved:Boolean;
  FlagNotPresent:Boolean;
  Str:string;
begin
  FlagSaved:=False;
  FlagNotPresent:=False;
  for i:=0 to StateInfo.MaxExtensionCount-1 do
  begin
    if AllExtension[i].CommErr then
    begin
      FlagNotPresent:=True;
      //DisplayNo(AllExtension[i].ExtensionID,False);
      //DisplayInfo('分机'+AllExtension[i].ExtensionID+'不在位');
    end
    else
    begin if FirstSamplingEnd then
      begin
        DisplayNo(AllExtension[i].ExtensionID,True);
      end;
    end;
  end;

  if MemoStatus.Color=clRed then
  begin
    if not FlagNotPresent then MemoStatus.Color:=clBlue;
  end;

  if (StateInfo.SystemState<>ssNormal) then
  begin
    if FlagNotPresent and CheckBoxIQ.Checked then
    begin
      PauseSampling;
      SendStopCommand();
      ResumeSampling;
      DisplayInfo('分机不在位,强制停机','1');
      StopProgress();
    end
    else
    begin
      if IsExtensionReset(StateInfo.CurrentOperateExtension) then
      begin
        PauseSampling;
        SendStopCommand();
        ResumeSampling;
        DisplayInfo('分机复位,强制停机','1');
        StopProgress();
      end;
    end;
  end;

  case StateInfo.SystemState of

⌨️ 快捷键说明

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