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

📄 wbta_32_idx.pas

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

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, WBTAUnit1, WBTA_Var, ScanIDX, PCtoIDX;

Function  GetH23 : string; // for PI / EPI
Function  GetREV:string;   // for TDDC and Warpdrive
Function  GetL70:Integer;
Procedure ScanIDX;
Procedure IDXToPC;
Procedure PCtoIDX;
Procedure GetPar;
Function  ParInfo(L : Integer): String;
implementation

// uses WBTAUnit1, WBTA_Var, ScanIDX;
// adapted for use with TDC and Warpdrive WB 01.02.2002

procedure ScanIDX;
var   I : integer;
    Str : string;
begin
  Doorgaan := False;  // stop the terminal
  Form1.Enabled := False;
  Doorgaan := True;
  Str := '';
  I := 1;
  IDXNum := 100;  // no indexer selected
  try
    Form1.ComboBox2.Clear;
    Form1.StatusBar1.Panels[2].Text := ' Unit : ? ';
    ScanForm := TScanForm.Create(Application);
    ScanForm.Caption := 'Scanning for Indexers';
    ScanForm.Label3.Caption := '99';
    ScanForm.Label2.Caption := 'Scanning';
    ScanForm.Show;
    WHILE ((I < 100) and (Doorgaan)) DO Begin
      ScanForm.ProgressBar1.Position := I;
      Form1.Comport1.WriteStr('<'+IntToStr(I)+'? ');
      ScanForm.Label2.Caption := 'Scanning : '+IntToStr(I)+' ';      // for test
      Sleep(100);
      Application.ProcessMessages;
      NumberOfBytes := Form1.Comport1.InputCount;
      Form1.ComPort1.ReadStr(Str, NumberOfBytes);
      IF NumberOfBytes > 0  then             { there was response from indexer }
         IF Pos(':',Str) <> 0 THEN begin
            IDXVersion := GetH23;
            sleep(400);
            IDXNum := I;
            Str := '# '+ inttostr(IDXNum)+' = ' + IDXVersion + ' busy';
            Form1.ComboBox2.Items.Add('# '+ inttostr(IDXNum)+' = ' + IDXVersion);
            ScanForm.Label4.Caption := Str;
            Form1.ComboBox2.Text := '# '+ inttostr(IDXNum)+' = ' + IDXVersion;
         end;
         IF Pos('=',Str) <> 0 THEN begin
            IDXVersion := GetH23; //GetH23;
            sleep(400);
            IDXNum := I;
            Str := '#  '+ inttostr(IDXNum)+' = ' + IDXVersion + ' ready';
            Form1.ComboBox2.Items.Add('# '+ inttostr(IDXNum)+' = ' + IDXVersion);
            Form1.ComboBox2.Text := '# '+ inttostr(IDXNum)+' = ' + IDXVersion;
            ScanForm.Label4.Caption := Str;
         end;
         Str := Form1.CleanStr(Str);
         IF StrToInt64Def(Str, 0) > 0 then // TDC or Warpdrive
         begin
            IDXVersion := GetREV;
            sleep(400);
            Str := copy(GetREV,1,22) + '...';
            IDXNum := I;
            Str := '# '+ inttostr(IDXNum) + ' = '+ Str;
            Form1.ComboBox2.Items.Add(Str);
            Form1.ComboBox2.Text := Str;
            ScanForm.Label4.Caption := Str;
          end;
      INC(I);
    End;  {WHILE }
    Form1.Comterminal1.WriteStr(#10+#13); // send new line
    IF IDXNum < 100 THEN Begin  // indexer was found
       Form1.Comport1.WriteStr('<'+IntToStr(IDXNum)+ ' '); // select last control
       Form1.StatusBar1.Panels[2].Text := ' Unit : ' + IDXVersion;
 //    Form1.Caption := Progname + UnitStr + ', #' + IntToStr(IDXNum)+ '--' + IDXVersion;
    End Else Form1.StatusBar1.Panels[2].Text := ' Unit : none ';
  finally
    Form1.ComPort1.ClearBuffer(True, True);
    ScanForm.Release;
    ScanForm := NIL;
  end;
  Form1.Enabled := True;
  Form1.TermReceive;  // restart the terminal
end;

Function GetH23:string;
var Str : string;
begin
  Str := '';
  Sleep(100);
  Form1.ComPort1.ClearBuffer(True, True);
  Form1.Comport1.WriteStr('H23'+CHR($0D)); { ask version, direct command}
  sleep(500);
  NumberOfBytes := Form1.Comport1.InputCount;
  Form1.ComPort1.ReadStr(Str, NumberOfBytes);
  Str := Form1.CleanStr(Str);
  if pos('=',Str) <> 0 then     // remove = sign
     delete(Str,pos('=',Str),1);
  Result := Str;
end;

Function GetREV:string;   // for TDDC and Warpdrive
var Str : string;
begin
  Str := '';
  Sleep(100);
  Form1.ComPort1.ClearBuffer(True, True);
  Form1.Comport1.WriteStr(chr(27)+'REV'+CHR($0D)); { ask version, direct command}
  sleep(500);
  NumberOfBytes := Form1.Comport1.InputCount;
  Form1.ComPort1.ReadStr(Str, NumberOfBytes);
  Str := Form1.CleanStr(Str);
  Result := Str;
end;



Procedure IDXToPC;
Var Str, Ss   : String;
    Line,
    Empty,
    Error,
    I         : Integer;
    ProgramStr   : TStringList;
Begin
  If IDXNum = 100 then begin
     Form1.NoIDXSel;
     exit;
  end;
  Error := 0;
  Doorgaan := True;
  ProgramStr := TStringList.Create;
  ProgramStr.Clear;    // FileOut := '';
  Empty := 0;
  If ProgPars Then begin
     Form1.ReadLParameters1Click(Form1); //GetPar;
     ProgramStr.Text := LParamStr.Text;
  end;
  try
     ScanForm := TScanForm.Create(Application);
     ScanForm.Caption := ' Reading program';
     ScanForm.Label2.Caption := 'Reading line : 0';
     ScanForm.Label3.Caption := '400';
     ScanForm.Label4.Caption := '';
     ScanForm.Show;
     Form1.Comport1.WriteStr('L26 0'+CHR($0A)+CHR($0D));
     sleep(100);
     Line := 1;
     Repeat                              { get the program from indexer }
       Form1.Comport1.WriteStr('N'+IntToStr(Line)+' H13'+CHR($0A)+CHR($0D));   { get one line }
       Sleep(25);
//       ScanForm.BringToFront;
       Application.ProcessMessages;
       I := 1;
       Str := '';
       Repeat
          INC(I);
          Sleep(20);
          NumberOfBytes := Form1.Comport1.InputCount;
          Form1.ComPort1.ReadStr(Ss, NumberOfBytes);
          Str := Str + Ss;
          If pos(#13,Str) <> 0 then
             I := 999;
          Str := Form1.CleanStr(Str);    { get string from IND and remove rubbish }
          If I = 500 then begin
             Error := 1; // communication problem
             Doorgaan := False;
             I := 999;
          end;
       Until I = 999;       // 500 is timeout
       IF Length(Str) > 5 then begin               { line contains something }
          Ss := Str;                                     { otherwise skip line }
          Ss := Form1.AchterSpatieWeg(Ss);
          IF Length(Ss) > 4 Then              { empty detection 23/01/1995}
             Empty := 0 else INC(Empty);
          IF Empty < 2 then begin   { write the data line and after an empty}
                                    { line only one empty line is written }
             ProgramStr.Text := ProgramStr.Text + Ss;
          End;
       End;
       ScanForm.Label2.Caption := 'Reading line : '+ IntToStr(Line);
       ScanForm.ProgressBar1.Position := Line div 4;
       INC(Line);
     Until (Line = 401) OR (Doorgaan = False);
     If Error = 1 then begin
       Application.MessageBox('There was a problem with the communication.'
        +#13#10+'You may try to save the file, but a ggod ressult is not sure.',
        'Communication Error', mb_applmodal+mb_iconwarning+mb_ok+mb_defbutton1);
     end;

  finally
      Form1.ComPort1.ClearBuffer(True, True);
      ScanForm.Release;
      ScanForm := NIL;
  end;
  Form1.SaveDialog1.Filter :=  'MicorSerie Files (*.PGM)|*.PGM';
  Form1.SaveDialog1.DefaultExt := 'PGM';
  If Form1.SaveDialog1.Execute then
     ProgramStr.SaveToFile(Form1.SaveDialog1.FileName);
  ProgramStr.Free;
  Doorgaan := True;
End;


{ ----------------- Get L code Parameters -----------------------}

Procedure GetLData;   { receive L code data from indexer }
Var I : Integer;
   Str : string;
    Ss : String;
 Error : Integer;
Begin
  If IDXNum = 100 then begin
     Form1.NoIDXSel;
     exit;
  end;
  LParamStr.Clear;
  Error := 0;
  LMax  := 0; { No L's received }
  Form1.Comport1.WriteStr('L49 0' + CHR($0D));
  Form1.Comport1.WriteStr('L50 1' + CHR($0D));
  Form1.Comport1.WriteStr('H16'+CHR($0D));
  try
    ScanForm := TScanForm.Create(Application);
    ScanForm.Caption := ' Reading L Parameters';
    ScanForm.Label3.Caption := '50';
    ScanForm.Label2.Caption := 'Reading.';
    ScanForm.Show;
    REPEAT                                          { get parameters from unit }
      Sleep(20);
      Application.ProcessMessages;
      I := 1;
      Str := '';
      Repeat
        INC(I);
        Sleep(10);
//      ScanForm.BringToFront;
        NumberOfBytes := 1; //Form1.Comport1.InputCount;
        Form1.ComPort1.ReadStr(Ss, NumberOfBytes);
        Str := Str + Ss;
        If POS(#13,Str) <> 0 then
           I := 999;
        Str := Form1.CleanStr(Str);    { get string from IND and remove rubbish }
        If Doorgaan = False Then I := 100; // to stop from outside
        If I = 100 then begin
           Error := 1; // communication problem
           Doorgaan := False;
           I := 999;
        end;
      Until I = 999;       // 500 is timeout
      IF Pos(#13, Str) <>  0 THEN Sleep(20);
      ScanForm.Label2.Caption := 'Reading Parameter : '+ IntToStr(Lmax);
      ScanForm.ProgressBar1.Position := LMax* 2;
      Str := StringReplace(Str,'=','',[rfReplaceAll]);
//      while pos('=',Str) <> 0 do          // remove any = signs
//         delete(Str,pos('=',Str),1);
      LParamStr.Add(Str);
      IF Pos('L',Str)<> 0 Then INC(LMax);   { count the parameters }
    UNTIL Error = 1;
    Sleep(25);
    IMax := I - 1; { keep end of data }
  finally
    Form1.ComPort1.ClearBuffer(True, True);
    ScanForm.Release;
    ScanForm := NIL;
  end;
  LParamStr.SaveToFile('LPARAM.TXT'); // for test
  Form1.Comport1.WriteStr('L50 0' + CHR($0D));  { set to factory default }
  Doorgaan := True; // keep terminal program running
End;

Function ParInfo(L : Integer): String;
Begin
 case L of
   { Control parameters }
   07 : Result := 'Strobe delay                    ';
   13 : Result := 'Step Increment for X,Y axes     ';
   16 : Result := 'Index from Run Travel Limit     ';
   18 : Result := 'Clockwise travel Limit          ';
   19 : Result := 'Counterclockwise travel Limit   ';
   20 : Result := 'Powerup Configuration           ';
   41 : Result := 'Autostart Line Number           ';
   45 : Result := 'Limit Switch Enable             ';
   57 : Result := 'Strobe 0, Strobe 1 Delay        ';
   67 : Result := 'Autoreverse                     ';
   70 : Result := 'Step Resolution                 ';
   { RS232 parameters }
   01 : Result := 'RS232 Message # 1               ';
   02 : Result := 'RS232 Message # 2               ';
   03 : Result := 'RS232 Message # 3               ';
   04 : Result := 'RS232 Message # 4               ';
   05 : Result := 'RS232 Message # 5               ';
   21 : Result := 'Device Identification Number    ';
   22 : Result := 'Baud Rate                       ';
   23 : Result := 'Character Length                ';
   25 : Result := 'RS232 Parity                    ';
   26 : Result := 'Command Acknowledge             ';
   48 : Result := 'Program Line Count Designator   ';
   49 : Result := 'Parameter Transfer Designator   ';
   50 : Result := 'Parameter Transfer Count        ';
   52 : Result := 'Buffer Warning Characters       ';
   53 : Result := 'Following Error Characters      ';
   54 : Result := 'Unable to Correct Characters    ';
   55 : Result := 'Line Done Characters            ';
   56 : Result := 'Program Done Characters         ';
   98 : Result := 'Delay between %H codes          ';
   { Program parameters }
   06 : Result := 'Program Execution Format        ';
   44 : Result := 'Delay After Motion              ';
   47 : Result := 'Program Repeat Count            ';
   51 : Result := 'Input/Output Mode select        ';
   58 : Result := 'Input Configuration             ';
   59 : Result := 'Output Configuration            ';
   91 : Result := '(BCD) Scale factor              ';
   {Feed Rate parameters }
   09 : Result := 'Jog Speed for X, Y Axis         ';
   12 : Result := 'Low Speed for X, Y Axis         ';
   14 : Result := 'Home Speed                      ';
   73 : Result := 'Deviation Frequency             ';
   {Ramp parameters }
   10 : Result := 'Deceleration                    ';
   11 : Result := 'Acceleration (+Decel PI/EPI)    ';
   71 : Result := 'Ramp Freqency Limit             ';
   72 : Result := 'Ramp Profile Select             ';
   { Mechanical Home Parameters }
   08 : Result := 'Mechanical Home Direction       ';
   17 : Result := 'Offset from Mechanical Home     ';
   { Backlash compensation }
   43 : Result := 'Delay between Index and Backlash';
   66 : Result := 'Backlash Compensation           ';
   { Closed Loop parameters }
   87 : Result := 'Following Error                 ';
   90 : Result := 'Pos. ver Enable / Disable       ';
   93 : Result := 'In position Bandwith            ';
   94 : Result := 'Invert Encoder Direction        ';
   95 : Result := 'Encoder Scale Factor            ';
   96 : Result := 'Number of Pos Corrections       ';
   97 : Result := 'Delay between Corrections       ';
   99 : Result := '                                '; { to clear info }
  else  Result := ' ????????? unknown L function   ';
  end;
End;


Function GetL70:Integer;  { receive L70 code data from indexer }
Var s : string;
Begin
  s := '';
  GetL70 := 0;
  Form1.ComPort1.WriteStr('L49 70' + CHR($0D));
  Form1.ComPort1.WriteStr('L50 1' + CHR($0D));
  Form1.ComPort1.WriteStr('H16'+CHR($0D));
  Sleep(200);
  Form1.ComPort1.ReadStr(S, 50);
  S := Form1.CleanStr(S);
  IF Pos('L70',s) <> 0 Then Begin
      IF Pos('001',s) <> 0 Then GetL70 := 1;
      IF Pos('002',s) <> 0 Then GetL70 := 2;
      IF Pos('005',s) <> 0 Then GetL70 := 5;
      IF Pos('010',s) <> 0 Then GetL70 := 10;
      IF Pos('125',s) <> 0 Then GetL70 := 125;
  End;
  Form1.ComPort1.WriteStr('L49 0' + CHR($0D));
  Form1.ComPort1.WriteStr('L50 0' + CHR($0D));
  Sleep(200);
End;

Procedure PCtoIDX;
Begin
{  If IDXNum = 100 then begin
     Form1.NoIDXSel;
     exit;
  end; }
  try
    ToIDX_Form := TToIDX_Form.Create(Application);
    ToIDX_Form.ShowModal;
  finally
     ToIDX_Form.Release;
     ToIDX_Form := NIL;
  end;
  Doorgaan := True; // keep terminal program running
End;

Procedure GetPar;
Begin                                      { Main body of Get parameters }
  Doorgaan := True;
  GetLData;                              { get L Parameters from indexer }
end; {GetPar}

end.

⌨️ 快捷键说明

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