uses Crt, CommDrv; function AskForBaseAddress(OldOne : String) : Word; const Msg : string[3] = '0'; var NewOne, Success, Dummy, Error : Word; AddrInputPosX, AddrInputPosY : Word; begin if (OldOne = 'OLD') then OldOne := Msg; WriteLn('Please enter the Base Address (100-3F8) for your card (in hex)'); WriteLn('or press ENTER for ', OldOne, '. '); Write('>'); AddrInputPosX := WhereX; AddrInputPosY := WhereY; Success := 0; repeat GotoXY(AddrInputPosX, AddrInputPosY); ClrEol; Readln(Msg); Val('$' + Msg, NewOne, Error); if ((NewOne <= $3F8) AND (NewOne >= $100)) then begin Success := 1; Dummy := NewOne; end else if (Msg = '') then begin GotoXY(AddrInputPosX, AddrInputPosY); WriteLn(OldOne); Msg := OldOne; Success := 1; Val('$' + Msg, Dummy, Error); end; until (Success = 1); AskForBaseAddress := Dummy; end; Var Address : word; procedure displayData; var Done : boolean; MyStr, MyStr2, tempStr : string; Loop, Start : byte; Value, Value2 : longint; ErrorL : integer; begin WriteLn; WriteLn('The data being read from the pod is displayed below.'); WriteLn; WriteLn('Press a key to finish the program . . .'); while (NOT KeyPressed) do begin WritePod(Address, 'A0'); Done := FALSE; while (NOT Done) do begin ReadPod(Address, MyStr); Done := (MyStr <> '') AND (MyStr[1] <> #7); { if error, then conversions not done } end; WritePod(Address, 'A1'); Done := FALSE; while (NOT Done) do begin ReadPod(Address, MyStr2); Done := (MyStr2 <> '') AND (MyStr2[1] <> #7); { if error, then conversions not done } end; MyStr[1]:='$'; {replace '=' with '$'} MyStr2[1]:='$';{replace '=' with '$'} Val(MyStr,Value,ErrorL); Val(MyStr2,Value2,ErrorL); GotoXY(15, 16); Writeln('Channel 0: ',(((10/16777216)*Value)-5.0):6:3); GotoXY(15, 18); Writeln('Channel 1: ',(((10/16777216)*Value2)-5.0):6:3); end; end; procedure errorfunc; begin clrscr; WriteLn('The system has been unable to establish communications with the pod.'); WriteLn('Press a key to exit program'); ReadKey; end; Var loop : boolean; MyStr : string; ErrorL : integer; str : string; dummy : char; tempStr : string; counter : integer; BEGIN ClrScr; WriteLn; WriteLn('RAD242 Sample Program'); WriteLn; WriteLn('The card must be configured as follows:'); WriteLn(' RAD242 is set at address 00'); WriteLn(' Communications is at 9600 bps'); WriteLn(' Base address of COM card is configureable'); WriteLn; WriteLn('Press ENTER to continue . . .'); ReadLn; gotoxy(1,14); Address := AskForBaseAddress('300'); while (PortW[Address] = $FFFF) do begin GotoXY(1, 21); writeln('Your card was not located at the assigned Base Address. Please re-enter.'); writeln('Press ENTER to continue or ESC to exit.'); dummy := Readkey; if (dummy = #27) then exit; gotoxy(1,21); clreol; gotoxy(1,22); clreol; gotoxy(1,14); Address := AskForBaseAddress('OLD'); end; ClrScr; WritePod(Address, 'CSR?'); ReadPod(Address, tempStr); WriteLn ('Sending CSR = 01, writing to the channel sample ratio'); WritePod(Address, 'CSR=01'); ReadPod(Address, str); WriteLn('There will be a delay of several seconds while the chip initializes'); delay(5000); loop := False; WriteLn; WriteLn('Sending CONTROL=208146, writing to the AD7710 control register'); WritePod(Address, 'CONTROL=208146'); ReadPod(Address, str); counter := 0; while ((loop = False) AND (counter <> 5)) do begin counter := counter + 1; WritePod(Address, 'CONTROL?'); ReadPod(Address, str); if (str[1] = '0') then loop := True; end; if (counter = 5) then begin errorfunc; exit; end; WriteLn('Reading the AD7710 control register'); WriteLn(''); WriteLn('Sending CONTROL=208146, writing to the AD7710 control register'); loop := False; WritePod(Address, 'CONTROL=228146'); ReadPod(Address, str); counter := 0; while ((loop = False) AND (counter <> 5)) do begin counter := counter + 1; WritePod(Address, 'CONTROL?'); ReadPod(Address, str); if (str[1] = '0') then loop := True; end; if (counter = 5) then begin errorfunc; exit; end; Writeln('Reading the AD7710 control register'); initCommCard(Address, 9600); { initialize the comm card } displayData; tempStr := 'CSR='+tempStr; WritePod(Address, tempStr); ReadPod(Address, str); ClrScr; WriteLn('Exiting Sample 1 . . .'); END. { main program }