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

📄 warpiotest.pas

📁 System will automatically delete the directory of debug and release, so please do not put files on t
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit WarpIOTest;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, DopjeNew, Gauges, Buttons, ToolWin, ComCtrls;

type
  TWarpIOForm = class(TForm)
    BCDBox: TGroupBox;
    IN11: TDopjeNew;
    IN12: TDopjeNew;
    IN13: TDopjeNew;
    IN14: TDopjeNew;
    IN15: TDopjeNew;
    IN16: TDopjeNew;
    IN17: TDopjeNew;
    IN18: TDopjeNew;
    AnalogIn: TGroupBox;
    Analog: TGauge;
    Label1: TLabel;
    BCDswitch: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    OptoIn: TGroupBox;
    IN1: TDopjeNew;
    IN2: TDopjeNew;
    IN3: TDopjeNew;
    IN4: TDopjeNew;
    IN5: TDopjeNew;
    IN6: TDopjeNew;
    IN7: TDopjeNew;
    IN8: TDopjeNew;
    IN9: TDopjeNew;
    IN10: TDopjeNew;
    Label4: TLabel;
    Label6: TLabel;
    StaticText1: TStaticText;
    AnalogOut: TGroupBox;
    AnOutOff: TButton;
    VoltOut: TLabel;
    UpDown1: TUpDown;
    StopBtn: TButton;
    Button2: TButton;
    Label12: TLabel;
    RunLabel: TLabel;
    encoderbox: TGroupBox;
    Label13: TLabel;
    ENC2Label: TLabel;
    ENC1: TLabel;
    ENC2: TLabel;
    OptoOut: TGroupBox;
    Label7: TLabel;
    Label8: TLabel;
    OUT1: TCheckBox;
    OUT2: TCheckBox;
    OUT3: TCheckBox;
    OUT4: TCheckBox;
    DrvReadyBox: TGroupBox;
    IN19: TDopjeNew;
//    Label5: TLabel;
    Label11: TLabel;
    BCDOut: TGroupBox;
    Label9: TLabel;
    OUT5: TCheckBox;
    OUT6: TCheckBox;
    OUT7: TCheckBox;
    OUT8: TCheckBox;
    SpeedButton3: TSpeedButton;
    BtBCD: TSpeedButton;
    BtBCDIO: TSpeedButton;
    BtAnalogIO: TSpeedButton;
    BtEncoder: TSpeedButton;
    procedure FormShow(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure OUT1Click(Sender: TObject);
    procedure BtBCDClick(Sender: TObject);
    procedure BtBCDIOClick(Sender: TObject);
    procedure BtEncoderClick(Sender: TObject);
    procedure BtAnalogIOClick(Sender: TObject);
    procedure AnOutOffClick(Sender: TObject);
    procedure UpDown1Changing(Sender: TObject; var AllowChange: Boolean);
    procedure StopBtnClick(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
  private
    { Private declarations }
    ServoStat : Integer;  // 0 inactive, 1 switch on, 2 switch off, 9 is torque mode
    TorqueCMD : Integer;  // torque command (0..1024)
    INmax : integer;      // TDC 19, Warp 17
    RunMode  : Integer;   // select the I/O
     IP : String[19];     // inputs, 101010110format
     OP : String[ 8];     // for the outputs
    OUTmax   : integer;   // indicate the number of outputs TDC 6, warp drv 8
    Running  : Boolean;
    AnalogOn : Boolean;
    procedure WriteOutput;
    procedure WriteOut(OutNbr : integer);
    Procedure SwitchSet(N : integer; S : Char);
    Procedure SwitchAll;
    Function  ReadInput(Inp : integer):Integer;
    procedure ReadIN1_5;
    procedure ReadIN6_10;
    procedure ReadIN11_15;
    procedure ReadIN16_19;
    Procedure ReadEncoders;
    Procedure ReadInputs;
    Procedure ReadBCD; { WB 04.07.1998 }
    Procedure ReadAnalog;
    procedure ReadOutputs;
    PROCEDURE CC_IO;
    procedure WegBoxen; // makes all the boxes invisible
  public
    { Public declarations }
    Function  PrintCCError( Er : Integer):String;
    Procedure GetCCError(Var E : Integer);
  end;

var
  WarpIOForm: TWarpIOForm;

implementation

uses WBTAUnit1,WBTA_Var;

{$R *.DFM}

procedure TWarpIOForm.FormShow(Sender: TObject);
var I : integer;
begin
  if ContrType = 6 then begin  // TDC only two outputs
     OUT3.Visible := False;
     OUT4.Visible := False;
     Label8.Visible := False;
     ENC2.Visible := True;     // second encoder
     ENC2Label.Visible := True;   // second encoder
     AnalogOut.Enabled := True;
     AnalogOut.Visible := True;
     Label6.Visible := True;
     Label9.Caption := '3    4    5    6';
     Label11.Caption := '11   12  13   14   15  16   17   18';
     WarpIOForm.Caption := ' TDC I/O Test ';
     OUTmax := 8;
     INmax := 19;
  end;
  if ContrType = 7 then begin  // warpdrive has 4 outputs
     IN9.Visible := False;
     IN10.Visible := False;
     ENC2.Visible := False;     // second encoder
     ENC2Label.Visible := False;   // second encoder
     AnalogOut.Enabled := False;
     AnalogOut.Visible := False;
     Label8.Visible := True;
     Label6.Visible := False;
     Label9.Caption := '5    6     7     8';
     Label11.Caption := '  9   10  11   12   13  14   15   16';
     OptoIN.Width := 172;
     WarpIOForm.Caption := ' WarpDrive I/O Test ';
     OUTmax := 8;
     INmax := 17;
  end;
  ServoStat := 0; // no action
  WarpIOForm.Left := Form1.Left + (Form1.Width  - WarpIOForm.Width)  div 2;
  WarpIOForm.Top  := Form1.Top  + (Form1.Height - WarpIOForm.Height) div 2;
  for I := 0 to ComponentCount - 1 do begin
    if (Components[I] is TDopjeNew) then begin
       TDopjeNew (Components[I]).PinShape  := circle;
       TDopjeNew (Components[I]).BackColor := clMaroon;
    end;
  end;
  OP := '00000000';
  IP := '0000000000000000000';
  ReadOutputs;  // set the outputs
  RunMode := 0; // BCD switch
  WegBoxen;
  Label2.Caption := ' +0000000 ';
  BCDSwitch.Visible := True;
end;

procedure TWarpIOForm.WriteOutput;
var I : integer;
begin
  for I := 1 to OUTmax do
    if OP[I] = '1' then begin
       WriteOut(I);
       OP[I] := '0';
    end;
  for I := 1 to 8 do   // display on terminal screen
     Form1.Comterminal1.WriteStr(OP[I]);
  Form1.Comterminal1.WriteStr(CR+LF);
end;

procedure TWarpIOForm.WriteOut(OutNbr : integer);
var N : integer; // offset for out
    S : String;
begin
  N := OutNbr;
  IF ((ContrType = 6) and (OutNbr > 4)) then
  begin
     OutNbr := OutNbr - 2;
  end;
  S := 'OUT(' + chr(OutNbr + 48)+ ')';
  case N of
    1 : IF OUT1.Checked = true then  Form1.Comport1.WriteStr('OUT(1)= 1'+ CR)
                               else  Form1.Comport1.WriteStr('OUT(1)= 0'+ CR);
    2 : IF OUT2.Checked = true then  Form1.Comport1.WriteStr('OUT(2)= 1'+ CR)
                               else  Form1.Comport1.WriteStr('OUT(2)= 0'+ CR);

    3 : IF OUT3.Checked = true then  Form1.Comport1.WriteStr('OUT(3)= 1'+ CR)
                               else  Form1.Comport1.WriteStr('OUT(3)= 0'+ CR);
    4 : IF OUT4.Checked = true then  Form1.Comport1.WriteStr('OUT(4)= 1'+ CR)
                               else  Form1.Comport1.WriteStr('OUT(4)= 0'+ CR);

    5 : IF OUT5.Checked = true then  Form1.Comport1.WriteStr(S + ' = 1'+ CR)
                               else  Form1.Comport1.WriteStr(S + ' = 0'+ CR);
    6 : IF OUT6.Checked = true then  Form1.Comport1.WriteStr(S + ' = 1'+ CR)
                               else  Form1.Comport1.WriteStr(S + ' = 0'+ CR);
    7 : IF OUT7.Checked = true then  Form1.Comport1.WriteStr(S + ' = 1'+ CR)
                               else  Form1.Comport1.WriteStr(S + ' = 0'+ CR);
    8 : IF OUT8.Checked = true then  Form1.Comport1.WriteStr(S + ' = 1'+ CR)
                               else  Form1.Comport1.WriteStr(S + ' = 0'+ CR);
  end;
  sleep(50);
  NumberOfBytes := Form1.Comport1.InputCount;
  Form1.ComPort1.ReadStr(S, NumberOfBytes);  //  S := GetStr;
end;

Procedure TWarpIOForm.SwitchSet(N : integer; S : Char);
begin
  Case N of       // for TDC and Warpdrive
     1  : if S = '1' then IN1.BackColor := clYellow
          else IN1.BackColor := clMaroon;
     2  : if S = '1' then IN2.BackColor := clYellow
          else IN2.BackColor := clMaroon;
     3  : if S = '1' then IN3.BackColor := clYellow
          else IN3.BackColor := clMaroon;
     4  : if S = '1' then IN4.BackColor := clYellow
          else IN4.BackColor := clMaroon;
     5  : if S = '1' then IN5.BackColor := clYellow
          else IN5.BackColor := clMaroon;
     6  : if S = '1' then IN6.BackColor := clYellow
          else IN6.BackColor := clMaroon;
     7  : if S = '1' then IN7.BackColor := clYellow
          else IN7.BackColor := clMaroon;
     8  : if S = '1' then IN8.BackColor := clYellow
          else IN8.BackColor := clMaroon;
  end;

  If ContrType = 6 then   // TDC input
  begin
    Case N of
       9  : if S = '1' then IN9.BackColor := clYellow
                       else IN9.BackColor := clMaroon;
      10  : if S = '1' then IN10.BackColor := clYellow
                       else IN10.BackColor := clMaroon;
      11  : if S = '1' then IN11.BackColor := clYellow
                       else IN11.BackColor := clMaroon;
      12  : if S = '1' then IN12.BackColor := clYellow
                       else IN12.BackColor := clMaroon;
      13  : if S = '1' then IN13.BackColor := clYellow
                       else IN13.BackColor := clMaroon;
      14  : if S = '1' then IN14.BackColor := clYellow
                       else IN14.BackColor := clMaroon;
      15  : if S = '1' then IN15.BackColor := clYellow
                       else IN15.BackColor := clMaroon;
      16  : if S = '1' then IN16.BackColor := clYellow
                       else IN16.BackColor := clMaroon;
      17  : if S = '1' then IN17.BackColor := clYellow
                       else IN17.BackColor := clMaroon;
      18  : if S = '1' then IN18.BackColor := clYellow
                       else IN18.BackColor := clMaroon;
      19  : if S = '1' then IN19.BackColor := clYellow
                       else IN19.BackColor := clMaroon;
    end;
  end;

   If ContrType = 7 then   // Warpdrive inputs
  begin
    Case N of
       9  : if S = '1' then IN11.BackColor := clYellow
                       else IN11.BackColor := clMaroon;
      10  : if S = '1' then IN12.BackColor := clYellow
                       else IN12.BackColor := clMaroon;
      11  : if S = '1' then IN13.BackColor := clYellow
                       else IN13.BackColor := clMaroon;
      12  : if S = '1' then IN14.BackColor := clYellow
                       else IN14.BackColor := clMaroon;
      13  : if S = '1' then IN15.BackColor := clYellow
                       else IN15.BackColor := clMaroon;
      14  : if S = '1' then IN16.BackColor := clYellow
                       else IN16.BackColor := clMaroon;
      15  : if S = '1' then IN17.BackColor := clYellow
                       else IN17.BackColor := clMaroon;
      16  : if S = '1' then IN18.BackColor := clYellow
                       else IN18.BackColor := clMaroon;
      17  : if S = '1' then IN19.BackColor := clYellow
                       else IN19.BackColor := clMaroon;
    end;
  end;
end;

Procedure TWarpIOForm.SwitchAll;
Var N : Integer;
begin
  For N := 1 to INmax do begin
     SwitchSet(N,IP[N]);
     sleep(10);
     Form1.ComPort1.ClearBuffer(True, True);
  end;
end;

// --------------- input section ----------------------

Procedure TWarpIOForm.ReadEncoders;
var R : real;
    S : String;
begin
  Form1.Comport1.WriteStr('EP'+CHR($0D));
  Sleep(100);
  NumberOfBytes := Form1.Comport1.InputCount;
  Form1.ComPort1.ReadStr(S, NumberOfBytes);  //  S := GetStr;
  S := Form1.CleanStr(S);
  If length(S) > 7 then begin
     try
       R := StrToFloat(S);
       If R < 0 then begin
        S := '-';
        R := R * -1;
       end else S := '+';
       S := S + FormatFloat('000000.000000', R);
//     S := ' ' + S + FloatToStrF(R, ffFixed, 18, 6) + ' ';
       S := ' ' + S + ' '; // add spaces
       ENC1.Caption := S;
     except
       Label13.Caption := ' error ';
     end;
  end else
     Label13.Caption := ' error ';
end;


Procedure TWarpIOForm.ReadAnalog;
var R : real;
    P : integer;
    S : String;
begin
  Form1.Comport1.WriteStr('AN'+CHR($0D));
  Sleep(100);
  NumberOfBytes := Form1.Comport1.InputCount;
  Form1.ComPort1.ReadStr(S, NumberOfBytes);  //  S := GetStr;
  S := Form1.CleanStr(S);
  If length(S) > 7 then begin
     try
       R := StrToFloat(S); // Val(S,R,P);
       If R < 0 then begin
          S := '-';
          R := R * -1;
       end else S := '+'; // Write(' ');
       Label3.Caption := S;
       S := ' ' + S + FloatToStrF(R, ffFixed, 15, 3) + ' ';
       Label1.caption := S;
       P := round(R * 10);
       Analog.Progress := P;
      except
        Label1.caption := ' error ';
      end;
  end else
     Label1.caption := ' error ';
end;


Procedure TWarpIOForm.ReadBCD; { WB 04.07.1998 }
var
 Sign : Char;
    P : integer;
    S : String;
begin
  Form1.Comport1.WriteStr('BCD'+ CR);
  Sleep(120);

⌨️ 快捷键说明

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