'********************************************************************* '* * '* QuickBASIC SAMPLE 1:QSAMPLE1.BAS * '* * '* AD12-8G Demonstration Data Acquisition Program * '* * '* This program demonstrates the following: * '* - How to initialize and configure the AD12-8G driver * '* - How to scan the A/D channels and do a simple presentation * '* of the data on the screen. * '* * * '* MODIFIED: 2/3/98 * '********************************************************************* ' Dimension the parameter passing variables. DIM TASK%, STAT%, PARAM%(5) ' Dimension some buffers. You need data and point buffers. DIM DATBUF%(200), PNTBUF%(200) COMMON SHARED PARAM%, DATBUF%, PNTBUF% ' This is the driver entry point declaration DECLARE SUB A12GDRV (TASK%, BYVAL PARAM%, STAT%) DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) '----------------------------- 'Ask for the Base Address '----------------------------- CLS PRINT " QSAMPLE1.BAS : AD12-8G DEMONSTRATION DATA ACQUISITION " PRINT PRINT "This is a demonstration program to be used with the AD12-8G A/D" PRINT "board. The program will display channels of data polled from the" PRINT "board using the A12GDRV driver module supplied with the board. The" PRINT "driver uses the three counters to set the gain on the mux board." PRINT PRINT Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT PRINT "Board Configuration:" PRINT PRINT " -- Base address is "; HEX$(Address%); " hex" PRINT " -- IRQ5 is used for interrupts (required)" PRINT " -- Sub-multiplexer board with programmmable" PRINT " gains is attached to channel 0 (required)" PRINT " -- All remaining jumper settings are irrelevant" PRINT : PRINT : PRINT : PRINT PRINT "Press ENTER to scan the data" INPUT ""; Msg$ '--------------------------- ' Initialize Driver TASK% = 0 PARAM%(1) = Address% '<- assign the base address. PARAM%(2) = 5 'interrupt number is 5 - has no effect on this sample PARAM%(3) = 1 'programmable gains on the sub-multiplexer GOSUB handler 'program the base address and int # '-------------------- 'reset the point list '-------------------- TASK% = 11 PARAM%(1) = 2 GOSUB handler '---------------------------------------------------- 'place the first 17 point addresses in the point list '---------------------------------------------------- TASK% = 5 PARAM%(1) = 0 PARAM%(2) = 16 GOSUB handler '-------------------------------------------------------- 'setup driver to use gain for first eight point addresses '-------------------------------------------------------- TASK% = 4 FOR I = 0 TO 7 PARAM%(1) = I PARAM%(2) = I PARAM%(3) = I GOSUB handler NEXT I C$ = " " DO UNTIL C$ = CHR$(27) TASK% = 11 'TASK 11 PARAM%(1) = 1 'reset the point list index back to 0 GOSUB handler '--------------------------------------------------------------- ' Get and display 17 channels. ' ' The data is transfered from the driver buffers to the BASIC ' buffers and displayed. Since the driver will place the actual ' count transfered in the fourth parameter, we will loop thru ' the transfers until all of the data has been displayed. '--------------------------------------------------------------- TASK% = 8 PARAM%(1) = VARPTR(DATBUF%(1)) PARAM%(2) = VARPTR(PNTBUF%(1)) PARAM%(3) = 17 'requested # of samples PARAM%(4) = 0 'actual # of samples returned here GOSUB handler 'call driver CLS ROW = 5 COL = 10 LOCATE ROW, COL: PRINT " CH DATA GAIN" ROW = ROW + 1 LOCATE ROW, COL: PRINT "--- ------ ----" ROW = ROW + 1 FOR I = 1 TO PARAM%(4) CH = (PNTBUF%(I) AND &HFF00) / 256 GAIN = PNTBUF%(I) AND &HFF DAT = DATBUF%(I) LOCATE ROW + I, COL: PRINT USING "### ##### #"; CH; DAT; GAIN NEXT I '----------------------- 'Wait for the operator. '----------------------- LOCATE ROW + 18, 10 PRINT "Press any key to rescan the data; press the [Esc] key to Quit"; C$ = INPUT$(1) LOOP END '************************************************************* ' DRIVER HANDLER ' ' This following section of code will call the driver for you ' handling the argument passing convention, then check the ' status after it returns and provide a couple of options if ' there was an error. '************************************************************* handler: STAT% = 0 CALL A12GDRV(TASK%, VARPTR(PARAM%(1)), STAT%) IF STAT% THEN PRINT "TASK"; TASK%; "has error code"; STAT% DO PRINT "Try to continue with the program or Exit (C/E)"; INPUT ans$ ans$ = UCASE$(ans$) IF ans$ = "C" THEN EXIT DO IF ans$ = "E" THEN END LOOP END IF RETURN FUNCTION AskForBaseAddress (OldOne AS INTEGER) Msg$ = "" NewOne% = 0: Success = 0: Dummy% = 0 AddrInputPosX = 0: AddrInputPosY = 0 PRINT "Please enter the Base Address (0000-FFFF) for your card (in hex)" PRINT "or press ENTER for "; HEX$(OldOne%); "." PRINT ">"; AddrInputPosX = POS(0): AddrInputPosY = CSRLIN WHILE Success = 0 LOCATE AddrInputPosY, AddrInputPosX PRINT " " LOCATE AddrInputPosY, AddrInputPosX LINE INPUT Msg$ NewOne% = VAL("&H0" + LEFT$(Msg$, 4)) Success = 1 Dummy% = NewOne% IF (Msg$ = "") THEN LOCATE AddrInputPosY, AddrInputPosX PRINT HEX$(OldOne%) Success = 1 Dummy% = OldOne% END IF WEND AskForBaseAddress = Dummy% END FUNCTION