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

📄 wbta_epi_io.pas

📁 System will automatically delete the directory of debug and release, so please do not put files on t
💻 PAS
字号:
unit WBTA_EPI_IO;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Buttons;

Const LF = #10;
      CR = #13;

type
  TEPI_IO_Form = class(TForm)
    GroupBox1: TGroupBox;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    Button1: TButton;
    GroupBox2: TGroupBox;
    Button2: TButton;
    GroupBox3: TGroupBox;
    StrobeBox: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    RadioButton6: TRadioButton;
    RadioButton7: TRadioButton;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    StaticText4: TStaticText;
    StaticText5: TStaticText;
    StaticText6: TStaticText;
    StaticText7: TStaticText;
    RadioButton8: TRadioButton;
    StaticText8: TStaticText;
    Panel1: TPanel;
    CheckBox8: TCheckBox;
    CheckBox10: TCheckBox;
    CheckBox9: TCheckBox;
    CheckBox11: TCheckBox;
    AllOutOFF: TButton;
    StrobesON: TButton;
    ReadInput: TButton;
    Button3: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure StobesONClick(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure AllOutOFFClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure ReadInputClick(Sender: TObject);
    Procedure GetEpiError;
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    Z79Step : integer;
    Z79Error : integer;
    ClearOutput : Boolean;
  public
    { Public declarations }
  end;

var
  EPI_IO_Form: TEPI_IO_Form;

implementation

uses WBTAUnit1, WBTA_Var, WBTA_32_IDX ;

{$R *.DFM}

procedure TEPI_IO_Form.FormCreate(Sender: TObject);
begin
  ClearOutput := False;
  Z79Step := 0;
  // set vertical text
//  SpeedButton1.Caption := 'R'+#13+'e'+#13+'a'#13+'d';
//  SpeedButton2.caption := 'O'+#13+'N';
//  SpeedButton3.Caption := 'O'+#13+'F'+#13+'F';

end;

procedure TEPI_IO_Form.StobesONClick(Sender: TObject);
begin  // switch to normal strobe operation
  RadioButton1.Checked := False;          //  RadioGroup1.ItemIndex := -1;
  RadioButton2.Checked := False;
  RadioButton3.Checked := False;
  RadioButton4.Checked := False;
  RadioButton5.Checked := False;
  RadioButton6.Checked := False;
  RadioButton7.Checked := False;
  RadioButton8.Checked := False;
  Form1.Comport1.WriteStr('Z90 9' + LF + CR);
  Sleep(300);
end;

procedure TEPI_IO_Form.RadioGroup1Click(Sender: TObject);
var Str : string;
begin
  Form1.Comport1.WriteStr('Z90 0' + LF + CR);   // disable normal strobing
  Sleep(100);
  Str := 'Z90 ' + IntToStr((sender as TRadioButton).Tag+1);
  Form1.Comport1.WriteStr(Str + LF + CR);
  Sleep(100);
end;

procedure TEPI_IO_Form.Button1Click(Sender: TObject);
begin
  StobesONClick(Sender);
  Form1.ComPort1.WriteStr('Z90 9 ' + CR);  // restart strobes
  Sleep(200);
  Form1.ComPort1.ClearBuffer(True, True);
end;

procedure TEPI_IO_Form.CheckBox1Click(Sender: TObject);
var Tag : Integer;
    Str : string;
begin
  if ClearOutput then exit;
  Tag := (sender as TCheckBox).Tag;
  Str := 'Z' + IntToStr(Tag);
  If (sender as TCheckBox).Checked = True then
     Str := Str + ' 1'
  else
     Str := Str + ' 0';
  Form1.Comport1.WriteStr(Str + LF + CR);
  Sleep(300);
end;

procedure TEPI_IO_Form.AllOutOFFClick(Sender: TObject);
begin
 // some stupid programming
  ClearOutput := True;  // avoid problem with checkbox events
  CheckBox1.Checked := False;
  CheckBox2.Checked := False;
  CheckBox3.Checked := False;
  CheckBox4.Checked := False;
  CheckBox5.Checked := False;
  CheckBox6.Checked := False;
  CheckBox7.Checked := False;

  Form1.Comport1.WriteStr('Z91 0' + CR);
  Sleep(10);
  Form1.Comport1.WriteStr('Z92 0' + CR);
  Sleep(10);
  Form1.Comport1.WriteStr('Z93 0' + CR);
  Sleep(10);
  Form1.Comport1.WriteStr('Z94 0' + CR);
  Sleep(10);
  Form1.Comport1.WriteStr('Z95 0' + CR);
  Sleep(10);
  Form1.Comport1.WriteStr('Z96 0' + CR);
  Sleep(10);
  Form1.Comport1.WriteStr('Z97 0' + CR);
  Sleep(10);
  ClearOutput := False;
end;

procedure TEPI_IO_Form.FormShow(Sender: TObject);
begin
  EPI_IO_Form.Left := Form1.Left + (Form1.Width  - EPI_IO_Form.Width)  div 2;
  EPI_IO_Form.Top  := Form1.Top  + (Form1.Height - EPI_IO_Form.Height) div 2 + 20;
end;

procedure TEPI_IO_Form.Button3Click(Sender: TObject);
var Str : String;
      I : integer;
begin
  INC(Z79Step);
  case Z79Step of
     1 : begin
           Button3.Enabled := False;
           Button3.Caption := ' Next';
           Form1.ComPort1.WriteStr('Z90 0 ' + CR);
           application.processmessages;
           sleep(500);
           Label1.Caption := 'Switch to "Z79" position';
           Button3.Enabled := True;
         end;
     2 : begin
           Button3.Enabled := False;
           Form1.ComPort1.WriteStr('Z79 ' + CR);
           Sleep(600);
           Label1.Caption := 'Switch to "OFF" position';
           Button3.Enabled := True;
         end;
     3 : begin
           Label1.Caption := 'Read the test result ';
           Button3.Enabled := False;
           Label2.Caption := '';
           NumberOfBytes := Form1.Comport1.InputCount;
           Form1.ComPort1.ReadStr(Str, NumberOfBytes);
           for I := 1 to length(Str) do
             If Str[I] in ['0'..'9'] then
                Label2.Caption := Label2.Caption + Str[I];
           Z79Error := StrToIntDef(Label2.Caption,999);
           application.processmessages;
           Sleep(1000);
           CASE Z79Error OF
              0 : Label2.Caption := Label2.Caption + ' = I/O port is good.';
              1 : Label2.Caption := Label2.Caption + ' = Strobe 0 error';
              2 : Label2.Caption := Label2.Caption + ' = Strobe 1 error';
              3 : Label2.Caption := Label2.Caption + ' = Strobe 2 error';
              4 : Label2.Caption := Label2.Caption + ' = Strobe 3 error';
              5 : Label2.Caption := Label2.Caption + ' = Strobe 4 error';
              6 : Label2.Caption := Label2.Caption + ' = Strobe 5 error';
              7 : Label2.Caption := Label2.Caption + ' = Strobe 6 error';
              8 : Label2.Caption := Label2.Caption + ' = Strobe 7 error';
              9 : Label2.Caption := Label2.Caption + ' = Output 1 error';
             10 : Label2.Caption := Label2.Caption + ' = Output 2 error';
             11 : Label2.Caption := Label2.Caption + ' = CW/CCW dir error';
             12 : Label2.Caption := Label2.Caption + ' = A.W.O. error';
             13 : Label2.Caption := Label2.Caption + ' = Motion Busy error';
             14 : Label2.Caption := Label2.Caption + ' = Input failure';
             15 : Label2.Caption := Label2.Caption + ' = Initialization error';
             16 : Label2.Caption := Label2.Caption + ' = EEPROM error';
           else Label2.Caption := Label2.Caption + ' = Communication error'; { case }
           end;
              Button3.Enabled := True;
              Button3.Caption := 'Finish';
         End;
     4 : begin
           Button3.Enabled := False;
           Form1.ComPort1.WriteStr('Z90 9 ' + CR);  // restart strobes
           application.processmessages;
           sleep(600);
           application.processmessages;
           Z79Step := 0; // ready for the next test
           Button3.Enabled := True;
           Button3.Caption :=' Start';
           Label1.Caption := 'Click on "Start"';
           Label2.Caption := '';
         end;
  end;
end;

procedure TEPI_IO_Form.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  Button1Click(Sender);
end;

procedure TEPI_IO_Form.ReadInputClick(Sender: TObject);
var S : string;
begin
  Form1.ComPort1.ClearBuffer(True, True);
  Form1.Comport1.WriteStr('H21 ' + LF + CR);
  Sleep(100);
  NumberOfBytes := Form1.Comport1.InputCount;
  Form1.ComPort1.ReadStr(S, 20);
  S := Form1.cleanStr(S);  // for test only
  while length(S) < 8 do
     S := '0' + S;   // no crash on error length
  if pos('=',S) <> 0 then     // remove =
     delete(S,pos('=',S),1);
  If S[8] = '1' then
    CheckBox8.Checked := True
  else
    CheckBox8.Checked := False;
  If S[7] = '1' then
    CheckBox9.Checked := True
  else
    CheckBox9.Checked := False;
  If S[6] = '1' then
    CheckBox10.Checked := True
  else
    CheckBox10.Checked := False;
  If S[5] = '1' then
    CheckBox11.Checked := True
  else
    CheckBox11.Checked := False;
end;


// ******* read the error from the indexer (SS2000I) ********* }
// WORKS ALSO PARTIAL FOR THE epi
Procedure TEPI_IO_Form.GetEpiError;
var Er85, Er86, Er87 : String;
begin
  if ContrType = 4 then Form1.WriteScreen('Reporting SS2000I - ' + GetH23 + ' error -' + CR+LF);
  if ContrType = 5 then Form1.WriteScreen('Reporting EPI '       + GetH23 + ' error -' + CR+LF);
  Form1.ComPort1.ClearBuffer(True, True);
  Form1.Comport1.WriteStr('H85'+CHR($0D));
  Sleep(100);
  NumberOfBytes := Form1.Comport1.InputCount;
  Form1.ComPort1.ReadStr(Er85, 40);

  Form1.Comport1.WriteStr('H86'+CHR($0D));
  Sleep(100);
  NumberOfBytes := Form1.Comport1.InputCount;
  Form1.ComPort1.ReadStr(Er86, 40);

  Form1.Comport1.WriteStr('H87'+CHR($0D));
  Sleep(100);
  NumberOfBytes := Form1.Comport1.InputCount;
  Form1.ComPort1.ReadStr(Er87, 20);

  Er85 := Form1.cleanStr(Er85);
  Er86 := Form1.cleanStr(Er86);
  Er87 := Form1.cleanStr(Er87);

  while pos('=',Er85) <> 0 do     // remove = sign
     delete(Er85,pos('=',Er85),1);
  while pos('=',Er86) <> 0 do     // remove = sign
     delete(Er86,pos('=',Er86),1);
  while pos('=',Er87) <> 0 do     // remove = sign
     delete(Er87,pos('=',Er87),1);

  if ContrType = 4 then begin  // do not crash on too short strings
    while length(Er85) < 10 do
       Er85 := Er85 + '0';
    while length(Er86) < 16 do
       Er86 := Er86 + '0';
  end;

  if ContrType = 5 then begin  // do not crash on too short strings
    while length(Er85) < 8 do
       Er85 := Er85 + '0';
    while length(Er86) < 8 do
       Er86 := Er86 + '0';
  end;

  Form1.WriteScreen(CR+LF);
  Form1.WriteScreen('H85 : '+ Er85 + '  ');
  If ContrType = 4 then begin  // SS2000I error section
     Form1.WriteScreen(Er85[1]+' Axis : ');    // X or Y axis
     If Er85[ 2] = '1' then Form1.WriteScreen(' Drive not ready');
     If Er85[ 3] = '1' then Form1.WriteScreen(' Index from Run Limit exceeded');
     If Er85[ 4] = '1' then Form1.WriteScreen(' CW Software Limit exceeded');
     If Er85[ 5] = '1' then Form1.WriteScreen(' CCW Software Limit exceeded');
     If Er85[ 6] = '1' then Form1.WriteScreen(' CW Hardware Limit exceeded');
     If Er85[ 7] = '1' then Form1.WriteScreen(' CCW Hardware Limit exceeded');
     If Er85[ 8] = '1' then Form1.WriteScreen(' Program Errorr');
     If Er85[ 9] = '1' then Form1.WriteScreen(' Closed Loop Error');
     If Er85[10] = '1' then Form1.WriteScreen(' Hardware or Software Clear');
     Form1.WriteScreen(CR+LF);

     Form1.WriteScreen('H86 : '+ Er86 + ' ');
     If Er86[ 2] = '1' then Form1.WriteScreen(' Illegal G Code');
     If Er86[ 3] = '1' then Form1.WriteScreen(' Illegal L Code');
     If Er86[ 4] = '1' then Form1.WriteScreen(' Subroutine or loop Nesting Error');
     If Er86[ 5] = '1' then Form1.WriteScreen(' F data out of range');
     If Er86[ 6] = '1' then Form1.WriteScreen(' X or Y data out of range');
     If Er86[ 7] = '1' then Form1.WriteScreen(' N data out of range');
     If Er86[ 8] = '1' then Form1.WriteScreen(' Line requires F data');
     If Er86[ 9] = '1' then Form1.WriteScreen(' Line requires X or Y data');

     If Er86[10] = '1' then Form1.WriteScreen(' G code illegal in current cycle');
     If Er86[11] = '1' then Form1.WriteScreen(' Switching axis while Jogging');
     If Er86[12] = '1' then Form1.WriteScreen(' Attempted Index during a Jog cycle');
     If Er86[13] = '1' then Form1.WriteScreen(' G code can not be executed from line 0');
     If Er86[14] = '1' then Form1.WriteScreen(' No external data source');
     If Er86[15] = '1' then Form1.WriteScreen(' Illegal comparision opposite direction');
     If Er86[16] = '1' then Form1.WriteScreen(' X/Y sign required');
     If Er86[17] = '1' then Form1.WriteScreen(' No Trigger from IFR/RMH cycle');
     Form1.WriteScreen(CR+LF);

     Form1.WriteScreen('H87 : '+ Er87 + '      ');
     Form1.WriteScreen('Error at line number : '+ Er87 +CR+LF);
  end;
  If ContrType =  5 then begin  // EPI error section
     If Er85[ 2] = '1' then Form1.WriteScreen(' Index from Run Limit exceeded');
     If Er85[ 3] = '1' then Form1.WriteScreen(' CCW Software Limit exceeded');
     If Er85[ 4] = '1' then Form1.WriteScreen(' CW Software Limit exceeded');
     If Er85[ 5] = '1' then Form1.WriteScreen(' CCW Software Limit exceeded');
     If Er85[ 6] = '1' then Form1.WriteScreen(' CW Software Limit exceeded');
     If Er85[ 7] = '1' then Form1.WriteScreen(' CCW Hardware Limit exceeded');
     If Er85[ 8] = '1' then Form1.WriteScreen(' CW Hardware Limit exceeded');
     Form1.WriteScreen(CR+LF);

     Form1.WriteScreen('H86 : '+ Er86 + ' ');
     If Er86[ 1] = '1' then Form1.WriteScreen(' Illegal G Code');
     If Er86[ 2] = '1' then Form1.WriteScreen(' Illegal L Code');
     If Er86[ 3] = '1' then Form1.WriteScreen(' Subroutine or loop Nesting Error');
     If Er86[ 4] = '1' then Form1.WriteScreen(' F data out of range');
     If Er86[ 5] = '1' then Form1.WriteScreen(' X data out of range');
     If Er86[ 6] = '1' then Form1.WriteScreen(' N data out of range');
     If Er86[ 7] = '1' then Form1.WriteScreen(' Line requires F data');
     If Er86[ 8] = '1' then Form1.WriteScreen(' Line requires X data');

     Form1.WriteScreen(CR+LF);
     Form1.WriteScreen('H87 : '+ Er87 + '      ');
     Form1.WriteScreen('Error at line number : '+ Er87 +CR+LF);
  end;
end;




procedure TEPI_IO_Form.Button2Click(Sender: TObject);
begin
    Application.HelpContext(5100);
end;

end.

⌨️ 快捷键说明

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