home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY1 / EXAMP1.ZIP / RMEX079.BAS < prev    next >
BASIC Source File  |  1990-03-28  |  953b  |  30 lines

  1. 'Reference Manual Example Page 79
  2. CLS
  3. 'Set up trap for processing COM input
  4. ON COM(1) GOSUB GetComInput
  5.  
  6. 'Allocate a 5K array to store input
  7. DIM ComPortInput$( 5*1024 )
  8.  
  9. 'Allocate head and tail pointers
  10. HeadPtr% = 0 : TailPtr% = 0
  11. COM(1) ON                       'turn COM input trapping on
  12. $COM 1024                       'set up 1K input buffer
  13. OPEN "COM1:" AS #1              'open COM1 with all default settings
  14. PRINT "Press any key to terminate the program..."
  15. WHILE NOT INSTAT                'if buffer isn't empty, display input
  16.   IF TailPtr% <> HeadPtr% THEN
  17.     PRINT "COM Port input: "; COMPortInput$( TailPtr% )
  18.     TailPtr% = TailPtr% + 1     'step to next spot in buffer
  19.   END IF
  20.   LOCATE 2,1 : PRINT TIME$
  21. WEND
  22. CLOSE
  23. END
  24.  
  25. 'Routine to COM port interrupt
  26. GetCOMInput:
  27.   'Read a line of input from COM port buffer
  28.   INPUT #1, COMPortInput$(HeadPtr%)
  29. HeadPtr% = HeadPtr% + 1         'advance buffer pointer
  30. RETURN