home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a081 / 2.ddi / CTFXX.EXE / FOXCOM10.PRG < prev    next >
Encoding:
Text File  |  1993-05-14  |  7.1 KB  |  230 lines

  1. *.............................................................................
  2. *   Program Name: FOXCOM10         Copyright: Magna Carta Software, Inc.
  3. *   Date Created: 10-03-91         Language:  FoxPro 2.x
  4. *.............................................................................
  5. * Description: Sample Terminal Program. Based on FOXCOM09.PRG plus...
  6. * File receive, with error correction, using any of XMODEM, XMODEM-CRC,
  7. * XMODEM-1k YMODEM, YMODEM-g, or ZMODEM
  8. *.............................................................................
  9. CLEAR ALL
  10. SET TALK OFF
  11. SET ESCAPE OFF
  12.  
  13. * Load the right library
  14. foxid = VERS()
  15. IF "2.0" $ foxid
  16.     SET LIBR TO ctf                 && Identified FoxPro 2.0
  17. ELSE
  18.     IF "2.5" $ VERS()
  19.         IF "Windows" $ foxid        && Identified FoxPro 2.5 for Windows
  20.             SET LIBR TO ctfw
  21.         ELSE
  22.             SET LIBR TO ctf25       && Identified FoxPro 2.5 for DOS
  23.         ENDIF
  24.     ENDIF
  25. ENDIF
  26.  
  27. SET COLOR OF SCHEME 17 TO SCHEME 1  && save default color scheme
  28. SET COLOR OF SCHEME 18 TO SCHEME 2
  29.  
  30. DO ctfhdr
  31. DO ctfutil
  32. SET PROCEDURE TO CTFUTIL
  33. number  = "720-9183"
  34. portid  = 0
  35. version = 10
  36.  
  37. ACTIVATE WINDOW w_status
  38. ACTIVATE WINDOW w_term
  39.  
  40. ret = u8250_init(portid, x2d("2e8"), 19200, 8, PARITY_NONE, 1)
  41. IF ret < 0
  42.     ? ret
  43.     =INKEY(0)
  44.     CANCEL
  45. ENDIF
  46. =CT_SET_WIN(portid)
  47.  
  48. ret =install_ipr(portid, RECEIVE, NULL, 2048)
  49. IF ret < 0
  50.     ? ret-1
  51.     =INKEY(0)
  52.     CANCEL
  53. ENDIF
  54. ret =install_ipr(portid, TRANSMIT, NULL, 4*1024)
  55. IF ret < 0
  56.     ? ret-1
  57.     =INKEY(0)
  58.     CANCEL
  59. ENDIF
  60. ret =install_isr(portid, 5, NULL)               && IRQ4 (use 3 for COM2)
  61. IF ret < 0
  62.     ? ret-2
  63.     =INKEY(0)
  64.     CANCEL
  65. ENDIF
  66.  
  67. IF ret == 0
  68.     =set_rx_xlat(0, LOCAL_ECHO, TRUE)           && turn on RX echo
  69. *   =set_rx_xlat(0, EOL, CR2CRLF)               && turn on RX echo
  70. ENDIF
  71.  
  72. DEFINE PAD p_ct_modem  OF main_menu PROMPT "\<Modem Command" AT 00, 37
  73.     ON SELECTION PAD p_ct_modem OF main_menu DO ct_modem WITH portid, 37 IN CTFMODEM.PRG
  74.  
  75. DEFINE PAD p_ct_fsend  OF main_menu PROMPT "S\<end a File" AT 00, 52
  76.     ON SELECTION PAD p_ct_fsend  OF main_menu =do_file_send(portid, 52)
  77.  
  78. DEFINE PAD p_ct_freceive OF main_menu PROMPT "\<Receive File" AT 00, 65
  79.     ON SELECTION PAD p_ct_freceive OF main_menu =do_file_receive(portid, 65)
  80.  
  81. ACTIVATE MENU main_menu
  82.  
  83.  
  84.  
  85. FUNCTION ct_online
  86.     PARAMETERS portid
  87.  
  88.     =c_term(portid)                 && switch to dumb terminal mode
  89. RETURN (0)
  90.  
  91.  
  92.  
  93. *
  94. * C_TERM -- This is a dumb terminal loop in FoxPro.
  95. * Alternately poll the serial input buffer and the keyboard for data.
  96. *
  97. FUNCTION c_term
  98.     PARAMETERS portid
  99.     PRIVATE c
  100.  
  101.     ACTIVATE WINDOW w_term
  102.     @ 00,00 SAY "CommTools Terminal Version " +;
  103.     ALLTRIM(STR(version)) + ": Press CTRL-HOME to return to menu"
  104.     ?
  105.  
  106.     DO WHILE .T.
  107.         * CHECK SERIAL PORT FOR BYTE *
  108.         c = c_getc(portid)                      && check the serial port for a byte
  109.         * CHECK KEYBOARD FOR A KEY PRESS *
  110.         c = INKEY()                             && check keyboard for a key
  111.         DO CASE                                 && evaluate the received key
  112.             CASE c == 29                        && CTL-HOME was pressed
  113.                 RETURN (0)
  114.             CASE c == DEL
  115.                 =c_putc(portid, BS)             && Fox Does not handle back space nicely
  116.             CASE c <> 0
  117.                 =c_putc(portid, c)
  118.         ENDCASE
  119.     ENDDO                                       && do while .t.
  120. RETURN (0)
  121.  
  122.  
  123.  
  124. *
  125. * DO_FILE_RECEIVE(expN portid)
  126. * Show a menu to invoke file transmission.
  127. * Called from mainmenu()
  128. *
  129. FUNCTION do_file_receive
  130.     PARAMETERS portid, col
  131.     PRIVATE fname, fsize, ret, protocol
  132.  
  133.     ret   = -1
  134.     fsize = 0
  135.     DO WHILE .T.
  136.         protocol = get_protocol(col)
  137.         IF protocol == 0
  138.             EXIT
  139.         ENDIF
  140.         IF protocol == KERMIT .OR. protocol == YMODEM;
  141.              .OR. protocol == ZMODEM .OR. protocol == YMODEM_G
  142.             fname = " "
  143.         ELSE
  144.             fname = get_filnam(.F.)
  145.         ENDIF
  146.         IF LEN(fname) != 0
  147.             =save_xlat(portid)
  148.             =set_rx_xlat(portid, LOCAL_ECHO, FALSE)   && optionally turn off RX local echo
  149.             =set_tx_xlat(portid, LOCAL_ECHO, FALSE)   && optionally don't echo TX data
  150.  
  151.             * USE XONXOFF FLOW CONTROL (THIS LETS THE RECEIVER WRITE TO DISK) *
  152.             IF protocol = ASCII
  153.                 =set_rx_xlat(portid, FLOWCTL, XONXOFF)   && better accept flow control if > 2400 bps
  154.                 =set_rx_xlat(portid, INTERBYTE_DELAY, 5000) && set interbyte delay to 5000 ms.
  155.             ENDIF
  156.             * Define a Window to show file transfer status reports.
  157.             * Note that the status window could be used for file transfer status
  158.             * reports instead.
  159.             =display_xfer(5, 5, fname, fsize)
  160.             * RECEIVE STARTS HERE (buffer size may be adjusted)
  161.             ret = freceive(portid, protocol, 6*1024, "xfer_progress")
  162. *           ret = freceive(portid, protocol, 4096, NULL)       && no progress reporting
  163.             =status_msg(0, STR(ret))
  164.             =SOUND_ON(100, 500)
  165.             DEACTIVATE WINDOW w_xfer
  166.             =status_msg(0, "FINISHED")
  167.             IF protocol = ASCII
  168.                 COPY FILE "TEMP0000.$$$" TO fname
  169.             ENDIF
  170.             DEACTIVATE WINDOW w_xfer
  171.             =restore_xlat(portid)
  172.         ELSE
  173.             =status_msg(0, "File not found")
  174.         ENDIF
  175.     ENDDO
  176. RETURN (ret)
  177.  
  178.  
  179.  
  180. *
  181. * DO_FILE_SEND(expN portid)
  182. * Show a menu to invoke file transmission.
  183. * Called from mainmenu()
  184. *
  185. FUNCTION do_file_send
  186.     PARAMETERS portid, col
  187.     PRIVATE fname, ret
  188.  
  189.     ret   = -1
  190.     DO WHILE .T.
  191.         protocol = get_protocol(52)
  192.         IF protocol == 0
  193.             EXIT
  194.         ENDIF
  195.         FOR i = 0 TO 10
  196.             fname = get_filnam(.T.)
  197.             IF LEN(fname) != 0
  198.                 ret = fqueue(fname)
  199.                 IF ret != 0
  200.                     EXIT
  201.                 ENDIF
  202.                 IF protocol == ASCII .OR. protocol == XMODEM .OR. ;
  203.                 protocol == XMODEM_CRC .OR. protocol == XMODEM_1K
  204.                     EXIT
  205.                 ENDIF
  206.             ELSE
  207.                 EXIT
  208.             ENDIF
  209.         NEXT
  210.         IF ret == 0
  211.             =save_xlat(0)
  212. *           =set_rx_xlat(portid, LOCAL_ECHO, TRUE) && optionally echo RX to screen
  213. *           =set_tx_xlat(portid, LOCAL_ECHO, TRUE) && optionally turn on TX local echo
  214.  
  215.             * USE XONXOFF FLOW CONTROL (THIS LETS THE RECEIVER WRITE TO DISK) *
  216.             IF protocol = ASCII
  217.                 =set_rx_xlat(portid, FLOWCTL, XONXOFF)   && better accept flow control if > 2400 bps
  218.             ENDIF
  219.             fsize = NULL
  220. *           =status_msg(0, "Sending: " + fname) && use this for status window
  221.             =display_xfer(5, 5, fname, fsize)
  222.             ret = fsend(portid, protocol, 4*1024, "xfer_progress") && send the file as ASCII
  223.             =INKEY(0.5)
  224.             DEACTIVATE WINDOW w_xfer
  225.             =status_msg(0, "FINISHED!")
  226.             =restore_xlat(0)
  227.         ENDIF
  228.     ENDDO
  229. RETURN (ret)
  230.