home *** CD-ROM | disk | FTP | other *** search
/ Computerworld Gratis 30 Hours of Connection / Image(2).iso / infovia / win31 / medium1.sc_ / medium1.sc
Text File  |  1995-03-06  |  7KB  |  164 lines

  1. <******************************************************* language=slang
  2.  
  3. Sample SLANG Modem Dialup Script
  4.  
  5. Description:
  6.  
  7.     Medium Example #1 -- Written in the SLANG scripting language
  8.  
  9.     This is the first script that uses the SLANG "define"
  10.     built-in function.  There are 3 functions "defined":
  11.     "dial-up", "log-in", "run-my-programs", "hang-up".  This
  12.     script demonstrates how SLANG can be used in to do
  13.     "structured programming".  Note that after all the functions
  14.     are "defined", they are called in sequence at the end of the
  15.     script.
  16.  
  17.     You will note that there is little difference between this
  18.     script and the Simple #5 script.  The value of "structured"
  19.     programming techniques will be demonstrated in more complex
  20.     examples.
  21.  
  22.     One important difference to note, if the log in fails we call
  23.     the "hang-up" function to re-initialize the modem.
  24.  
  25.     This script dials the modem.  It then checks "polls" the
  26.     serial line to see if the modem has connected with the remote
  27.     modem.
  28.  
  29.     If the connection has been made the script enters a user-id
  30.     after a short delay, then a password after another short
  31.     delay and, finally, packet mode is enabled so enable TCP/IP
  32.     data transfers.  The last thing the script does is run two
  33.     DOS applications:  PCMAIL and VMAIL.  VMAIL is left running
  34.     after the script is done.
  35.  
  36.     If no connetion is made the script informs the user and ends.
  37.  
  38.     This script does not store a user id or password directly,
  39.     but uses the ones that were entered in WDial's Configuration
  40.     Window.
  41.  
  42. To Use This Script:
  43.  
  44.     Change "00000" to the phone number of the remote machine you
  45.     would like to connect to.
  46.  
  47.     Be sure the enter your password and user id in WDial's
  48.     Configuration Window.
  49.  
  50.     Adjust the intervals in the (pause,...) functions to suit
  51.     your needs.  These are in milliseconds (50000 milliseconds ==
  52.     5 seconds).
  53.  
  54.     This script assumes that your modem, and the remote host,
  55.     terminate commands with an ASCII Carrage-Return character.
  56.     If, instead, a Carrage-Return/Line-Feed (CRLF) is required,
  57.     change "(cr)" to "(cr)(lf)" everywhere in the script it is
  58.     necessary.
  59.  
  60. Notes:
  61.  
  62.     This is a very simple dial script.  It assumes that, once the
  63.     modem connection has been made the following will be true:
  64.  
  65.     o       the remote machine will always be ready for your
  66.         user-id after a set interval
  67.  
  68.     o       like-wise for your password
  69.  
  70.     It is more robust than simpler examples in that it checks to
  71.     see if the modem connected or not, and acts accordingly.
  72.     There is no provision for retries, or verification of the
  73.     remote host, all of which are possible in SLANG.  The script
  74.     also assumes that there will be a user id and password prompt
  75.     after set intervals.
  76.  
  77.     Note that the send function calls in the "hang-up" do not
  78.     have curly braces around the modem commands.  Curly braces
  79.     are no necessary in this case because the modem commands are
  80.     one word (not containing spaces, tabs, newlines or commas).
  81.     Here is what you see:
  82.  
  83.         (send, ATH (cr) )
  84.  
  85.     What is sent consists of the letters 'A', 'T', 'H', and the
  86.     ASCII Carrage-return character.
  87.  
  88. Built-In SLANG Functions Used:
  89.  
  90.     define          Define a function.
  91.     send            Send a character string to the modem.
  92.     poll            Wait for the serial line to change state.
  93.     pause           Wait a specified number of milliseconds.
  94.     username        Return username from WDial's Configuration Window.
  95.     password        Return password from WDial's Configuration Window.
  96.     shell           Run a program, wait until program is done running.
  97.     start           Run a program, don't wait for it to complete.
  98.     changemode      Changes mode of connection from "raw" to
  99.             "packet" or vice-versa.
  100.  
  101. ************************************************************************>
  102.  
  103. (define, dial-up, {             <* START OF "dial-up" FUNCTION          *>
  104.   (send,                        <*   Dial the remote modem/host         *>
  105.     {ATDT00000}             <*      Modem command and phone number  *>
  106.     (cr)                    <*      Carrage-Return after modem cmd  *>
  107.   )                             <*      End of "send" function          *>
  108. })                              <* END OF "dial-up" FUNCTION            *>
  109.  
  110. (define, log-in, {              <* START OF "log-in" FUNCTION           *>
  111.   (poll, physical, open, 30000, <*   Wait for the modem to connect      *>
  112.     {                           <*   IF THE MODEM CONNECTED SUCESSFULLY *>
  113.       (pause, 3000)             <*    Wait for remote machine's prompt  *>
  114.                 <*    Log-in to the remote modem/host   *>
  115.       (send, (username) )       <*      Send your user id               *>
  116.       (send, (cr) )             <*      Carrage-Return after user id    *>
  117.       (pause, 5000)             <*    Wait for a password prompt        *>
  118.                 <*    Send the password                 *>
  119.       (send, (password) )       <*      Send password                   *>
  120.       (send, (cr) )             <*      Carrage-Return after password   *>
  121.       (pause, 5000)             <*    Pause for a moment                *>
  122.       (changemode, packet)      <*    Change to "packet" mode           *>
  123.  
  124.  
  125.     }                           <*   END IF THE MODEM CONNECTED         *>
  126.  
  127.     ,                           <*   Comma delimits "Else" part of poll *>
  128.  
  129.     {                           <*   ELSE IF THE MODEM DOSN'T CONNECT   *>
  130.       (output, {
  131.  
  132.     The Modem didn't connect.  End of Script.
  133.  
  134. }                               <*     everything between { } displayed *>
  135.       )                         <*   End of the "output" function       *>
  136.       (hang-up)                 <*   Reset the modem                    *>
  137.       (exit)                    <*   Exit the script                    *>
  138.     }                           <*   END IF THE MODEM DOESN'T CONNECT   *>
  139.   )                             <*   End of the "poll" function         *>
  140. })                              <* END OF "log-in" FUNCTION             *>
  141.  
  142. (define, run-my-programs, {     <* START OF "run-my-programs" FUNCTION  *>
  143.     (shell,pcmail)              <*   Run mailer                         *>
  144.     (start,vmail)               <*   Run mail reader                    *>
  145. })                              <* END OF "run-my-programs" FUNCTION    *>
  146.  
  147. (define, hang-up, {             <* START OF "hang-up" FUNCTION          *>
  148.     (changemode, raw)           <*   Change back to "raw" mode          *>
  149.     (send, +++ )                <*   Get modem's attention              *>
  150.     (pause, 3000 )              <*   Wait 3 seconds for modem response  *>
  151.     (send, ATH (cr) )           <*   Send "hang up" command to modem    *>
  152.     (pause, 1000 )              <*   Give modem 1 second to do it       *>
  153.     (send, ATZ (cr) )           <*   "Zero" modem                       *>
  154.  
  155. })                              <* END OF "hang-up" FUNCTION            *>
  156.  
  157.  
  158. <*************************  RUN THE SCRIPT  *****************************>
  159.  
  160. ( dial-up         )             <* DIAL THE REMOTE MODEM                *>
  161. ( log-in          )             <* LOG IN, STOP SCRIPT HERE IF FAILURE  *>
  162. ( run-my-programs )             <* RUN PROGRAMS WHILE LOGGED IN         *>
  163. ( hang-up         )             <* HANG UP AND RESET THE MODEM          *>
  164.