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

📄 sendcommand.pas

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

Function  TfrmSendCommand.IsExtensionExist(ExtensionID:String):Boolean;
var
  i :Integer;
begin
  Result:=False;
  if ListBoxSelect.Items.Count<=0 then
  begin
    Result:=False;
  end
  else
  begin
    for i:=0 to ListBoxSelect.Items.Count-1 do
    begin
      if ExtensionID=GetID(ListBoxSelect.Items.Strings[i]) then
      begin
        Result:=True;
        Break;
      end;
    end;
  end;
end;

Procedure TfrmSendCommand.SendACommand(RawCommand:TRawCommand);
var
  SendPacket:TSendPacket;
  CommID:integer;
  MultiCount,i:integer;
  ClearPacket:array[0..1] of byte;
begin
  ClearPacket[0]:=10;
  ClearPacket[1]:=10;
  CommID:=StrToInt(RawCommand.CommandID);
  SendPacket:=FormSendData(RawCommand);
  with ComPort do
  begin
    BeginUpDate;
    Parity.Check:=False;
    Parity.Bits:=prSpace;
    EndUpdate;
    Write(ClearPacket[0],1);
    Write(ClearPacket[1],1);
    MultiCount:=SendPacket[0];
    Sleep(3);
    BeginUpDate;
    Parity.Bits:=prMark;
    EndUpdate;
    for i:=1 to MultiCount do
    begin
      Write(SendPacket[i],1);
    end;
    Sleep(3);
    BeginUpdate;
    Parity.Bits:=prSpace;
    EndUpdate;
    Write(SendPacket[MultiCount+1],1);
    Write(SendPacket[MultiCount+2],1);
  end;
  case CommID of
    1,3,6:StateInfo.HeightAcc:=0;
    2,4,5,8:StateInfo.HeightAcc:=1;
  end;
  if (CommID<>0) and (CommID<>7) and (CommID<>9) then
    begin
    StateInfo.CurrentOperateExtension[0]:=MultiCount;
    for i:=1 to MultiCount+2 do
      StateInfo.CurrentOperateExtension[i]:=SendPacket[i];
    end;
end;

Function TfrmSendCommand.NameToID(strName:String):String;
begin
  Result:=Copy(strName,Length(StrName)-6,6);
end;

procedure TfrmSendCommand.FormCreate(Sender: TObject);
var
  i:Integer;
begin
  try
  with frmSendCommand do
  begin
    Top:=1;
    left:=1;
    Height:=450;
    Width:=570;
  end;
  Except

  end;
  try
    ComPort.LoadSettings(stRegistry, 'HKEY_LOCAL_MACHINE\Software\深圳特辰实业有限公司\特辰2000升降架自动控制系统\Setting');
  except
    ComPort.StoreSettings(stRegistry, 'HKEY_LOCAL_MACHINE\Software\深圳特辰实业有限公司\特辰2000升降架自动控制系统\Setting');
  end;
  Event := TEvent.Create(nil, True, False, '');
  ComPort.Events := [];
  if not ComPort.Connected then
    ComPort.Open;
  Events := [evRxChar];

//  SetConsoleCtrlHandler(@CtrlHandler, True);

  PanelProgress.Visible:=False;
  SaveInterval:=0;
  HHeight:=0;
  CurrentExtensionID:=0;
  with StateInfo do
  begin
    SystemState:=ssNormal;
    MaxValue:=0;
    Height:=0;
    MaxHeight:=5999;
    HeightAcc:=0;
  end;
  with dmMainDB  do
  begin
    if ViewProjectID.State=dsInactive then
      ViewProjectID.Open
    else
      ViewProjectID.First;
    if ViewPH.State=dsInactive then
      ViewPH.Open
    else
      ViewPH.First;
    if ViewGroupID.State=dsInactive then
      ViewGroupID.Open
    else
      ViewGroupID.First;
    if ViewExtensionID.State=dsInactive then
      ViewExtensionID.Open
    else
      ViewExtensionID.First;
    if ViewGEMaster.State=dsInactive then
      ViewGEMaster.Open
    else
      ViewGEMaster.First;
    if ViewGEDetail.State=dsInactive then
      ViewGEDetail.Open
    else
      ViewGEDetail.First;
    if tbOriginData.State=dsInactive then
      tbOriginData.Open
    else
      tbOriginData.Last;
 end;

 PanelFirst.Align:=alClient;
 PanelSecond.Align:=alClient;
 PanelFirst.Visible:=True;
 PanelSecond.Visible:=False;
 IsQuery:=False;
 LabelHourse.Caption:='';
 LabelProject.Caption:='';
 RadioGroupSelect.ItemIndex:=0;

 with dmMainDB.ViewProjectID  do
 begin
   if State=dsInactive then
      Open
   else
      First;
   try
     ListBoxProject.Items.BeginUpdate;
     ListBoxProject.Items.Clear;
     While Not Eof do
     begin
       ListBoxProject.Items.Append(FieldByName('CodeMeaning').AsString+' ['+FieldByName('ACode').AsString+']');
       Next;
     end;
     if ListBoxProject.Items.Count<>0 then
     begin
       ListBoxProject.ItemIndex:=0;
       LabelProject.Caption:=ListBoxProject.Items.Strings[ListBoxProject.ItemIndex];

     end;
   finally

     ListBoxProject.Items.EndUpdate;
   end;
 end;
 dmMainDB.ViewProjectID.First;
 ListBoxHourse.Items.Clear;
 with dmMainDB.ViewPH do
 begin
   First;
   While Not Eof do
   begin
     ListBoxHourse.Items.Append(FieldByName('HourseIDLookup').AsString+' ['+FieldByName('HourseID').AsString+']');
     Next;
   end;
 end;
 for i:=0 to MaxExtensionCount-1 do
 begin
   AllExtension[i].GroupID:='';
   AllExtension[i].ExtensionID:='';
   AllExtension[i].Flag:=0;
 end;
 StateInfo.CurrentExtensionCount:=0;
end;

procedure TfrmSendCommand.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=caFree;
end;

procedure TfrmSendCommand.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if IsQuery then
  begin
    CanClose:=IsPasswordCorrect(AppInfo,UserInfo);
    if CanClose then
    begin
      StopProgress;
      StopSampling;
      SaveData;
    end;
  end
  else
  begin
    CanClose:=True;
  end;
end;

{procedure TfrmSendCommand.ActionReverseExecute(Sender: TObject);
var
  i:Integer;
begin
  if IsPasswordCorrect(AppInfo,UserInfo) then
  begin
  Try
    PauseSampling;
  try
    if RadioGroupSelect.ItemIndex=0 then
    begin
      for i:=0 to ListBoxSelect.Items.Count-1 do
      begin
        SendReverseCommand(GetID(ListBoxSelect.Items.Strings[i]));
      end;
    end
    else
    begin
      for i:=0 to ListBoxSelect.Items.Count-1 do
      begin
        if ListBoxSelect.Selected[i] then
        begin
          SendReverseCommand(GetID(ListBoxSelect.Items.Strings[i]));
        end;
      end;
    end;
  finally
    LogInfo.UserName:=UserInfo.UserName;
    Loginfo.Operation:=OperationType[8];
    Loginfo.DDate:=Date();
    Loginfo.DTime:=Time();
    Loginfo.Remark:='success';
    WriteLog(dmMainDB.qryPublic,LogInfo);
  end;
  finally
    ResumeSampling;
  end;

  end;
end;}

procedure TfrmSendCommand.ActionSetupExecute(Sender: TObject);
begin
  Application.CreateForm(TfrmStandardGravity, frmStandardGravity);
  frmStandardGravity.ShowModal;
end;



{procedure TfrmSendCommand.ComDataPacketPacket(Sender: TObject;
  const Str: String);
var
  i:Integer;
begin
  DataPacket:=DataParse(Str);
  With ExtensionState1[StrToInt(DataPacket.ExtensionID)] do
  begin
    Gravity:=DataPacket.Gravity;
    Height:=DataPacket.Height;
    State:=DataPacket.State;
  end;
  With AllExtension[StrToInt(DataPacket.ExtensionID)] do
  begin
    Gravity:=DataPacket.Gravity;
    Height:=DataPacket.Height;
    Flag:=DataPacket.State;
  end;
  CalcAverage();
  for i:=0 to MaxExtensionCount-1 do
  begin
    if AllExtension[i].ExtensionID<>'' then
    begin
      ExtensionState1[i].HorizonDiff:=AllExtension[i].HorizonDiff;
    end;
  end;
end;
}

procedure TfrmSendCommand.ActionOKExecute(Sender: TObject);     //选择项目
var
  RootNode,CurrentNode,LastLayerNode:TTreeNode;
  iSeq,iRow,i:Integer;
begin
  With frmSendCommand do
  begin
    Caption:='向下位机发送控制命令';
    //WindowState:=wsMaximized;
  end;
  StateInfo.MaxExtensionCount:=0;
  StateInfo.CurrentGroupCount:=0;
  StateInfo.CurrentOperateExtension[0]:=0;
  PanelFirst.Visible:=False;
  PanelSecond.Visible:=True;
  Width:=540;
  IsQuery:=True;
  ProjectInfo.ProjectName:=GetName(LabelProject.Caption);
  ProjectInfo.ProjectID:=GetID(LabelProject.Caption);
  ProjectInfo.HourseName:=GetName(LabelHourse.Caption);
  ProjectInfo.HourseID:=GetID(LabelHourse.Caption);
  GProjectInfo:=ProjectInfo;
  LabelCurrentProject.Caption:=LabelProject.Caption;
  LabelCurrentHourse.Caption:=LabelHourse.Caption;
  RadioButtonGravity.Checked:=True;
  With dmMainDB.qryPublic do
  begin
    Close;
    SQL.Clear;
    SQL.Add('Select GroupID,Count(ExtensionID) ECount from ge');
    SQL.Add(' where ProjectID=:ProjectID and HourseID=:HourseID');
    SQL.Add(' Group by GroupID');
    ParamByName('ProjectID').AsString:=ProjectInfo.ProjectID;
    ParamByName('HourseID').AsString:=ProjectInfo.HourseID;
    Prepare;
    try
      Open;
    except
      ExecSQL;
    end;
    While not Eof do
    begin
      try
       iRow:=StrToInt(FieldByName('GroupID').AsString);
      except
       iRow:=0;
      end;
      StateInfo.CurrentGroupCount:=StateInfo.CurrentGroupCount+1;
      AllGroup[iRow].GroupID:=FieldByName('GroupID').AsString;
      AllGroup[iRow].ExtensionCount:=FieldByName('ECount').AsInteger;
      StateInfo.MaxExtensionCount:=StateInfo.MaxExtensionCount+AllGroup[iRow].ExtensionCount;
      AllGroup[iRow].Flag:='000';
      Next;
    end;
    Close;
  end;

  With dmMainDB do
  begin

    ViewGEMaster.Filter:='ProjectID='+''''+ProjectInfo.ProjectID+''''+' and HourseID='+''''+ProjectInfo.HourseID+'''';
    ViewGEMaster.Filtered:=True;
    try
      TreeViewSelect.Items.BeginUpdate;
      RootNode:=TreeViewSelect.Items.Add(nil,ProjectInfo.HourseName+' ['+ProjectInfo.HourseID+']');
      RootNode.ImageIndex:=0;
      RootNode.StateIndex:=1;
      RootNode.SelectedIndex:=3;

      while not ViewGEMaster.Eof do
      begin
        CurrentNode:=TreeViewSelect.Items.AddChild(RootNode,ViewGEMaster['GroupIDLookup']+' ['+ViewGEMaster['GroupID']+']');
        CurrentNode.ImageIndex:=0;
        CurrentNode.SelectedIndex:=3;
        ViewGEDetail.First;
        While not (ViewGEDetail.Eof) do
        begin
          LastLayerNode:=TreeViewSelect.Items.AddChild(CurrentNode,ViewGEDetail['ExtensionIDLookup']+' ['+ViewGEDetail['ExtensionID']+']');
          LastLayerNode.ImageIndex:=2;
          LastLayerNode.SelectedIndex:=3;
          iSeq:=StrToInt(ViewGEDetail['ExtensionID']);
          if (iSeq>MaxExtensionCount-1) then
             iSeq:=MaxExtensionCount-1;
          if (iSeq<0) then
             iSeq:=0;
          AllExtension[iSeq].GroupID:=ViewGEDetail['GroupID'];
          AllExtension[iSeq].ExtensionID:=ViewGEDetail['ExtensionID'];
          StateInfo.CurrentExtensionCount:=StateInfo.CurrentExtensionCount+1;
          ViewGEDetail.Next;
        end;
        ViewGEMaster.Next;
      end;
    finally
      TreeViewSelect.FullExpand;
      TreeViewSelect.Items.EndUpdate;
      ViewGEMaster.Close;
      ViewGEDetail.Close;
    end;
  end;
  ListBoxSelect.Clear;
  with dmMainDB do
  begin
    if tbStandardG.State=dsInactive then
    begin
      tbStandardG.Open;
    end
    else
    begin
      tbStandardG.First;
    end;
    tbStandardG.Filter:='HourseID='+''''+ProjectInfo.HourseID+'''';
    tbStandardG.Filtered:=True;
    tbStandardG.First;
    for i:=0 to MaxExtensionCount-1 do
    begin
      StandardG[i].ExtensionID:='';
      StandardG[i].Value:=0;
    end;
    i:=0;
    While not tbStandardG.Eof do

⌨️ 快捷键说明

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