DECLARE SUB sdadigin (in0%, in1%, in2%, out0%, out1%, out2%) DECLARE SUB sdadigout (line0%, line1%, line2%) DECLARE SUB sdagetnv (n%, v!) DECLARE SUB sdainit () DECLARE SUB rs232close () DECLARE SUB rs232inbyte (byte$) DECLARE SUB rs232init () DECLARE SUB rs232out (msg$) DECLARE SUB rs232queuelen (nbytes%) DECLARE SUB rs232setpar (portnum$, baudrate$, parity$, ndatabits$, nstopbits$, specifics$) DECLARE SUB sdaget11v (v11!()) '**************************************************************************** 'Module 232SDA12 'This module contains I/O subroutines for the B&B 232SDA12 data acquisition 'module. ' 'Zachary Wolf '12/21/96 '**************************************************************************** 'Keep shared parameters in a common block COMMON SHARED /sda/ xx$ 'Semi-permanent parameters CONST refposP! = 5! CONST refnegP! = 0! CONST nadcstepsP% = 4095 SUB sdadigin (in0%, in1%, in2%, out0%, out1%, out2%) '**************************************************************************** 'This subroutine reads the three digital input lines and the states of the 'three digital output lines of the B&B 232SDA12. ' 'Output: ' in0%, input line 0 state, 0 or 1 ' in1%, input line 1 state, 0 or 1 ' in2%, input line 2 state, 0 or 1 ' out0%, output line 0 state, 0 or 1 ' out1%, output line 1 state, 0 or 1 ' out2%, output line 2 state, 0 or 1 ' 'Zachary Wolf '12/23/96 '**************************************************************************** 'Clear the input buffer CALL rs232queuelen(nbytes%) IF nbytes% > 0 THEN FOR i% = 1 TO nbytes% CALL rs232inbyte(a$) NEXT i% END IF 'Send the command to read the lines CALL rs232out("!0RD") 'Wait until the 232SDA12 is finished t0# = TIMER DO CALL rs232queuelen(nbytes%) IF nbytes% = 1 THEN EXIT DO IF TIMER > t0# + .5 THEN BEEP PRINT "The 232sda12 is not responding." CALL rs232close STOP END IF LOOP 'Read the input byte CALL rs232inbyte(byte$) 'Convert the ASCII character to an integer representing the line values value% = ASC(byte$) 'PRINT value% 'Extract the line values out0% = value% AND 1 out1% = value% AND 2 out2% = value% AND 4 in0% = value% AND 8 in1% = value% AND 16 in2% = value% AND 32 'Convert to 1s and 0s IF out0% <> 0 THEN out0% = 1 IF out1% <> 0 THEN out1% = 1 IF out2% <> 0 THEN out2% = 1 IF in0% <> 0 THEN in0% = 1 IF in1% <> 0 THEN in1% = 1 IF in2% <> 0 THEN in2% = 1 END SUB SUB sdadigout (line0%, line1%, line2%) '**************************************************************************** 'This subroutine sets the three digital output lines of the B&B 232SDA12. ' 'Input: ' line0%, line 0 output, 0 or 1 ' line1%, line 1 output, 0 or 1 ' line2%, line 2 output, 0 or 1 ' 'Zachary Wolf '12/23/96 '**************************************************************************** 'Check the input values IF line0% <> 0 AND line0% <> 1 THEN PRINT "SDADIGOUT: improper line value" EXIT SUB END IF IF line1% <> 0 AND line1% <> 1 THEN PRINT "SDADIGOUT: improper line value" EXIT SUB END IF IF line2% <> 0 AND line2% <> 1 THEN PRINT "SDADIGOUT: improper line value" EXIT SUB END IF 'Form the numerical value corresponding the the line values value% = line2% * 4 + line1% * 2 + line0% 'Get the ASCII character corresponding to value% ascii$ = CHR$(value%) 'Send the command CALL rs232out("!0SO" + ascii$) END SUB SUB sdaget11v (v11!()) '**************************************************************************** 'This subroutine gets the voltage from each of the 11 A/D channels 'of the B&B 232sda12. It assumes the + reference is at 5 V and the '- reference is at 0 V. ' 'Output: ' v11!(0 to 10), the voltage from each channel ' 'Zachary Wolf '12/21/96 '**************************************************************************** 'Clear the input buffer CALL rs232queuelen(nbytes%) IF nbytes% > 0 THEN FOR i% = 1 TO nbytes% CALL rs232inbyte(a$) NEXT i% END IF 'Tell the 232SDA12 to measure the voltage on all channels CALL rs232out("!0RA" + CHR$(10)) 'Wait until the 232SDA12 is finished t0# = TIMER DO CALL rs232queuelen(nbytes%) IF nbytes% = 22 THEN EXIT DO IF TIMER > t0# + .5 THEN BEEP PRINT "The 232sda12 is not responding." CALL rs232close STOP END IF LOOP 'Get the 11 digitized values DIM digval%(0 TO 10) FOR i% = 10 TO 0 STEP -1 CALL rs232inbyte(byte$) hibyte% = ASC(byte$) msb% = hibyte% * 256 CALL rs232inbyte(byte$) lobyte% = ASC(byte$) lsb% = lobyte% digval%(i%) = msb% + lsb% NEXT i% 'Apply a calibration to get the voltages cal! = (refposP! - refnegP!) / nadcstepsP% FOR i% = 0 TO 10 v11!(i%) = cal! * digval%(i%) NEXT i% END SUB SUB sdagetnv (n%, v!) '**************************************************************************** 'This subroutine gets the voltage from channel n of the B&B 232sda12. ' 'Input: ' n%, channel number to read the voltage from, 0 to 10 ' 'Output: ' v!, the voltage from channel n% ' 'Zachary Wolf '12/21/96 '**************************************************************************** 'Get the voltages from all the channels DIM v11!(0 TO 10) CALL sdaget11v(v11!()) 'Return the desired voltage v! = v11!(n%) END SUB SUB sdainit '**************************************************************************** 'This subroutine initializes the B&B 232SDA12. ' 'Zachary Wolf '12/21/96 '**************************************************************************** 'Leave time for power up if the RS232 port is supplying power SLEEP 1 'Clear the input RS232 buffer CALL rs232queuelen(nbytes%) IF nbytes% > 0 THEN FOR i% = 1 TO nbytes% CALL rs232inbyte(a$) NEXT i% END IF 'Take an initial measurement of the voltage on all channels CALL rs232out("!0RA" + CHR$(10)) 'Wait until the 232SDA12 is finished t0# = TIMER DO CALL rs232queuelen(nbytes%) IF nbytes% = 22 THEN EXIT DO IF TIMER > t0# + .5 THEN BEEP PRINT "The 232sda12 is not responding." CALL rs232close STOP END IF LOOP 'Collect the 11 digitized values FOR i% = 10 TO 0 STEP -1 CALL rs232inbyte(byte$) CALL rs232inbyte(byte$) NEXT i% END SUB SUB sdatest '**************************************************************************** 'This subroutine is used to perform quick tests on the B&B 232SDA12. ' 'Zachary Wolf '12/21/96 '**************************************************************************** 'Open RS232 communications portnum$ = "2" baudrate$ = "9600" parity$ = "N" ndatabits$ = "8" nstopbits$ = "1" specifics$ = "CD,DS" CALL rs232setpar(portnum$, baudrate$, parity$, ndatabits$, nstopbits$, specifics$) CALL rs232init 'Initialize the 232SDA12 CALL sdainit 'Analog only 'GOTO analogonly 'Set the digital output lines line0% = 1 line1% = 0 line2% = 1 CALL sdadigout(line0%, line1%, line2%) 'Display the digital input lines CLS DO IF INKEY$ = CHR$(27) THEN EXIT DO CALL sdadigin(in0%, in1%, in2%, out0%, out1%, out2%) LOCATE 5, 1 PRINT "Output 0, 1, 2 states: "; out0%; ", "; out1%; ", "; out2% PRINT "Input 0, 1, 2 states: "; in0%; ", "; in1%; ", "; in2% LOOP analogonly: 'Print all 11 voltages to the screen DIM v11!(0 TO 10) CLS DO IF INKEY$ = CHR$(27) THEN EXIT DO CALL sdaget11v(v11!()) LOCATE 5, 1 FOR i% = 0 TO 10 PRINT USING " #.###"; v11!(i%); NEXT i% PRINT LOOP 'Display a temperature CLS DO IF INKEY$ = CHR$(27) THEN EXIT DO CALL sdagetnv(1, v!) tc! = v! / .01 tf! = tc! * 9 / 5 + 32! LOCATE 5, 1 PRINT USING "T = ###.## C"; tc!; PRINT USING " = ###.## F"; tf! LOOP END SUB