;Demonstrates Aspect Set/Fetch Functions     v1.00 

;*************************************************************************
;* Written by:  Symantec ASPECT Assist                                       *
;*                                                                           *                                                                             
;* This script file will give the user the option of either capturing data   *
;* in half hour increments, or in 24 hour increments. The Capture file will  *
;* close after a predefined period of inactivity on the port.                *
;*                                                                           *
;* This ASPECT script is intended only as a sample of ASPECT programming.    *
;* Symantec makes no warranty of any kind, express or implied, including     *
;* without limitation, any warranties of merchantability and/or fitness      *
;* for a particular purpose.  Use of this program is at your own risk.       *
;*                                                                           *
;* Technical Support is not provided on this script.                         *                                                                          *
;*****************************************************************************



;*************************************************************************
;*   GLOBAL VARIABLES                                                    *
;*************************************************************************
string szAllProt    = "Zmodem,Kermit,Xmodem,1K-Xmodem,1K-Xmodem-G,Ymodem,Ymodem-G,CIS-B+,ASCII,RAW ASCII,IND$FILE"
string szAllConn    = "direct connect-Com1,direct connect-Com2,direct connect-Com3,direct connect-Com4"
string szAllSpeed   = "300,1200,2400,9600,19200,38400,57600,115200"
string szCurTerm, szCurProt, szCurConn, szDefProt, szDefSpeed
string szDefTerm, szDefConn
integer iQSelect, iCurDBits, iCurParity, ICurSbits, iDefSBits, iDefDBits
integer iDefParity
long lCurSpeed, lDefSpeed


;*************************************************************************
;*                                                                       *
;* MAIN                                                                  *
;* The main procedure calls DRAWDIALOG to get the order in which the     *
;* entries need to be imported.  It then calls the HANDLDIALOG procedure *
;* to handle the dialog events.                                          *
;*                                                                       *
;* Globals: NONE                                                         *
;* Calls: GETOPTIONS, GET DEFAULTS, DRAWDIALOG, HANDLEDIALOG, EXITSCRIPT * 
;*                                                                       *
;*************************************************************************
proc Main
   when dialog 0 call HandleDialog1      ;Handle the main dialog.
   GetDefaults ()                        ;Get the default options.
   DrawDialog1 ()                        ;Display the main Dialog.
   ExitScript  ()                        ;Restore values and exit script.
endproc



;*************************************************************************
;*                                                                       *
;* GetDefaults ()                                                        *
;* This procedure fetches all of the current settings options that are   *
;* Quick-Select Line. These will be saved until the user exits the       *      
;* script. At that time they will be restored.                           *
;* to the user.                                                          *
;*                                                                       *
;* Globals: szCurTerm, szDefTerm, szCurrConn, szDefConn, szCurProt,      *
;*          szDefProt, lCurSpeed, szDefSpeed, iCurDBits, szDefBits,      *
;*          szDefDBits, iCurSBits, iDefSBits, iCurParity, iDefParity,    *
;*          iQSelect                                                     *
;*                                                                       *
;* Calls:    NONE                                                        *
;* Called by:  MAIN                                                      *
;*                                                                       *
;************************************************************************* 
proc GetDefaults
string szSep = ","

   fetch quickselect iQSelect         ;Find out if QuickSelect is on or not.

   if iQselect == 0                   ;If not,
      set quickselect 1               ;turn it on while script is running.
      usermsg "Turning on Quickselect Line while this script runs"
   endif

   fetch terminal type szCurTerm      ;Fetch current terminal type.
   szDefTerm = szCurTerm              ;Assign value to temporary variable.
   fetch modem connection szCurConn   ;Fetch current connection type.
   szDefConn = szCurConn              ;Assign value to temporary variable.
   strcat szAllConn szSep             ;Add current connection to static
   strcat szAllConn szDefConn         ;list that is hardcoded into script.
   fetch protocol szCurProt           ;Fetch current transfer protocol.
   szDefProt = szCurProt              ;Assign value to temporary variable.
   fetch port baudrate lCurSpeed      ;Fetch current baud rate.
   ltoa lCurSpeed szDefSpeed          ;Assign value to temporary variable.
   fetch port databits iCurDBits      ;Fetch current Databits setting.

   if iCurDBits == 7                  ;Assign value to temporary variable.
      iDefDBits = 61
   else
      iDefDBits = 62
   endif

   fetch port stopbits iCurSBits      ;Fetch current Stopbits setting. 

   if iCurSBits == 1                  ;Assign value to temporary value
      iDefSBits = 51
   else
      iDefSBits = 52
   endif

   fetch port parity iCurParity       ;Fetch the current Parity setting.

   switch iCurParity                  ;Assign value to temporary variable.
      case 0
         iDefParity  = 71
      endcase
      case 1
         iDefParity  = 72
      endcase
      case 2
           iDefParity  = 73
      endcase
      case 3
         iDefParity  = 74
      endcase
      case 4 
         iDefParity  = 75
      endcase
   endswitch

endProc



;*************************************************************************
;*                                                                       *
;* DRAWDIALOG1()                                                         *
;* The procedure DRAWDIALOG1 creates a dialog box which shows the        *
;* current values as the defaults, and invites the user to make changes. *
;*                                                                       *
;*                                                                       *
;* Globals:  NONE                                                        *
;* Calls:    NONE                                                        *
;* Called by:  MAIN                                                      *
;*                                                                       *
;************************************************************************* 
proc DrawDialog1

   dialogbox 0 8 23 264 190 70 "Change Connection Settings" 
      text 1 8 2 80 11 "Terminal Emulation:" left 
      fcombobox 3 8 14 81 39 DROPDOWNLIST "sfterm.txt" szDefTerm 
      text 9 7 58 77 12 "Transfer Protocol:" left 
      combobox 10 8 73 80 38 DROPDOWNLIST szAllProt szDefProt
      text 20 122 2 77 12 "Connection Speed:" left 
      combobox 21 121 14 80 44 DROPDOWNLIST szAllSpeed szDefSpeed
      text 23 8 122 77 12 "Connection:" left 
      combobox 8 8 133 80 38 DROPDOWNLIST szAllConn szDefConn
      text 4 124 52 41 14 "Stop Bits:" left 
      radiogroup 50 iDefSBits
         radiobutton 51 126 64 42 11 "1" 
         radiobutton 52 126 80 42 11 "2" 
      endgroup
      text 19 178 52 46 14 "Data Bits:" left 
      radiogroup 60 iDefDBits
         radiobutton 61 177 64 38 12 "7" 
         radiobutton 62 176 80 38 12 "8" 
      endgroup
      text 100 127 102 41 14 "Parity:" left 
      radiogroup 70 idefParity
         radiobutton 71 126 114 42 11 "NONE" 
         radiobutton 72 126 126 42 11 "ODD" 
         radiobutton 73 126 137 42 11 "EVEN" 
         radiobutton 74 126 149 42 11 "MARK" 
         radiobutton 75 126 161 42 11 "SPACE" 
      endgroup
      pushbutton 90 188 110 48 19 "&OK" OK 
      pushbutton 91 188 139 48 19 "&Cancel" CANCEL 
   enddialog 
endproc



;*************************************************************************
;*                                                                       *
;* HANDLEDIALOG1()                                                       *
;* The procedure HANDLEDIALOG handle dialog events from DRAWDIALOG.      *
;*                                                                       *
;* Globals:  NONE                                                        *
;* Calls:    NONE                                                        *
;* Called by:  MAIN                                                      *
;*                                                                       *
;************************************************************************* 
proc HandleDialog1
integer Temp1                              ;Temporary variable

   dlgevent 0 Temp1                        ;Returns the effected control

   switch Temp1                            ;Switch based on control
      case 90
         set terminal type szDefTerm       ;Change terminal to new value.
         set modem connection szDefConn    ;Change connect to new value.
         set protocol szDefProt            ;Change Protocol to new value.
         atol szDefSpeed lDefSpeed          ;Convert speed to long variable.
         set port baudrate lDefSpeed       ;Change Speed to new value.

         switch iDefSBits                  ;Change Stopbits to new value.
            case 51
               set port stopbits 1
            endcase
            case 52
               set port stopbits 2
            endcase
         endswitch

         switch iDefDBits                  ;Change Databits to new value.
            case 61
               set port databits 7
            endcase
            case 62
               set port databits 8
            endcase
         endswitch         

         switch idefparity                 ;Change Parity to new value.
            case 71   
               set port parity 0
            endcase
            case 72
               set port parity 1
            endcase
            case 73
               set port parity 2
            endcase
            case 74
               set port parity 3
            endcase
            case 75
               set port parity 4
            endcase
        endswitch

        usermsg "The Quickselect line now shows the changes you made. When you click OK, defaults will be restored, and the script will exit."
      endcase                              ;Endcase for switch on OK BUTTON.
      case 91                              
         exit                              ;If user Cancels, exit w/o changes.
      endcase
   endswitch 
endproc



;*************************************************************************
;*                                                                       *
;* EXITSCRIPT()                                                          *
;* The procedure restores settings to original valuse, and exits script. *
;*                                                                       *
;* Globals:  NONE                                                        *
;* Calls:    NONE                                                        *
;* Called by:  MAIN                                                      *
;*                                                                       *
;*************************************************************************
proc ExitScript

   set terminal type szCurTerm       ;Restore terminal value.
   set modem connection szCurConn    ;Restore connect value.
   set protocol szCurProt            ;Restore Protocol value.
   set port baudrate lCurSpeed       ;Restore Speed value.
   set port stopbits iCurSBits       ;Restore Stop Bit Value.
   set port databits iCurDBits       ;Restore Databit Value.
   set port parity   iCurParity      ;Restore Parity Value.

   if iQselect == 0                   ;QuickSelect was off originally, 
      set quickselect 0               ;so we'll turn it off since we're done.
   Endif

   exit                              ;Exit the script.

endproc   
