Guidance
指路人
g.yi.org
software / rapidq / Examples / Devices / RS232 Serial Port / comport CAPTURE.bas

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
 KEY OFF: CLS
 PRINT " *************************************************************** "
 PRINT " *                    CAPTURE.BAS                              * "
 PRINT " *                                                             * "
 PRINT " * Download a file using  DTR and RTS Hardware Handshaking     * "
 PRINT " * Mimics a serial printer, except saves input to a disk file  * "
 PRINT " *   Line settings are:  COM1:1200,N,8,1                       * "
 PRINT " *   use QBASIC  (or GWBASIC /S:1024 /C:1024)                  * "
 PRINT " *************************************************************** "
 GOSUB 200:  'Ask for the filename
 GOSUB 300:  'Open the receive file
 GOSUB 400:  'Open the communications line
 GOSUB 500:  'Start Message
 GOSUB 600:  'Capture
 GOSUB 1000: 'Close files
 GOSUB 1100: 'End Message
 END
 '***** Ask for the filename ***************************************
 INPUT "Enter the name of the file to capture:  ",F$
 INPUT "Add Ctrl-Z to the end of the file (Y/N) ",Z$
 IF INSTR("YyNn", Z$) = 0 THEN 220
 RETURN
 '***** Open the receive file **************************************
 OPEN F$ FOR OUTPUT AS #2
 RETURN
 '***** Open the communications line *******************************
 OPEN "COM1:1200,N,8,1" FOR RANDOM AS #1 LEN = 1024
 RETURN
 '***** Start Message **********************************************
 PRINT
 PRINT "You may now instruct the other computer to send " ;F$
 PRINT "Press [ESC] to end the capture."
 PRINT
 RETURN
 '***** CAPTURE ****************************************************
 'GWBASIC must have been invoked with GWBASIC /S:1024 /C:1024
 'this routine implements DTR & RTS hardware handshaking
 PAUSE = 0: C$ = ""
 WHILE C$ <> CHR$(27)                       'end with <ESC>
  IF EOF(1) THEN 710:                      'nothing received
  B = LOC(1):                              'number of characters in buffer
  IF B > 768 THEN GOSUB 800:               'buffer > 3/4 full: stop input
  IF B < 256 AND PAUSE = 1 THEN GOSUB 900: 'buffer < 1/4 full: cont input
  LN$ = INPUT$(LOC(1), #1):                'read the buffer into LN$
  PRINT LN$; :                             'display LN$ on the screen
  PRINT #2, LN$; :                         'save LN$ to the file
  C$ = INKEY$:                             'get any key pressed
 WEND
 RETURN
 '***** turn off handshaking ***************************************
 'port address &H3FC = modem control register for COM1, use &H2FC for COM2
 IF PAUSE = 1 THEN RETURN                   'already in pause mode
 OUT &H03FC, 0:                             'turn off DTR & RTS
 PAUSE = 1                                  'set pause flag
 RETURN
 '***** turn handshaking back on ***********************************
 OUT &H03FC, 3:                             'bits 1 & 2: DTR & RTS on
 PAUSE = 0                                  'reset pause flag
 RETURN
 '***** close files ***********************************************
 CLOSE #1:                                 'close the comm line
 IF INSTR("Yy" ,Z$) <> 0 THEN PRINT #2, CHR$(26); : 'add ^Z to file
 CLOSE #2:                                 'close the disk file
 RETURN
 '***** End Message ***********************************************
 PRINT
 PRINT "*** Finished Capture ***"
 RETURN
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2018-10-20  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-09-20 23:19:20