uses Crt, CommDrv; function AskForBaseAddress(OldOne : String) : Word; const Msg : string[4] = '0'; var NewOne, Success, Dummy, Error : Word; AddrInputPosX, AddrInputPosY : Word; begin if (OldOne = 'OLD') then OldOne := Msg; WriteLn('Please enter the Base Address (0000-FFFF) for your com card (in hex)'); WriteLn('or press ENTER for ', OldOne, '. '); Write('>'); AddrInputPosX := WhereX; AddrInputPosY := WhereY; repeat GotoXY(AddrInputPosX, AddrInputPosY); ClrEol; Readln(Msg); Val('$' + Msg, NewOne, Error); if (error=0) 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; { end of AskForBaseAddress } Var Address : word; procedure printCurrentPointList; var Loop : byte; inst : byte; MyStr : String; begin ClrScr; WriteLn; WriteLn('The current point list configuration for channels 0-15 is : '); for Loop := 0 to 15 do begin if Loop < 10 then { skip over ascii chars between 9 and A } inst := Loop + 48 else inst := Loop + 55; WritePod(Address, 'PL0' + Chr(inst) + '?'); { Ask pod } ReadPod(Address, MyStr); { save response } Write(' ', MyStr); end; WriteLn; WriteLn; end; procedure changePointList; var Loop : byte; inst : byte; MyStr : String; begin WriteLn; WriteLn('Changing point list to acquire all even channels, then all odd . . .'); for Loop := 0 to 7 do begin { even } MyStr := ''; { adding 48 turns a number into equivalent ASCII char } MyStr := 'PL0'+Chr(Loop + 48)+'=0'+Chr((Loop*2) + 48)+'0000'; WritePod(Address, MyStr); { tell pod } Write(MyStr, ', '); ReadPod(Address, MyStr); { save response } { odd } if Loop < 2 then inst := Loop + 56 else inst := Loop + 63; MyStr := ''; { adding 48 turns a number into equivalent ASCII char } { place channels in bipolar, -5V to +5V range } MyStr := 'PL0'+Chr(inst)+'=0'+Chr((Loop*2)+1+48)+'0000'; 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-0F,0008'); { convert CH0-CH15, 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 15 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 <= 7) 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('RA1216 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(' RA1216 is set at address 00'); } WriteLn('--Communications is at 28800 bps'); WriteLn('--Base address of RS422 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, 28800); { initialize the comm card } printCurrentPointList; changePointList; displayData; ClrScr; WriteLn('Exiting Sample 1 . . .'); END. { main program }