'********************************************************************* '* * '* QuickBASIC SAMPLE 1:QSAMPLE1.BAS * '* * '* AD12-8 Demonstration Data Acquisition Program * '* * '* This program demonstrates the following: * '* - How to initialize and configure the AD12-8 driver * '* - Examples of error handling. * '* - How to program the 8 A/D channels to scale the input * '* counts for 0 to 10000 counts which is -5.000 to 5.000 volts. * '* - How to scan the 8 A/D channels and do a simple presen- * '* tation of the data on the screen. * '********************************************************************* ' Dimension the parameter passing variables. DIM TASK%, STAT%, PARAM%(5) ' Dimension some buffers. You need data and point buffers. DIM DATBUF%(200), PNTBUF%(200) ' Place all arrays in same segment for use with driver in QB environment COMMON SHARED PARAM%(), DATBUF%(), PNTBUF%() ' This is the driver entry point declaration DECLARE SUB A12DRV (TASK%, BYVAL PARAM%, STAT%) DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) '--------------------------- ' Initialize Driver CLS PRINT "SAMPLE 1 AD12-8" PRINT PRINT "This sample will display the eight analog inputs, in volts." PRINT : PRINT Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT PRINT "Done." PRINT : PRINT : PRINT PRINT "Board Configuration:" PRINT PRINT " -- BASE ADDRESS: "; HEX$(Address%); " hex" PRINT " -- RANGE: 5 volt range (required)" PRINT " -- POLARITY: Bipolar (required)" PRINT " -- All remaining jumper settings are irrelevant." PRINT : PRINT : PRINT PRINT "Please press return to continue."; INPUT "", xx$ TASK% = 0 PARAM%(1) = 1 'manual initialization mode PARAM%(2) = Address% '<- assigning Base Address PARAM%(3) = 3 'interrupt number is 3 PARAM%(4) = 5 '5 volt range PARAM%(5) = 1 'Bipolar mode GOSUB handler 'program the base address and int # ' 'Create small delay for fast computers ' TASK% = 11 PARAM%(1) = 5 PARAM%(2) = 10 GOSUB handler '-------------------------------------- 'setup driver to scale counts to volts '-------------------------------------- FOR I = 0 TO 7 TASK% = 10 PARAM%(1) = 3 PARAM%(2) = I * 16 PARAM%(3) = -5000 PARAM%(4) = 5000 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 8 channels. ' ' The data is transferred from the driver buffers to the BASIC ' buffers and displayed. Since the driver will place the actual ' count transferred in the fourth parameter, we will loop through ' the transfers until all of the data has been displayed. '--------------------------------------------------------------- TASK% = 8 PARAM%(1) = VARPTR(DATBUF%(1)) PARAM%(2) = VARPTR(PNTBUF%(1)) PARAM%(3) = 8 '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" ROW = ROW + 1 LOCATE ROW, COL: PRINT "--- -------" ROW = ROW + 1 FOR I = 0 TO 7 CH = (PNTBUF%(I + 1) AND &HFF00) / 4096 DAT = DATBUF%(I + 1) * .001 LOCATE ROW + I, COL: PRINT USING " # ###.### V"; CH; DAT NEXT I '----------------------- 'Wait for the operator. '----------------------- LOCATE ROW + 10, 10 PRINT "Press any key to rescan for 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 A12DRV(TASK%, VARPTR(PARAM%(1)), STAT%) IF STAT% THEN PRINT "TASK"; TASK%; "has error code"; STAT% DO PRINT "Try to continue with 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