{*************************************************************************** * PASCAL LANGUAGE SAMPLE 1: SAMPLE1.PAS * * * * This is a demonstration program to be used with the AIO8 A/D card. * * The program will display sixteen channels of data polled from the * * card using the AIO8DRV.OBJ driver module supplied with the card. * * * * LAST MODIFICATION: 2/4/98 * * * ***************************************************************************} Program startup; {$L aio8drv} {$F+} USES crt; type param_array = array[1..5] of integer; dat_array = array[1..20] of integer; pnt_array = array[1..20] of word; { all of the parameters passed to the AIO8DRV driver must be declared globally, including the buffers which have their offset passed inside the params array } var task,status : integer; params : param_array; ch : char; pntbuf : pnt_array; datbuf : dat_array; procedure aio8drv(t_off:word;p_off:word;st_off:word);external; 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 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 } {*************************************************************************** * PROCEDURE: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver module. * * * * INPUT: None. * * * * CALLS: aio8drv - entry point to driver module. * * * * OUTPUT: None. * * * ***************************************************************************} procedure call_driver; var t_off,p_off,st_off : word; begin { this section extracts the offset of the parameters that we will pass to the assembly driver } t_off := ofs(task); p_off := ofs(params[1]); st_off := ofs(status); status := 0; aio8drv(t_off,p_off,st_off); { this section checks for an error code } if status > 0 then begin WriteLn('A status error code of ',status,' was detected.'); WriteLn('Program terminated.'); end; end; { call_driver } {************************************************************************** * PROCEDURE: setup -- local routine * * * * PURPOSE: Sets up the driver module. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver module. * * * * OUTPUT: None. * * * **************************************************************************} procedure setup; var Address:word; begin ClrScr; WriteLn(' Sample 1 : AIO8'); WriteLn; WriteLn('This sample reads sixteen analog inputs from the AIO8 and AIM-16 '); WriteLn('and displays them for you.'); WriteLn; WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- Jumper EXT should be installed (required)'); WriteLn(' -- Jumper IRQ5 should be installed (required)'); WriteLn(' -- All remaining jumper settings are irrelevant.'); WriteLn; WriteLn; WriteLn; WriteLn; WriteLn('Please press ENTER to continue.'); ReadLn; task := 0; params[1] := Address; { starting board address } params[2] := 1; { manual initialization } params[3] := 0; { AIM-16 programmable gains } call_driver; { call routine to call ext module } if status = 0 then begin { clear the point list } task := 11; params[1] := 2; call_driver; { call routine to call ext module } { assign the first 16 point addresses to the point list } task := 5; params[1] := 0; params[2] := 15; call_driver; { call routine to call ext module } { assign point address 0 as a reference junction } task := 10; params[1] := 2; params[2] := 0; { point address 0 } params[3] := 84; { ascii 'T', assign as reference junction } params[4] := 70; { ascii 'F', use degrees F as temperature units } call_driver; { call routine to call ext module } { assign point address 1 as a t type thermocouple } task := 10; params[1] := 2; params[2] := 1; { point address 1 } params[3] := 116; { ascii 't', assign as t thermocouple } params[4] := 70; { ascii 'F', use degrees F as temperature units } call_driver; { call routine to call ext module } { assign gain code of 5 (200) to point address 1, required for t thermocouple } task := 4; params[1] := 1; params[2] := 1; params[3] := 5; call_driver; { call routine to call ext module } end; { assign a sample and hold settle time } task := 11; params[1] := 5; params[2] := 25; call_driver; end; { setup } {************************************************************************** * PROCEDURE: get_readings -- local routine * * * * PURPOSE: Reads 16 points and displays them on the screen. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver module. * * * * OUTPUT: None. * * * **************************************************************************} procedure get_readings; var channel,I,gain :integer; data :real; begin { now reset the task list index } task := 11; params[1] := 1; call_driver; { call routine to call ext module } if status = 0 then begin task := 8; params[1] := ofs(datbuf[1]); { offset to data buffer } params[2] := ofs(pntbuf[1]); { offset to point bufffer } params[3] := 16; { make 16 readings from point list } params[4] := 0; { number of samples returned here } call_driver; if status = 0 then begin {if status > 0 then error } { now if OK list the data to the screen } ClrScr; WriteLn; WriteLn(' CHANNEL VALUE GAIN'); WriteLn(' ------- ------ ----'); for I := 1 to 16 do begin channel := (pntbuf[I] and $FF00) div 256; { upper bits are ch number } gain := pntbuf[I] and $FF; { lower bits are gain } data := datbuf[I] * 0.1; { scale } WriteLn(channel:10,data:12:3,gain:7); end; end; end; end; { get_readings } {************************************************************************** * PROCEDURE: main -- local routine * * * * PURPOSE: Controls program flow, detects when user is ready to exit. * * * * INPUT: None. * * * * CALLS: setup - set up program and drivers. * * get_readings - read the A/D channels and display. * * * * OUTPUT: None. * * * **************************************************************************} BEGIN ch := ' '; setup; { set up program and the driver } while (status = 0) and (ch <> 'E') and (ch <> 'e') do begin get_readings; { display current values for the 16 channels } if status = 0 then begin { if status > 0 then error } { check for program exit } WriteLn; WriteLn('Press E to exit the program. Press any other key to rescan for data...'); ch:=readkey; { wait for key press } end; end; END. { main program }