{***************************************************************************** * PASCAL LANGUAGE SAMPLE 1: SAMPLE1.PAS * * * * This is a demonstration program to be used with the AD12-8G A/D board. * * Program will display channels of data polled from the board using the * * A12GDRV driver module supplied with the board. This sample expects that * * a sub-multiplexer board with programmable gains is attached to channel 0. * * The driver uses the three counters to set the gain on the mux board. * * * * LAST MODIFICATION: 2/4/98 * * * *****************************************************************************} program startup; {$L a12gdrv} { link the driver module } {$F+} { force far calls } USES crt; type param_array = array[1..5] of integer; dat_array = array[1..200] of integer; pnt_array = array[1..200] of word; { all of the parameters passed to the A12GDRV 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; 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 a12gdrv(t_off:word;p_off:word;st_off:word);external; {*************************************************************************** * PROCEDURE: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver package. * * * * INPUT: None. * * * * CALLS: A12GDRV - entry point to driver package. * * * * OUTPUT: None. * * * ***************************************************************************} procedure call_driver; Var Char_Input : char; begin { this section extracts the offset of the parameters that we will pass to the assembly driver } a12gdrv(ofs(task),ofs(params[1]),ofs(status)); { this section checks for an error code } if status > 0 then begin WriteLn('TASK ',task,' has returned an error code of ',status,'.'); WriteLn('Press ''C'' to continue, any other key to exit.'); Char_Input := UpCase(Readkey); If Char_Input = 'C' Then status := 0; end; end; { call_driver } {************************************************************************** * PROCEDURE: setup -- local routine * * * * PURPOSE: Sets up the driver package with the first 17 point addresses* * and sets the gain code first 8 point addresses to a value * * equal to the point address. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: None. * * * **************************************************************************} procedure setup; var I :integer; Address :word; begin ch := ' '; ClrScr; WriteLn(' SAMPLE1.PAS : DEMONSTRATION DATA ACQUISITION'); WriteLn; WriteLn('This is a demonstration program to be used with the AD12-8G A/D board.'); WriteLn('Program will display channels of data polled from the board using the'); WriteLn('A12GDRV driver module supplied with the board. The driver uses the'); WriteLn('three counters to set the gain on the mux board.'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- Sub-multiplexer board with programmable'); WriteLn(' gains attached to channel 0. (required)'); WriteLn(' -- All remaining jumper settings are irrelevant.'); WriteLn; WriteLn; WriteLn; WriteLn; WriteLn('Press any key to run the program'); while not keypressed do; ch := readkey; task := 0; params[1] := Address; { starting board address } params[2] := 5; { IRQ5 - does not matter in this sample} params[3] := 1; { programmable gain } call_driver; { call routine to call ext module } if status <> 0 then exit; { now reset the task list } task := 11; params[1] := 2; call_driver; { call routine to call ext module } if status <> 0 then exit; { install first 17 point address to point list } task := 5; params[1] := 0; params[2] := 16; call_driver; { call routine to call ext module } if status <> 0 then exit; { set gain codes, channel 0 = gain code 0 etc } task := 4; for I:= 0 to 7 do begin params[1] := I; params[2] := I; params[3] := I; call_driver; if status <> 0 then exit; end; { set the driver settle time count } task := 11; params[1] := 4; params[2] := 25; call_driver; { call routine to call ext module } if status <> 0 then exit; end; { setup } {************************************************************************** * PROCEDURE: get_readings -- local routine * * * * PURPOSE: Reads the 17 points in the point list. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: None. * * * **************************************************************************} procedure get_readings; var channel,I,gaincode :integer; begin { now reset the task list index } task := 11; params[1] := 1; call_driver; { call routine to call ext module } if status <> 0 then exit; task := 8; params[1] := ofs(datbuf[1]); { offset to data buffer } params[2] := ofs(pntbuf[1]); { offset to point bufffer } params[3] := 17; { make 17 readings from point list } params[4] := 0; { number of samples returned here } call_driver; if status <> 0 then exit; { now if OK list the data to the screen } ClrScr; WriteLn; WriteLn(' CHANNEL VALUE GAIN'); WriteLn(' ------- ------ ----'); for I := 1 to params[4] do begin channel := (pntbuf[I] and $ff00) div 256; { upper bits are ch number } gaincode := (pntbuf[I] and $00FF); WriteLn(channel:10,datbuf[I]:12,gaincode:7); { The subtraction performed in the above line is the bipolar offset } end; end; { get_readings } { MAIN PROGRAM } BEGIN setup; { set up program and the driver } while (status = 0) and (upcase(ch)<>'E') do begin get_readings; { display current values } 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 the data...'); ch:=readkey; { wait for key press } end; end; END. { main program }