{****************************************************************************} {* This program was built with parts of a terminal program. *} {* The setup for the 5141 was commented out. I had a difficult time trying *} {* to get the 5141 to work with this program. Instead I set it up using *} {* a terminal emulator, then ran this program. *} {* *} {* *} {* *} {* *} {* *} {* *} {* *} {* *} {* *} {* *} {* *} {****************************************************************************} {****************************************************************************} {* TERMINAL.PAS *} {* version 1.03 *} {* *} {* - Turbo Pascal program that emulates a dumb terminal. *} {* *} {* - Compatible with Turbo Pascal versions 4.0 or greater. *} {* *} {* - Uses standard Turbo Pascal CRT and DOS units along with RS_232 *} {* unit supplied on disk. *} {* *} {* - Revision list: *} {* 1.00 11/30/89 Release date *} {* 1.01 03-24-90 Fix parity selection bug *} {* 1.02 12-14-90 Eliminated extra communications variables. *} {* Comm. variables are now PUBLIC from RS_232.TPU *} {* - 1.03 06-01-94 Addition of 57.6K and 115.2K baud rates *} {* *} {* - Copyright Dutile, Glines & Higgins Corporation (c) 1989,95 *} {****************************************************************************} {$U+,I+,C-} {$M 20000,0,655360} Uses Crt, Dos, RS_232; Type ADC_REC = RECORD Direction : Char; StepNumber: Integer; Channel1 : REAL; Channel2 : REAL; Channel3 : REAL; END; Const BaudRates : Array[1..10] of String[6]=('300 ', '600 ', '1200 ', '2400 ', '4800 ', '9600 ', '19200 ', '38400 ', '57.6K ', '115.2K'); ComPorts : Array[1..2] of String[5]=('COM1:', 'COM2:'); Paritys : Array[1..7] of String[5]=('ODD ', '', 'EVEN ', 'NONE ', 'MARK ', '', 'SPACE'); Var KeyBd : Char; {Used to Tx and Rx data} LocalEcho : Boolean; {True to Echo Keyboard characters} InString : String[50]; ADC_VAL : ADC_REC; ADCFILE : FILE OF ADC_REC; OUTFILE : TEXT; Code : Integer; Y : Integer; {***********************************************************************} Procedure ErrorMessage(N : Integer); { - Display Error Messages pertaining to window routines} Var Txt : String[80]; Begin Case N of 1 : Txt := 'Windows buffer full, can not add any more'; 2 : Txt := 'Attempt to erase window that does not exist, or out of range'; 3 : Txt := 'Cannot select an empty window, or value out of range'; 4 : Txt := 'Error Opening serial communications port'; End; Writeln(Txt); Readln; End; {***********************************************************************} Procedure SetupNF90; Begin Com := 2; If OpenCom(Com, Baud, Parity, DtBits, StBits) Then Begin Tx_String('F'); Tx_String('C'); Tx_String('S1M200'); Tx_String('A1M50'); KeyBd := Rx_Char; KeyBd := Rx_Char; KeyBd := Rx_Char; KeyBd := Rx_Char; CloseCom(Com); End Else Begin ErrorMessage(4); End; End; {***********************************************************************} Procedure SetupD5141; Begin Com := 1; If OpenCom(Com, Baud, Parity, DtBits, StBits) Then Begin Tx_String('$1WE'); InString := Rx_String; {Look for received characters} Tx_String('$1SU31026140'); InString := Rx_String; {Look for received characters} Tx_String('$1RR'); InString := Rx_String; {Look for received characters} Delay(500); Tx_String('$1WE'); InString := Rx_String; {Look for received characters} Tx_String('$1CZ'); InString := Rx_String; {Look for received characters} Tx_String('$2CZ'); InString := Rx_String; {Look for received characters} Tx_String('$3CZ'); InString := Rx_String; {Look for received characters} CloseCom(Com); End Else Begin ErrorMessage(4); End; End; {***********************************************************************} Procedure Step; Begin Com := 2; If OpenCom(Com, Baud, Parity, DtBits, StBits) Then Begin Tx_String('R'); KeyBd := Rx_Char; CloseCom(Com); End Else Begin ErrorMessage(4); End; End; {***********************************************************************} Procedure TowardMotor; Begin Com := 2; If OpenCom(Com, Baud, Parity, DtBits, StBits) Then Begin Tx_String('C'); Delay(500); Tx_String('I1M-400'); Delay(500); KeyBd := Rx_Char; KeyBd := Rx_Char; ADC_VAL.Direction:='F'; CloseCom(Com); End Else Begin ErrorMessage(4); End; End; {***********************************************************************} Procedure AwayFromMotor; Begin Com := 2; If OpenCom(Com, Baud, Parity, DtBits, StBits) Then Begin Tx_String('C'); Delay(500); Tx_String('I1M400'); Delay(500); KeyBd := Rx_Char; KeyBd := Rx_Char; ADC_VAL.Direction:='B'; CloseCom(Com); End Else Begin ErrorMessage(4); End; End; {***********************************************************************} Procedure ReadoutADC; Begin Com := 1; If OpenCom(Com, Baud, Parity, DtBits, StBits) Then Begin Tx_String('$1RD'); Delay(500); InString := Rx_String; {Look for received characters} Val(InString, ADC_VAL.Channel1, code); WRITELN(InString,' ',code,' ',ADC_VAL.Channel1); If Code <> 0 Then Writeln('Error in numeric conversion'); Tx_String('$2RD'); Delay(500); InString := Rx_String; {Look for received characters} Val(InString, ADC_VAL.Channel2, code); WRITELN(InString,' ',code,' ',ADC_VAL.Channel2); If Code <> 0 Then Writeln('Error in numeric conversion'); Tx_String('$3RD'); Delay(500); InString := Rx_String; {Look for received characters} Val(InString, ADC_VAL.Channel3, code); WRITELN(InString,' ',code,' ',ADC_VAL.Channel3); If Code <> 0 Then Writeln('Error in numeric conversion'); WRITELN(''); WRITE(ADCFILE,ADC_VAL); WRITELN(OUTFILE,Y:8,',',ADC_VAL.Channel1:8:3,',',ADC_VAL.Channel2:8:3,',',ADC_VAL.Channel3:8:3); CloseCom(Com); End Else Begin ErrorMessage(4); End; End; {***********************************************************************} {***********************************************************************} {***********************************************************************} Begin ASSIGN(ADCFILE,'DGH_ADC.DAT'); REWRITE(ADCFILE); ASSIGN(OUTFILE,'ADCASCII.DAT'); REWRITE(OUTFILE); WRITELN(OUTFILE,'STEP':8,'CHAN1':8,'CHAN2':8,'CHAN3':8); {***********************************************************************} Baud := 6; Parity := 5; DtBits := 3; StBits := 1; {***********************************************************************} SetupNF90; { SetupD5141;} AwayFromMotor; Y:=0; ADC_VAL.StepNumber:=0; Delay(15000); ReadoutADC; FOR Y := 1 TO 400 DO BEGIN Step; ADC_VAL.StepNumber:=Y; Delay(15000); ReadoutADC; END; TowardMotor; Y:=0; ADC_VAL.StepNumber:=0; Delay(15000); ReadoutADC; FOR Y := 1 TO 400 DO BEGIN Step; ADC_VAL.StepNumber:=Y; Delay(15000); ReadoutADC; END; {***********************************************************************} Com := 2; If OpenCom(Com, Baud, Parity, DtBits, StBits) Then Begin Tx_String('Q'); CloseCom(Com); End Else Begin ErrorMessage(4); End; {***********************************************************************} CLOSE(ADCFILE); CLOSE(OUTFILE); End.