{*************************************************************************** * PASCAL LANGUAGE SAMPLE 3: SAMPLE3.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. * * This sample is identical to sample1 with the exception that auto * * initialization is used. Thus you can see the difference in the amount * * of code when you do the setup yourself. * * * * 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; {*************************************************************************** * 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; begin clrscr; writeln(' Sample 3 : AIO8'); writeln; writeln('This sample reads sixteen analog inputs from the AIO8 and AIM-16 '); writeln('and displays them for you.'); writeln; writeln('Board Configuration Requirements:'); writeln; writeln(' -- BASE ADDRESS: as assigned in SETUP.CFG file'); writeln(' -- All needed jumper settings are explained in SETUP.CFG file'); writeln; writeln; writeln; writeln('Please press ENTER to continue.'); readln; task := 0; params[2] := 0; { auto initialization } call_driver; { call routine to call ext module } { 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 from the point list displays them. * * * * 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 { display current values for the 8 channels } get_readings; 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 }