DECLARE SUB rs232in (msg$) DECLARE SUB rs232checkpar (ok$) '**************************************************************************** 'Module RS232 'This module contains I/O subroutines for RS232 communications. ' 'Zachary Wolf '12/21/96 '**************************************************************************** 'Keep shared parameters in a common block COMMON SHARED /rs232/ comfilenumP%, openparP$ SUB rs232checkpar (ok$) '**************************************************************************** 'This subroutine checks that all required parameters have been assigned 'values. ' 'Output: ' ok$, "y" if parameter assignments are ok, "n" otherwise ' 'Zachary Wolf '12/21/96 '**************************************************************************** 'Default value ok$ = "n" 'comfilenumP% IF comfilenumP% <= 0 THEN PRINT "RS232: file number not defined: " + STR$(comfilenumP%) EXIT SUB END IF 'openparP$ IF openparP$ = "" THEN PRINT "RS232: COM port parameters not allowed" EXIT SUB END IF 'If we made it this far, all parameters have values ok$ = "y" END SUB SUB rs232close '**************************************************************************** 'This subroutine closes the RS232 COM port. ' 'Zachary Wolf '12/21/96 '**************************************************************************** 'Close the port CLOSE #comfilenumP% END SUB SUB rs232in (msg$) '**************************************************************************** 'This subroutine inputs all bytes in the RS232 buffer. ' 'Output: ' msg$, bytes from the buffer ' 'Zachary Wolf '12/21/96, 12/15/97 '**************************************************************************** 'Get the bytes in the RS232 buffer nbytes% = LOC(comfilenumP%) IF nbytes% > 0 THEN msg$ = INPUT$(nbytes%, comfilenumP%) ELSE msg$ = "" END IF 'Debug 'PRINT "Nbytes = "; nbytes% 'PRINT "MSG = "; msg$ END SUB SUB rs232init '**************************************************************************** 'This subroutine opens an RS232 COM port. ' 'Zack Wolf '12/21/96 '**************************************************************************** 'Get a file number and save it comfilenumP% = FREEFILE 'Check all RS232 parameters CALL rs232checkpar(ok$) IF ok$ <> "y" THEN PRINT "Can not open RS232 COM port." EXIT SUB END IF 'Open the COM port OPEN openparP$ FOR RANDOM AS #comfilenumP% 'Clear the input buffer CALL rs232in(msg$) END SUB SUB rs232out (msg$) '**************************************************************************** 'This subroutine outputs a string to an RS232 device. ' 'Input: ' msg$, message to send to the device ' 'Zachary Wolf '12/21/96 '**************************************************************************** 'Send the message PRINT #comfilenumP%, msg$ 'Wait .5 sec for the message transfer to complete t0 = TIMER WHILE (TIMER - t0) < .5 WEND 'Debug 'SLEEP 1 'PRINT 'PRINT msg$ 'CALL rs232in(msgin$) 'PRINT msgin$ END SUB SUB rs232setpar (openpar$) '**************************************************************************** 'This subroutine sets the parameters required by this module. ' 'Input: ' openpar$, string containing all parameters for the open statement ' eg. OPEN openpar$ FOR RANDOM AS #num ' eg. openpar$ = "COM2:9600,N,8,1,ASC,RS,CD0,CS0,DS0" ' 'Zachary Wolf '12/15/97 '**************************************************************************** 'Set the parameters openparP$ = openpar$ END SUB