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 printCurrentPointList; var Loop : byte; MyStr : String; begin ClrScr; WriteLn; WriteLn('The current point list configuration for channels 0-7 is : '); for Loop := 0 to 7 do begin Str(Loop, MyStr); { convert to strings } WritePod(Address, 'PL0' + MyStr + '?'); { Ask pod } ReadPod(Address, MyStr); { save response } Write(' ', MyStr); end; WriteLn; WriteLn; end; procedure changePointList; var Loop : byte; MyStr : String; begin WriteLn; WriteLn('Changing point list to acquire all even channels, then all odd . . .'); for Loop := 0 to 3 do begin { even } MyStr := ''; { adding 48 turns a number into equivalent ASCII char } { place channels in bipolar, -5V to +5V range } MyStr := 'PL0'+Chr(Loop + 48)+'=10'+Chr((Loop*2) + 48)+'0'; WritePod(Address, MyStr); { tell pod } Write(MyStr, ', '); ReadPod(Address, MyStr); { save response } { odd } MyStr := ''; { adding 48 turns a number into equivalent ASCII char } { place channels in bipolar, -5V to +5V range } MyStr := 'PL0'+Chr(Loop+4+48)+'=10'+Chr((Loop*2)+1+48)+'0'; WritePod(Address, MyStr); { tell pod } WriteLn(MyStr); ReadPod(Address, MyStr); { save response } end; WriteLn; WriteLn('Press ENTER to proceed . . .'); ReadLn; end; procedure displayData; var Done : boolean; MyStr, tempStr : string; Loop, Start : byte; Value : Integer; ErrorL : integer; begin ClrScr; WriteLn('The data being read from the pod is displayed below.'); WriteLn('Channels are as shown, the pod is actually acquiring'); WriteLn('the data in this order.'); WriteLn; WriteLn('Press a key to finish the program . . .'); while (NOT KeyPressed) do begin WritePod(Address,'AC00-07,0008'); { convert CH0-CH7, eight total } Done := FALSE; while (NOT Done) do begin WritePod(Address, 'R'); { attempt to read the data } ReadPod(Address, MyStr); Done := (MyStr <> '') AND (MyStr[1] <> #7); { if error, then conversions not done } end; for Loop := 0 to 7 do begin { parse the returned data } Start := (Loop * 7) + 3; tempStr := Copy(MyStr, Start, 4); { simply copy the 4 bytes we need } Val('$'+tempStr,Value,ErrorL); GotoXY(15, (Loop * 2) + 7); if (Loop <= 3) then Write('Channel ',(Loop*2),': ',((10/4096)*Value):6:3) else Write('Channel ',(((Loop-4)*2)+1),': ',((10/4096)*Value):6:3) end; end; end; Var Loop : byte; MyStr : string; ErrorL : integer; BEGIN ClrScr; WriteLn('RAG128 Sample Program'); WriteLn; WriteLn('This program will show you how to display and configure the'); WriteLn('point list to acquire data. First, the even channels'); WriteLn('are displayed, then the odds.'); WriteLn; WriteLn('The card must be configured as follows:'); WriteLn(' RAG128 is set at address 00'); WriteLn(' Communications is at 9600 bps'); WriteLn(' Base address of RS485 card is configureable'); WriteLn; WriteLn('Press ENTER to continue . . .'); ReadLn; Address := AskForBaseAddress('300'); while (Port[Address] = $FF) do begin GotoXY(1, 21); WriteLn('Your card was not located at the assigned Base Address. Please re-enter.'); GotoXY(1, 14); Address := AskForBaseAddress('OLD'); end; initCommCard(Address, 9600); { initialize the comm card } printCurrentPointList; changePointList; displayData; ClrScr; WriteLn('Exiting Sample 1 . . .'); END. { main program }