📄 warpiotest.pas
字号:
Application.ProcessMessages;
NumberOfBytes := Form1.Comport1.InputCount;
Form1.ComPort1.ReadStr(S, 30 {NumberOfBytes}); // S := GetStr;
If length(S) > 8 then
begin
S := Form1.CleanStr(S);
Sign := '+';
If Pos('-',S) <> 0 then begin
Sign := '-';
S := Copy(S,2,Length(S));
end;
P := Pos('.',S);
S := Copy(S,1,P-1); // remove all after the .
While Length(S) < 7 do
S := '0' + S;
Label2.Caption := ' ' + Sign + S + ' ';
end;
end;
Function TWarpIOForm.ReadInput(Inp : integer):Integer;
var N : integer;
Str, S : String;
Ch : Char;
begin
result := 0;
Form1.Comport1.WriteStr('IN('+InttoStr(Inp)+')'+CR);
Sleep(15);
Str := '';
N := 0;
Ch := '0';
repeat
sleep(5);
application.ProcessMessages;
Form1.ComPort1.ReadStr(S, 1); // S := GetStr;
if length(S) > 0 then Ch := S[1];
if Ch in['0'..'1']
then Str := Str + Ch;
INC(N);
if Running = False then N := 101; // stop with running
application.ProcessMessages;
until (Ch = #13) or (N > 50);
if ((N < 100) and ( length(Str) > 0)) then begin // valid value
try
Ch := Str[1];
IP[Inp] := Ch;
result := StrToInt(Ch);
except
// Form1.Edit2.Text := 'Input Error'; // ?????
end;
end;
end;
procedure TWarpIOForm.ReadIN1_5;
var I : integer;
begin
for I := 1 to 7 do begin
ReadInput(I);
end;
for I := 1 to INmax do // display on terminal screen
Form1.Comterminal1.WriteStr(IP[I]);
Form1.Comterminal1.WriteStr(CR+LF);
end;
procedure TWarpIOForm.ReadIN6_10;
var I : integer;
begin
for I := 8 to 10 do begin
ReadInput(I);
end;
end;
procedure TWarpIOForm.ReadIN11_15;
var I : integer;
begin
for I := 11 to 15 do begin
ReadInput(I);
end;
end;
procedure TWarpIOForm.ReadIN16_19;
var I : integer;
begin
for I := 16 to INmax do begin // TDC 19 Warp 17
ReadInput(I);
end;
end;
Procedure TWarpIOForm.ReadInputs;
begin
ReadIN1_5;
ReadIN6_10;
ReadIN11_15;
ReadIN16_19;
end;
procedure TWarpIOForm.ReadOutputs;
{ used after start of the program to set outputs to the real position }
var I : integer;
S : String;
Ch : Char;
begin
Ch := '0';
Form1.Comport1.WriteStr(CHR($0D));
Sleep(20);
NumberOfBytes := Form1.Comport1.InputCount;
Form1.ComPort1.ReadStr(S, NumberOfBytes); // S := GetStr;
for I := 1 to OUTmax do begin
Form1.Comport1.WriteStr('out('+InttoStr(I)+')'+CHR($0D));
Sleep(50);
NumberOfBytes := Form1.Comport1.InputCount;
Form1.ComPort1.ReadStr(S, NumberOfBytes); // S := GetStr;
S := Form1.CleanStr(S);
if length(S) = 1 then begin
Ch := S[1];
// OP[I] := Ch;
end;
// set output checkboxes according to outputs,
if ((I = 1) and (CH = '1')) then OUT1.Perform(BM_SETCHECK, Ord(true), 0);
if ((I = 2) and (CH = '1')) then OUT2.Perform(BM_SETCHECK, Ord(true), 0);
if ((I = 3) and (CH = '1')) then OUT3.Perform(BM_SETCHECK, Ord(true), 0);
if ((I = 4) and (CH = '1')) then OUT4.Perform(BM_SETCHECK, Ord(true), 0);
if ((I = 5) and (CH = '1')) then OUT5.Perform(BM_SETCHECK, Ord(true), 0);
if ((I = 6) and (CH = '1')) then OUT6.Perform(BM_SETCHECK, Ord(true), 0);
if ((I = 7) and (CH = '1')) then OUT7.Perform(BM_SETCHECK, Ord(true), 0);
if ((I = 8) and (CH = '1')) then OUT8.Perform(BM_SETCHECK, Ord(true), 0);
end;
end;
{ ------------------------------------------------------------}
{ I/O Test section for the Cobra WB 15.06.1998 }
{ Converted to Delphi4 WB 25.05.2001 }
{ ------------------------------------------------------------}
PROCEDURE TWarpIOForm.CC_IO;
begin
Application.ProcessMessages;
ReadInputs;
ReadBCD;
SwitchAll;
// show communication by flashing the leds
Form1.Comport1.WriteStr('ledtest'+CHR($0D));
Sleep(20);
Repeat
RunLabel.visible := true;
Form1.Comport1.WriteStr('ledtest'+CHR($0D));
Application.ProcessMessages;
Sleep(150);
Application.ProcessMessages;
ReadIN1_5;
If EncoderBox.Visible = True then
ReadEncoders;
Application.ProcessMessages;
ReadIN6_10;
RunLabel.visible := false; // flashing label
Application.ProcessMessages;
if RunMode = 1 then
ReadIN11_15;
Application.ProcessMessages;
ReadIN16_19;
SwitchAll;
If ServoStat = 1 then // send start commands
begin
Form1.Comport1.WriteStr('SERVOOUT=1'+CHR($0D));
Form1.Comport1.WriteStr('SERVOOUT=0'+CHR($0D));
Form1.Comport1.WriteStr('WNDGS=1'+CHR($0D));
ServoStat := 9; // run mode
end;
If ServoStat = 2 then // send stop commands
begin
Form1.Comport1.WriteStr('TORQUE=0'+CHR($0D));
Form1.Comport1.WriteStr('SERVOOUT=1'+CHR($0D));
Form1.Comport1.WriteStr('TORQUE=0'+CHR($0D));
ServoStat := 0;
end;
If ServoStat = 9 then // send torque command
Form1.Comport1.WriteStr('TORQUE='+IntToStr(TorqueCMD)+CHR($0D));
Sleep(100);
WriteOutput;
if RunMode = 0 then
ReadBCD;
Application.ProcessMessages;
if AnalogIn.Visible = True then
ReadAnalog;
until Running = False;
// stop motor if running in torque mode.
// If ServoStat = 9 then // stop any motion
Form1.Comport1.WriteStr('TORQUE=0'+CHR($0D));
Form1.Comport1.WriteStr('SERVOOUT=1'+CHR($0D));
Form1.Comport1.WriteStr('TORQUE=0'+CHR($0D));
Form1.Comport1.WriteStr('WNDGS=0'+CHR($0D));
RunLabel.visible := true;
RunLabel.Enabled := False;
RunLabel.Caption := ' Stopped ';
end;
procedure TWarpIOForm.Button2Click(Sender: TObject);
begin
Application.ProcessMessages;
Running := not Running;
if Running then begin
// OptoPanel.Enabled := True;
BCDOut.Enabled := True;
BCDOut.Enabled := True;
StopBtn.Enabled := False;
Button2.Caption := 'Stop';
RunLabel.visible := true;
RunLabel.Enabled := True;
RunLabel.Caption := ' Running ';
CC_IO;
end
else begin
// OptoPanel.Enabled := False;
BCDOut.Enabled := False;
BCDOut.Enabled := False;
Button2.Caption := 'Start';
StopBtn.Enabled := true;
end;
end;
procedure TWarpIOForm.OUT1Click(Sender: TObject);
begin
OP[(Sender as TCheckbox).Tag] := '1' ; // update request
// WriteOut((Sender as TCheckbox).Tag) ;
end;
procedure TWarpIOForm.BtBCDClick(Sender: TObject);
begin
WegBoxen;
BCDSwitch.Visible := True;
// switch off the BCD-I/O outputs
OUT5.Perform(BM_SETCHECK, Ord(false), 0);
OUT6.Perform(BM_SETCHECK, Ord(false), 0);
OUT7.Perform(BM_SETCHECK, Ord(false), 0);
OUT8.Perform(BM_SETCHECK, Ord(false), 0);
end;
procedure TWarpIOForm.BtBCDIOClick(Sender: TObject);
begin
WegBoxen;
RunMode := 1;
BCDBox.Visible := True;
BCDOut.Visible := True;
end;
procedure TWarpIOForm.WegBoxen;
begin
RunMode := 0;
BCDSwitch.Visible := False;
BCDBox.Visible := False;
BCDOut.Visible := False;
AnalogOut.Visible := False;
AnalogIn.Visible := False;
Encoderbox.Visible := false;
end;
procedure TWarpIOForm.BtEncoderClick(Sender: TObject);
begin
WegBoxen;
EncoderBox.Visible := True;
end;
procedure TWarpIOForm.BtAnalogIOClick(Sender: TObject);
begin
WegBoxen;
if ContrType = 6 then begin
AnalogOut.Visible := True;
AnalogOut.Enabled := true;
end;
AnalogIn.Visible := True;
AnalogOn := False;
end;
procedure TWarpIOForm.AnOutOffClick(Sender: TObject);
begin
AnalogOn := Not AnalogOn;
If AnalogOn then
begin
AnOutOff.Caption := 'Off';
ServoStat := 1;
end else
begin
AnOutOff.Caption := 'On';
ServoStat := 2;
end;
end;
procedure TWarpIOForm.UpDown1Changing(Sender: TObject; var AllowChange: Boolean);
var R : real;
S : String;
begin
R := UpDown1.Position / 100;
S := FloatToStrF(R,ffFixed,4,2);
VoltOut.Caption := S;
// Form1.Edit2.Text := IntToStr(Round(R * 204.8));
TorqueCMD := Round(R * 204.8);
end;
// taken from WETA program WB 19.12.2001
Function TWarpIOForm.PrintCCError( Er : Integer):String;
var S : String;
begin
case Er of
00 : S := 'There is no Error';
01 : S := 'Could nort burn Flash succesfully';
02 : S := 'Could not download file';
03 : S := 'Not enough memory to execute user program';
04 : S := 'Attempt to acces non-existing array element';
05 : S := 'Real data too large to convert to integer data.';
06 : S := 'Attempt to set accel data <= 0';
07 : S := 'Attempt to set decel data <= 0';
08 : S := 'Attempt to acces non-existing output';
09 : S := 'Attempt to acces non-existing input';
10 : S := 'Attempt to divide by zero';
11 : S := 'Received serial data will not fit in buffer';
12 : S := 'Motion occuring when program ended';
13 : S := 'Attempt to execute user program that is not present';
14 : S := 'Incorrect user program checksum';
15 : S := 'Attempt to set Kp out of range';
16 : S := 'Attempt to set Kd out of range';
17 : S := 'Attempt to set Ki out of range';
18 : S := 'Attempt to set Kvff out of range';
19 : S := 'Attempt to set FOLERR < 0';
20 : S := 'Attempt to set INTLIM out of range';
21 : S := 'Move distance too large';
22 : S := 'Function not implemented';
23 : S := 'INPUT command error occured';
24 : S := 'NVR specified location out of range(1-400)';
25 : S := 'NVR device not detected.';
128 : S := '+ limit switch activated';
129 : S := '- limit switch activated';
130 : S := '+ software travel limit exceeded';
131 : S := '- software travel limit exceeded';
132 : S := 'This code is reserved for future use';
133 : S := 'Excessive position error';
134 : S := 'Registration distance too small';
135 : S := 'Attempt to move with drive not enable';
136 : S := 'Attempt to move with drive not ready';
137 : S := 'Gearing backlog overflow';
138 : S := 'NVR data corrupt';
else S := '---- Unknown Error ----'
end;
Result := S;
end;
// taken from WETA program WB 19.12.2001
Procedure TWarpIOForm.GetCCError(var E : Integer);
var W : String;
M, I : Integer;
begin
Sleep(20);
Form1.ComPort1.ReadStr(W, 5);
W := Form1.CleanStr(W); // W := GetStr;
// W := Copy(W, 1, Pos(#13,(W)) - 1); // get error number from string
Form1.WriteScreen('Error #'+W +' : ');
Val(W,I,M);
If M = 0 Then Form1.WriteScreen(PrintCCError(I)+#13+#10); // WriteLn(PrintCCError(I));
E := I;
end;
procedure TWarpIOForm.StopBtnClick(Sender: TObject);
begin
close;
end;
procedure TWarpIOForm.SpeedButton3Click(Sender: TObject);
begin
If BtBCD.Down = True then Application.HelpContext(4300);
If BtBCDIO.Down = True then Application.HelpContext(4400);
If BtAnalogIO.Down = True then Application.HelpContext(4500);
If BtEncoder.Down = True then Application.HelpContext(4600);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -