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

  1. *.............................................................................
  2. *   Program Name: CTFI1400         Copyright: Magna Carta Software, Inc.
  3. *   Date Created: 02-05-93         Language:  FoxPro 2.x (DOS/Windows)
  4. *.............................................................................
  5. * Description: Same as FOXCOM11, except...
  6. * Use INT14h network modem protocol services to access a network modem.
  7. * NOTA BENE: This program requires that an INT14h network modem server be
  8. * installed. We have tested it with...
  9. * Cross Communications, Inc. "Lan+Modem" (303) 444-7799.
  10. * Please report results with other INT14h drivers. If you discover an
  11. * incompatibility, please call Pinnacle Technical Support at (206) 251-3513
  12. * and we will investigate supporting the driver you are using.
  13. * Many Thanks.
  14. *.............................................................................
  15. * Default system settings
  16. CLEAR ALL
  17. SET TALK OFF
  18. SET ESCAPE OFF
  19.  
  20. * Load the right library
  21. foxid = VERS()
  22. IF "2.0 " $ foxid
  23.     SET LIBR TO ctf                 && Identified FoxPro 2.0
  24. ELSE
  25.     IF "2.5 " $ VERS()
  26.         IF "Windows" $ foxid        && Identified FoxPro 2.5 for Windows
  27.             SET LIBR TO ctfw
  28.         ELSE
  29.             SET LIBR TO ctf25       && Identified FoxPro 2.5 for DOS
  30.         ENDIF
  31.     ENDIF
  32. ENDIF
  33.  
  34. PUBLIC fhr, number, portid, version
  35. fhr     = 0
  36. number  = "555-1212"         && phone number for modem to dial (change to suit
  37. portid  = 0
  38. version = 5
  39.  
  40. DO ctfhdr
  41. IF "2.0 " $ foxid
  42.     DO ctfutil
  43.     SET PROCEDURE TO CTFUTIL
  44. ELSE
  45.     DO ctfutil0
  46.     SET PROCEDURE TO CTFUTIL0
  47. ENDIF
  48.  
  49. ACTIVATE WINDOW w_main
  50. ACTIVATE WINDOW w_status
  51. ACTIVATE WINDOW w_term
  52.  
  53. * 'Lan+Modem' presence test. Omit if using another server.
  54. haddock = IS_NETDEV()
  55. IF haddock == 0
  56.     @00, 00 SAY "Fishy, "Lan + Modem not detected"
  57.     RETURN
  58. ELSE
  59.     @00, 00 SAY "Lan + Modem INT14h redirector detected"
  60.     @01, 00 SAY "Initializing channel. Please wait..."
  61. ENDIF
  62.  
  63. * This is interesting. We only change one line of our FoxPro source.
  64. * Instead of initializing a "u8250..." family device, we initialize an INT14h
  65. * driver. The rest of our source code is the same.
  66. * Here we comment out the old initialization...
  67. * ret = u8250_init(portid, x2d("3e8"), 9600, 8, PARITY_NONE, 1)
  68. * Here, we replace it with our new one.
  69. ret = int14_init(portid, 9600, 8, PARITY_NONE, 1)
  70. IF ret < 0
  71.     ? ret
  72.     =INKEY(0)
  73.     CANCEL
  74. ENDIF
  75.  
  76. * Note: We NEVER install interrupts when using a network modem.
  77.  
  78. @ 00,00 SAY "CommTools INT14h Network Modem Terminal Version " +;
  79.     ALLTRIM(STR(version)) + ": Press CTRL-HOME for menu"
  80. @01, 00 SAY "                                    "
  81.  
  82.  
  83. DEFINE PAD p_ct_modem  OF main_menu PROMPT "\<Modem" AT 00, 51
  84.     ON SELECTION PAD p_ct_modem OF main_menu =ct_modem(portid, 51)
  85.  
  86. DEFINE PAD p_ct_fsend  OF main_menu PROMPT "\<Send" AT 00, 60
  87.     ON SELECTION PAD p_ct_fsend  OF main_menu =do_file_send(portid, 60)
  88.  
  89. DEFINE PAD p_ct_freceive OF main_menu PROMPT "\<Receive" AT 00, 67
  90.     ON SELECTION PAD p_ct_freceive OF main_menu =do_file_receive(portid, 67)
  91.  
  92. DEFINE PAD p_ct_emul OF main_menu PROMPT "\<Emulation" AT 00, 77
  93.     ON SELECTION PAD p_ct_emul OF main_menu =do_term_emul(portid, 77)
  94.  
  95.  
  96.  
  97. ACTIVATE MENU main_menu                     && start the event loop
  98.  
  99.  
  100.  
  101. * CT_ONLINE -- We embed our call to c_term() (the terminal loop) inside
  102. * this function so that we can separate the WINDOW MANAGEMENT from the
  103. * TERMINAL OPERATIONS
  104. FUNCTION ct_online
  105.     PARAMETERS portid
  106.  
  107.     ACTIVATE WINDOW w_term                  && Activate our terminal window
  108.     =CT_SET_WIN(portid)                     && tell CommTools to use w_term
  109.     @ 00,00 SAY "CommTools Terminal Version " + LTRIM(STR(version)) + ": Press CTRL-HOME to Exit"
  110.     =c_term(portid)                         && switch to dumb terminal mode
  111. RETURN (0)
  112.  
  113.  
  114.  
  115. *
  116. * C_TERM -- This is a dumb terminal loop in FoxPro. You will see this (and
  117. * its close siblings) in every terminal example in CommTools.
  118. * Purpose: Alternately poll the serial input buffer and the keyboard for data.
  119. * Send received data to a window (the screen)
  120. * Send key strokes out of the serial port.
  121. PROCEDURE c_term
  122.     PARAMETERS portid
  123.     PRIVATE c
  124.  
  125.     * WINDOWS ADDS A CR SO WE MUST DO SOME EOL FORMATTING
  126.     * THE END-OF-LINE CONVERSION CR2LF CONVERTS A CR TO A LF. HOWEVER CRLF PAIRS ARE
  127.     * CONVERTED TO A SINGLE LF.
  128.     * WINDOWS ALSO MAY NOT DISPLAY CR PROPERLY
  129.     IF _WINDOWS == .T.
  130. *       =set_rx_xlat(portid, EOL, CR2LF)
  131.     ENDIF
  132.     =set_rx_xlat(portid, LOCAL_ECHO, TRUE)
  133.     ?
  134.     DO WHILE .T.
  135.         * CHECK SERIAL PORT FOR BYTE *
  136.         c = c_getc(portid)                          && check the serial port for a byte
  137.         IF  c == ENQ                                && CIS download request
  138.             fsize = 0
  139.             fname = " "
  140.             =set_rx_xlat(portid, LOCAL_ECHO, FALSE)
  141.             * Define a Window to show file transfer status reports.
  142.             * Note that the status window could be used for file transfer status
  143.             * reports instead.
  144.             =display_xfer(5, 5, fname, fsize)
  145.             * RECEIVE STARTS HERE (buffer size may be adjusted)
  146.             ret = freceive(portid, CISBPLUS, 4*1024, "xfer_progress")
  147.             =status_msg(0, STR(ret))
  148.             =SOUND_ON(100, 500)
  149.             DEACTIVATE WINDOW w_xfer
  150.             =status_msg(0, "FINISHED")
  151.             =set_rx_xlat(portid, LOCAL_ECHO, TRUE)
  152.         ENDIF
  153.  
  154.         * CHECK KEYBOARD FOR A KEY PRESS *
  155.         * THE GRAND COMPROMISE...
  156.         * INKEY() IS SLOW, TO AVOID IT
  157.         * CHRSAW() DOES NOT DISPLAY THE CURSOR, SO CALL INKEY() PERIODICALLY
  158.         IF c == CT_EOF .OR. CHRSAW() == .T.
  159.             c= INKEY()                              && check keyboard for a key
  160.             DO CASE                                     && evaluate the received key
  161.                 CASE c == DEL
  162.                     =c_putc(portid, BS)             && Fox Does not handle back space nicely
  163.                 CASE c == 29                        && CTRL-HOME pressed
  164.                     RETURN
  165.                 CASE c <> 0                         && another key was pressed...
  166.                     =c_putc(portid, c)              && out the port it goes
  167.             ENDCASE
  168.         ENDIF
  169.     ENDDO                                           && do while .t.
  170.     @02,00 SAY "Exiting c_term()"                   && show our mastery of the obvious
  171. RETURN
  172.  
  173.  
  174.                        *** Modem command code ***
  175.  
  176. * MODEM_MENU(expN portid, expC number)
  177. * Show a menu that allows the user to send commands to the modem.
  178. *
  179. FUNCTION ct_modem
  180.     PARAMETERS portid, col
  181.  
  182.     DEFINE POPUP pop_modem FROM 02, col;
  183.         IN WINDOW w_main;
  184.         MARGIN;
  185.         SHADOW
  186.     DEFINE BAR 1  OF pop_modem PROMPT "Return"
  187.     DEFINE BAR 2  OF pop_modem PROMPT "Initialize"
  188.     DEFINE BAR 3  OF pop_modem PROMPT "Dial"
  189.     DEFINE BAR 4  OF pop_modem PROMPT "Hang Up"
  190.  
  191.     ON SELECTION POPUP pop_modem =_ct_modem(portid, BAR())
  192.     ACTIVATE POPUP pop_modem
  193.     RELEASE pop_modem
  194. RETURN (0)
  195.  
  196.  
  197.  
  198. FUNCTION _ct_modem
  199.     PARAMETERS portid, choice
  200.     PRIVATE motype
  201.     DIMENSION modem_type[17]
  202.  
  203.     DO CASE
  204.         CASE choice = 1
  205.         CASE Choice = 2
  206.             ret=status_msg(0, "Obtaining modem type information...")
  207.             motype = modem_id(portid)
  208.             ret=status_msg(0, "Modem Type is: " + get_modem(motype))
  209.             =mspause(1000)
  210.             ret=status_msg(0, "Initializing...")
  211.             =modem_init(portid, motype)
  212.             ret=status_msg(0, "Ready")
  213.         CASE Choice = 3
  214.             IF number == ""
  215.                 ret=status_msg(0, "No telephone number specified")
  216.                 =mspause(500)
  217.             ELSE
  218.                 ret=status_msg(0, "Dialing: " + LTRIM(number))
  219.                 ret = modem_dial(portid, number)
  220.                 ret = status_msg(0, "Dial Return Code: " + STR(ret))
  221.                 =INKEY(0)
  222.                 IF ret < 0
  223.                     =status_msg(0, "Modem not initialized")
  224.                     =INKEY(0)
  225.                 ENDIF
  226.             ENDIF
  227.         CASE Choice = 4
  228.             =status_msg(0, "Attempting to hang up modem")
  229.             ret = modem_hangup(portid)
  230.             IF ret >= 0
  231.                 =status_msg(0, "Modem successfully hung up")
  232.             ELSE
  233.                 =status_msg(0, "Error while attempting to hang up modem")
  234.             ENDIF
  235.     ENDCASE
  236.     DEACTIVATE POPUP pop_modem
  237. RETURN (Choice)
  238.  
  239.  
  240.  
  241. FUNCTION get_modem
  242.     PARAMETERS type
  243.     PRIVATE strtype
  244.  
  245.     DO CASE
  246.         CASE type = 0
  247.             strtype = "UNKNOWN"
  248.         CASE type = 300
  249.             strtype = "Hayes Compatible 300 bps"
  250.         CASE type = 1200
  251.             strtype = "Hayes Compatible 1200 bps"
  252.         CASE type = 1300
  253.             strtype = "Hayes Compatible 1200EF"
  254.         CASE type = 2400
  255.             strtype = "Hayes Compatible 2400 bps"
  256.         CASE type = 9600
  257.             strtype = "Hayes Compatible 9600 bps"
  258.         CASE type = 14400
  259.             strtype = "Hayes Compatible 14400 bps"
  260.         CASE type = 961
  261.             strtype = "TELEBIT RA12C"
  262.         CASE type = 962
  263.             strtype = "TELEBIT RA12E"
  264.         CASE type = 963
  265.             strtype = "TELEBIT RM12C"
  266.         CASE type = 964
  267.             strtype = "TELEBIT T18PC"
  268.         CASE type = 965
  269.             strtype = "TELEBIT T18SA"
  270.         CASE type = 966
  271.             strtype = "TELEBIT T18RMM"
  272.         CASE type = 901
  273.             strtype = "UDS 9600"
  274.         CASE type = 1
  275.             strtype = "UDS V3224"
  276.         CASE type = 2
  277.             strtype = "UDS V3225"
  278.         CASE type = 144
  279.             strtype = "USR 9600 DUAL STD"
  280.         OTHERWISE
  281.             strtype = "UNKNOWN"
  282.     ENDCASE
  283. RETURN (strtype)
  284.  
  285.  
  286.  
  287. *
  288. * DO_FILE_RECEIVE(expN portid)
  289. * Show a menu to invoke file transmission.
  290. * Called from mainmenu()
  291. *
  292. FUNCTION do_file_receive
  293.     PARAMETERS portid, col
  294.     PRIVATE fname, fsize, ret, protocol
  295.  
  296.     ret   = -1
  297.     fsize = 0
  298.     DO WHILE .T.
  299.         protocol = get_protocol(col)
  300.         IF protocol == 0
  301.             EXIT
  302.         ENDIF
  303.         IF protocol == KERMIT .OR. protocol == YMODEM;
  304.              .OR. protocol == ZMODEM .OR. protocol == YMODEM_G
  305.             fname = " "
  306.         ELSE
  307.             fname = get_filnam(.F.)
  308.         ENDIF
  309.         IF LEN(fname) != 0
  310.             =save_xlat(portid)
  311.             =set_rx_xlat(portid, LOCAL_ECHO, FALSE)   && optionally turn off RX local echo
  312.             =set_tx_xlat(portid, LOCAL_ECHO, FALSE)   && optionally don't echo TX data
  313.  
  314.             * USE XONXOFF FLOW CONTROL (THIS LETS THE RECEIVER WRITE TO DISK) *
  315.             IF protocol = ASCII
  316.                 =set_rx_xlat(portid, FLOWCTL, XONXOFF)   && better accept flow control if > 2400 bps
  317.                 =set_rx_xlat(portid, INTERBYTE_DELAY, 5000) && set interbyte delay to 5000 ms.
  318.             ENDIF
  319.             * Define a Window to show file transfer status reports.
  320.             * Note that the status window could be used for file transfer status
  321.             * reports instead.
  322.             =display_xfer(5, 5, fname, fsize)
  323.             * RECEIVE STARTS HERE (buffer size may be adjusted)
  324.             ret = freceive(portid, protocol, 6*1024, "xfer_progress")
  325. *           ret = freceive(portid, protocol, 4096, NULL)       && no progress reporting
  326.             =status_msg(0, STR(ret))
  327.             =SOUND_ON(100, 500)
  328.             DEACTIVATE WINDOW w_xfer
  329.             =status_msg(0, "FINISHED")
  330.             IF protocol = ASCII
  331.                 COPY FILE "TEMP0000.$$$" TO fname
  332.             ENDIF
  333.             DEACTIVATE WINDOW w_xfer
  334.             =restore_xlat(portid)
  335.         ELSE
  336.             =status_msg(0, "File not found")
  337.         ENDIF
  338.     ENDDO
  339. RETURN (ret)
  340.  
  341.  
  342.  
  343. *
  344. * DO_FILE_SEND(expN portid)
  345. * Show a menu to invoke file transmission.
  346. * Called from mainmenu()
  347. *
  348. FUNCTION do_file_send
  349.     PARAMETERS portid, col
  350.     PRIVATE fname, ret
  351.  
  352.     ret   = -1
  353.     DO WHILE .T.
  354.         protocol = get_protocol(52)
  355.         IF protocol == 0
  356.             EXIT
  357.         ENDIF
  358.         FOR i = 0 TO 10
  359.             fname = get_filnam(.T.)
  360.             IF LEN(fname) != 0
  361.                 ret = fqueue(fname)
  362.                 IF ret != 0
  363.                     EXIT
  364.                 ENDIF
  365.                 IF protocol == ASCII .OR. protocol == XMODEM .OR. ;
  366.                 protocol == XMODEM_CRC .OR. protocol == XMODEM_1K
  367.                     EXIT
  368.                 ENDIF
  369.             ELSE
  370.                 EXIT
  371.             ENDIF
  372.         NEXT
  373.         IF ret == 0
  374.             =save_xlat(0)
  375. *           =set_rx_xlat(portid, LOCAL_ECHO, TRUE) && optionally echo RX to screen
  376. *           =set_tx_xlat(portid, LOCAL_ECHO, TRUE) && optionally turn on TX local echo
  377.  
  378.             * USE XONXOFF FLOW CONTROL (THIS LETS THE RECEIVER WRITE TO DISK) *
  379.             IF protocol = ASCII
  380.                 =set_rx_xlat(portid, FLOWCTL, XONXOFF)   && better accept flow control if > 2400 bps
  381.             ENDIF
  382.             fsize = NULL
  383. *           =status_msg(0, "Sending: " + fname) && use this for status window
  384.             =display_xfer(5, 5, fname, fsize)
  385.             ret = fsend(portid, protocol, 4*1024, "xfer_progress") && send the file as ASCII
  386.             =INKEY(0.5)
  387.             DEACTIVATE WINDOW w_xfer
  388.             =status_msg(0, "FINISHED!")
  389.             =restore_xlat(0)
  390.         ENDIF
  391.     ENDDO
  392. RETURN (ret)
  393.  
  394.  
  395.  
  396. *
  397. * DO_TERM_EMUL(expN portid)
  398. * Show a menu that allows the user to select a terminal to emulate.
  399. * Called from mainmenu()
  400. *
  401. FUNCTION do_term_emul
  402.     PARAMETERS portid, col
  403.     PRIVATE nChoice, termtype
  404.  
  405.     termtype = get_terminal(col)
  406.     IF termtype != CT_EOF
  407.         * USE XONXOFF FLOW CONTROL (THIS LETS US BUFFER RECEIVED DATA) *
  408.         =set_tx_xlat(portid, FLOWCTL, XONXOFF)  && better accept flow control if > 2400 bps
  409.         =set_rx_xlat(portid, LOCAL_ECHO, TRUE)  && echo RX data to screen
  410.         =set_tx_xlat(portid, LOCAL_ECHO, FALSE) && (optionally) don't echo TX data
  411.         ret = term_init(portid, termtype)
  412.         =term_set(portid, TERM_ROWS, WROWS("w_term")) && Must be interior height of window+1
  413. *       =term_set(portid, TERM_ROWS, 25)        && Won't work. Must be interior height of window+1
  414.         =term_set(portid, TERM_COLS, 80)
  415.         =term_set(portid, TERM_KEYCLICK, 0)     && Drives you mad!
  416.         IF ret < 0
  417.             =status_msg(0, "Insufficient memory for terminal emulation")
  418.         ENDIF
  419.     ENDIF
  420. RETURN (ret)
  421.  
  422.  
  423.  
  424. *
  425. * GET_TERMINAL(expN tr, expN lc)
  426. * Show a menu that allows the user to select a terminal to emulate.
  427. * Called from do_terminal_menu()
  428. *
  429. FUNCTION get_terminal
  430.     PARAMETER col
  431.     PRIVATE termtype
  432.  
  433.     termtype = 0
  434.     DEFINE POPUP pop_terminal FROM 02, col;
  435.         IN WINDOW w_main;
  436.         SHADOW
  437.     DEFINE BAR 1  OF pop_terminal PROMPT " \<TTY        "
  438.     DEFINE BAR 2  OF pop_terminal PROMPT " \<ANSI.SYS   "
  439.     DEFINE BAR 3  OF pop_terminal PROMPT " ANSI \<X3.64 "
  440.     DEFINE BAR 4  OF pop_terminal PROMPT " T\<V925      "
  441.     DEFINE BAR 5  OF pop_terminal PROMPT " VT\<52       "
  442.     DEFINE BAR 6  OF pop_terminal PROMPT " VT\<100      "
  443.     DEFINE BAR 7  OF pop_terminal PROMPT " VT\<220      "
  444.  
  445.     ON SELECTION POPUP pop_terminal termtype=_terminal_menu(BAR())
  446.     ACTIVATE POPUP pop_terminal
  447.     DEACTIVATE POPUP pop_terminal
  448.     RELEASE POPUPS pop_terminal
  449. RETURN (termtype)
  450.  
  451.  
  452. FUNCTION _terminal_menu
  453.     PARAMETERS nChoice
  454.     PRIVATE termtype
  455.  
  456.     DO CASE
  457.         CASE nChoice = 1
  458.             termtype = TTY
  459.         CASE nChoice = 2
  460.             termtype = ANSI_SYS
  461.         CASE nChoice = 3
  462.             termtype = ANSI_X364
  463.         CASE nChoice = 4
  464.             termtype = TV925
  465.         CASE nChoice = 5
  466.             termtype = DEC_VT52
  467.         CASE nChoice = 6
  468.             termtype = DEC_VT100
  469.         CASE nChoice = 7
  470.             termtype = DEC_VT220
  471.         OTHERWISE
  472.             termtype = CT_EOF
  473.     ENDCASE
  474.     =status_msg(0, "Terminal: " + ALLTRIM(PROMPT()))
  475. RETURN (termtype)
  476.