unit LmtData;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,GTFunc,GlobalVar;

type
  TLmitDlg = class(TForm)
    Axis1Limit: TRadioGroup;
    Axis2Limit: TRadioGroup;
    Axis3Limit: TRadioGroup;
    LLmitSns: TLabel;
    ELimtVal: TEdit;
    BEnter: TButton;
    procedure Axis1LimitClick(Sender: TObject);
    procedure Axis2LimitClick(Sender: TObject);
    procedure Axis3LimitClick(Sender: TObject);
    procedure ELimtValExit(Sender: TObject);
    procedure ELimtValKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    SelectNo:Integer;
    bFirEnter:Boolean;
    { Public declarations }
  end;

var
  LmitDlg: TLmitDlg;

implementation

{$R *.dfm}

procedure TLmitDlg.Axis1LimitClick(Sender: TObject);
begin
  if bFirEnter then
  begin
     exit;
  end;

  if SelectNo=0 then
  begin
    if (Axis1Limit.ItemIndex=0) then
    begin
       rtn:=GT_LmtsOn(1);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_LmtsOn',1);
    end
    else
    begin
       rtn:=GT_LmtsOff(1);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_LmtsOff',1);
    end;
    if rtn=0 then
      Limit1Sts:=Axis1Limit.ItemIndex
  end
  else if SelectNo=1 then begin
    if (Axis1Limit.ItemIndex=0) then
    begin
       rtn:=GT_AxisOff(1);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AxisOff',1);
    end
    else
    begin
       rtn:=GT_AxisOn(1);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AxisOn',1);
    end;
    if rtn=0 then
      Ctrl1Sts:=Axis1Limit.ItemIndex;
  end
  else if SelectNo=2 then begin
    if (Axis1Limit.ItemIndex=0) then
    begin
       rtn:=GT_StepDir(1);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_StepDir',1);
    end
    else
    begin
       rtn:=GT_StepPulse(1);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_StepPulse',1);
    end;
    if rtn=0 then
      Step1Mod:=Axis1Limit.ItemIndex;
  end
  else  if SelectNo=3 then begin
    if (Axis1Limit.ItemIndex=0) then
    begin
       rtn:=GT_AlarmOff(1);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AlarmOff',1);
    end
    else
    begin
       rtn:=GT_AlarmOn(1);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AlarmOn',1);
    end;
    if rtn=0 then
      Alarm1Sts:=Axis1Limit.ItemIndex;
  end;
end;

procedure TLmitDlg.Axis2LimitClick(Sender: TObject);
begin
  if bFirEnter then
  begin
     if rtn<>0 then   bFirEnter:=false;
     rtn:=0;
     exit;
  end;

  if SelectNo=0 then
  begin
    if (Axis2Limit.ItemIndex=0) then
    begin
       rtn:=GT_LmtsOn(2);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_LmtsOn',2);
    end
    else
    begin
       rtn:=GT_LmtsOff(2);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_LmtsOff',2);
    end;
    if rtn=0 then
      Limit2Sts:=Axis2Limit.ItemIndex;

  end
  else if SelectNo=1 then begin
    if (Axis2Limit.ItemIndex=0) then
    begin
       rtn:=GT_AxisOff(2);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AxisOff',2);
    end
    else
    begin
       rtn:=GT_AxisOn(2);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AxisOn',2);
    end;
    if rtn=0 then
      Ctrl2Sts:=Axis2Limit.ItemIndex;
  end
  else if SelectNo=2 then begin
    if (Axis2Limit.ItemIndex=0) then
    begin
       rtn:=GT_StepDir(2);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_StepDir',2);
    end
    else
    begin
       rtn:=GT_StepPulse(2);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_StepPulse',2);
    end;
    if rtn=0 then
      Step2Mod:=Axis2Limit.ItemIndex;
  end
  else  if SelectNo=3 then begin
    if (Axis2Limit.ItemIndex=0) then
    begin
       rtn:=GT_AlarmOff(2);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AlarmOff',2);
    end
    else
    begin
       rtn:=GT_AlarmOn(2);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AlarmOn',2);
    end;
    if rtn=0 then
      Alarm2Sts:=Axis2Limit.ItemIndex;
  end;

end;

procedure TLmitDlg.Axis3LimitClick(Sender: TObject);
begin
  if bFirEnter then
  begin
     if rtn<>0 then   bFirEnter:=false;
     rtn:=0;
     exit;
  end;

  if SelectNo=0 then
  begin
    if (Axis3Limit.ItemIndex=0) then
    begin
       rtn:=GT_LmtsOn(3);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_LmtsOn',3);
    end
    else
    begin
       rtn:=GT_LmtsOff(3);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_LmtsOff',3);
    end;
    if rtn=0 then
      Limit3Sts:=Axis3Limit.ItemIndex;
  end
  else  if SelectNo=1 then begin
    if (Axis3Limit.ItemIndex=0) then
    begin
       rtn:=GT_AxisOff(3);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AxisOff',3);
    end
    else
    begin
       rtn:=GT_AxisOn(3);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AxisOn',3);
    end;
    if rtn=0 then
      Ctrl3Sts:=Axis3Limit.ItemIndex;
  end
  else if SelectNo=2 then begin
    if (Axis3Limit.ItemIndex=0) then
    begin
       rtn:=GT_StepDir(3);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_StepDir',3);
    end
    else
    begin
       rtn:=GT_StepPulse(3);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_StepPulse',3);
    end;
    if rtn=0 then
      Step3Mod:=Axis3Limit.ItemIndex;
  end
  else  if SelectNo=3 then begin
    if (Axis3Limit.ItemIndex=0) then
    begin
       rtn:=GT_AlarmOff(3);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AlarmOff',3);
    end
    else
    begin
       rtn:=GT_AlarmOn(3);
       ShowErrorMsg(rtn);
       ShowResult(rtn,'GT_AlarmOn',3);
    end;
    if rtn=0 then
      Alarm3Sts:=Axis3Limit.ItemIndex;
  end;
end;

procedure TLmitDlg.ELimtValExit(Sender: TObject);
begin
   if (ELimtVal.Text='') or (StrToInt(ELimtVal.Text)>255) or (StrToInt(ELimtVal.Text)<0)  then
   begin
       if lang=1 then
         ShowMessage('输入值超过范围，重新输入')
       else
         ShowMessage('error input，please reinput');
       ELimtVal.SetFocus();
       exit;
   end;
   LmtVal:=StrToInt(ELimtVal.Text);
   rtn:=GT_LmtSns(LmtVal);
   ShowErrorMsg(rtn);
   ShowResult(rtn,'GT_LmtSns',LmtVal);
end;

procedure TLmitDlg.ELimtValKeyPress(Sender: TObject; var Key: Char);
begin
   if not (key in DigitsSet) then
   begin
       key:=#0;
       exit;
   end;
end;

procedure TLmitDlg.FormShow(Sender: TObject);
begin
   if lang=1 then    BEnter.Caption:='确定(&o)'
   else   BEnter.Caption:='Confirm(&o)';

   bFirEnter:=true;
   rtn:=0;
   if SelectNo=0 then
   begin
      ELimtVal.Text:=IntToStr(LmtVal);
      ElimtVal.Visible:=true;
      LLmitSns.Visible:=true;
      Axis1Limit.ItemIndex:=Limit1Sts;
      Axis2Limit.ItemIndex:=Limit2Sts;
      Axis3Limit.ItemIndex:=Limit3Sts;

      if lang=1 then
      begin
         caption:='设置限位电平';
         Axis1Limit.Caption:='轴1 限位开关状态';
         Axis1Limit.Items[0]:='限位开关有效';
         Axis1Limit.Items[1]:='限位开关无效';
         Axis2Limit.Caption:='轴2 限位开关状态';
         Axis2Limit.Items[0]:='限位开关有效';
         Axis2Limit.Items[1]:='限位开关无效';
         Axis3Limit.Caption:='轴3 限位开关状态';
         Axis3Limit.Items[0]:='限位开关有效';
         Axis3Limit.Items[1]:='限位开关无效';
         LLmitSns.Caption:='限位开关的有效电平：';
      end
      else begin
         LLmitSns.Caption:='limit switch triger';
         caption:='set limit level';
         Axis1Limit.Caption:='Axis 1 Limit Status';
         Axis1Limit.Items[0]:='Limit On';
         Axis1Limit.Items[1]:='Limit Off';
         Axis2Limit.Caption:='Axis 2 Limit Status';
         Axis2Limit.Items[0]:='Limit On';
         Axis2Limit.Items[1]:='Limit Off';
         Axis3Limit.Caption:='Axis 3 Limit Status';
         Axis3Limit.Items[0]:='Limit On';
         Axis3Limit.Items[1]:='Limit Off';
      end;
   end
   else if SelectNo=1 then begin
      ElimtVal.Visible:=false;
      LLmitSns.Visible:=false;
      Axis1Limit.ItemIndex:=Ctrl1Sts;
      Axis2Limit.ItemIndex:=Ctrl2Sts;
      Axis3Limit.ItemIndex:=Ctrl3Sts;
      if lang=1 then
      begin
         caption:='轴控制状态';
         Axis1Limit.Caption:='轴1 控制状态';
         Axis1Limit.Items[0]:='关闭驱动使能';
         Axis1Limit.Items[1]:='驱动使能';
         Axis2Limit.Caption:='轴2 控制状态';
         Axis2Limit.Items[0]:='关闭驱动使能';
         Axis2Limit.Items[1]:='驱动使能';
         Axis3Limit.Caption:='轴3 控制状态';
         Axis3Limit.Items[0]:='关闭驱动使能';
         Axis3Limit.Items[1]:='驱动使能';
      end
      else begin
         caption:='Axis Contol Status';
         Axis1Limit.Caption:='Axis 1 Control Status';
         Axis1Limit.Items[0]:='Axis Off';
         Axis1Limit.Items[1]:='Axis On';
         Axis2Limit.Caption:='Axis 2 Control Status';
         Axis2Limit.Items[0]:='Axis Off';
         Axis2Limit.Items[1]:='Axis On';
         Axis3Limit.Caption:='Axis 3 Control Status';
         Axis3Limit.Items[0]:='Axis Off';
         Axis3Limit.Items[1]:='Axis On';
      end;
   end
   else if SelectNo=2 then begin
      ElimtVal.Visible:=false;
      LLmitSns.Visible:=false;
      Axis1Limit.ItemIndex:=Step1Mod;
      Axis2Limit.ItemIndex:=Step1Mod;
      Axis3Limit.ItemIndex:=Step1Mod;
      if lang=1 then
      begin
         caption:='设置轴控制输出模式';
         Axis1Limit.Caption:='轴1 控制输出模式';
         Axis1Limit.Items[0]:='方向＋脉冲';
         Axis1Limit.Items[1]:='正负脉冲';
         Axis2Limit.Caption:='轴2 控制输出模式';
         Axis2Limit.Items[0]:='方向＋脉冲';
         Axis2Limit.Items[1]:='正负脉冲';
         Axis3Limit.Caption:='轴3 控制输出模式';
         Axis3Limit.Items[0]:='方向＋脉冲';
         Axis3Limit.Items[1]:='正负脉冲';
      end
      else begin
         caption:='Set Axis Control Output Mode';
         Axis1Limit.Caption:='Axis 1 Control Output Mode';
         Axis1Limit.Items[0]:='Dir + Pulse';
         Axis1Limit.Items[1]:='+Pulse/-Pulse';
         Axis2Limit.Caption:='Axis 2 Control Output Mode';
         Axis2Limit.Items[0]:='Dir + Pulse';
         Axis2Limit.Items[1]:='+Pulse/-Pulse';
         Axis3Limit.Caption:='Axis 3 Control Output Mode';
         Axis3Limit.Items[0]:='Dir + Pulse';
         Axis3Limit.Items[1]:='+Pulse/-Pulse';
      end;
   end
   else if SelectNo=3 then begin
      ElimtVal.Visible:=false;
      LLmitSns.Visible:=false;
      Axis1Limit.ItemIndex:=Alarm1Sts;
      Axis2Limit.ItemIndex:=Alarm2Sts;
      Axis3Limit.ItemIndex:=Alarm3Sts;
      if lang=1 then
      begin
         caption:='设置轴报警状态';
         Axis1Limit.Caption:='轴1 报警开关';
         Axis1Limit.Items[0]:='关闭报警';
         Axis1Limit.Items[1]:='打开报警';
         Axis2Limit.Caption:='轴2 报警开关';
         Axis2Limit.Items[0]:='关闭报警';
         Axis2Limit.Items[1]:='打开报警';
         Axis3Limit.Caption:='轴3 报警开关';
         Axis3Limit.Items[0]:='关闭报警';
         Axis3Limit.Items[1]:='打开报警';
      end
      else begin
         caption:='Set Axis Alarm Status';
         Axis1Limit.Caption:='Axis 1 Alarm Status';
         Axis1Limit.Items[0]:='Alarm Off';
         Axis1Limit.Items[1]:='Alarm On';
         Axis2Limit.Caption:='Axis 2 Alarm Status';
         Axis2Limit.Items[0]:='Alarm Off';
         Axis2Limit.Items[1]:='Alarm On';
         Axis3Limit.Caption:='Axis 3 Alarm Status';
         Axis3Limit.Items[0]:='Alarm Off';
         Axis3Limit.Items[1]:='Alarm On';
      end;
   end;
   bFirEnter:=false;   
end;

end.

