home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / PIBTERM.ZIP / SETPARMS.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1987-11-25  |  10.3 KB  |  315 lines

  1. (*----------------------------------------------------------------------*)
  2. (*                Set_Params --- Set Communications Parameters          *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. Function Set_Params( First_Time : Boolean ) : Boolean;
  6.  
  7. (*                                                                      *)
  8. (*     Function:  Set_Params                                            *)
  9. (*                                                                      *)
  10. (*     Purpose:    Ask for and set communications parameters            *)
  11. (*                                                                      *)
  12. (*     Calling Sequence:                                                *)
  13. (*                                                                      *)
  14. (*        Flag := Set_Params( First_Time ) : Boolean;                   *)
  15. (*                                                                      *)
  16. (*           First_Time:  TRUE for initial setup, else FALSE.           *)
  17. (*           Flag is TRUE if successful set-up, else FALSE.             *)
  18. (*                                                                      *)
  19. (*      Calls:   ClrScr                                                 *)
  20. (*               Async_Init                                             *)
  21. (*               Async_Open                                             *)
  22. (*               Menu_Get_Choice                                        *)
  23. (*               Menu_Display_Choices                                   *)
  24. (*                                                                      *)
  25.  
  26.                 (* Constants for Communications Parameter Values *)
  27. Const
  28.  
  29.    Baud_Rates: Array[ 1 .. 8 ] OF Integer
  30.                = ( 110, 150, 300, 600, 1200, 2400, 4800, 9600 );
  31.  
  32.    Parities:   Array[ 1 .. 3 ] OF Char
  33.                = ( 'E', 'O', 'N' );
  34.  
  35.    Stop_Data:  Array[ 1 .. 2 ] OF Integer
  36.                = ( 1 , 2 );
  37.  
  38.    Char_Bits:  Array[ 1 .. 2 ] Of Integer
  39.                = ( 7 , 8 );
  40.  
  41.    Term_Data:  Array[ 1 .. 2 ] Of Terminal_Type
  42.                = ( Dumb , VT52 );
  43.  
  44.                 (* Menu Variables *)
  45. Var
  46.    Port_Menu   : Menu_Type;
  47.    Baud_Menu   : Menu_Type;
  48.    Parity_Menu : Menu_Type;
  49.    Stop_Menu   : Menu_Type;
  50.    Bits_Menu   : Menu_Type;
  51.    BS_Menu     : Menu_Type;
  52.    Emul_Menu   : Menu_Type;
  53.    I           : Integer;
  54.  
  55.  
  56. Begin (* Set_Params *)
  57.  
  58.                                    (* Select Default Parameters *)
  59.    If First_Time Then
  60.       Begin
  61.          Data_Bits           := 7;
  62.          Parity              := 'E';
  63.          Stop_Bits           := 1;
  64.          Baud_Rate           := 1200;
  65.          Comm_Port           := 1;
  66.          BS_Char             := CHR( BS );
  67.          Ctrl_BS_Char        := CHR( DEL );
  68.          Terminal_To_Emulate := VT52;
  69.       End;
  70.  
  71.                                    (* Get port number           *)
  72.    Port_Menu.Menu_Size    := 2;
  73.    Port_Menu.Menu_Default := Comm_Port;
  74.    Port_Menu.Menu_Row     := 11;
  75.    Port_Menu.Menu_Column  := 30;
  76.    Port_Menu.Menu_Tcolor  := Menu_Text_Color;
  77.    Port_Menu.Menu_Bcolor  := BackGround_Color;
  78.    Port_Menu.Menu_Fcolor  := Menu_Frame_Color;
  79.    Port_Menu.Menu_Width   := 0;
  80.    Port_Menu.Menu_Height  := 0;
  81.  
  82.    For I := 1 to 2 Do
  83.       With Port_Menu.Menu_Entries[I] Do
  84.       Begin
  85.          Menu_Item_Row    := I;
  86.          Menu_Item_Column := 2;
  87.          Case I Of
  88.             1:  Menu_Item_Text:= 'Serial Port 1';
  89.             2:  Menu_Item_Text:= 'Serial Port 2';
  90.          End (* Case *);
  91.       End;
  92.  
  93.    Port_Menu.Menu_Title := 'Which Communications Port: ';
  94.  
  95.    Menu_Display_Choices( Port_Menu );
  96.    Comm_Port := Menu_Get_Choice( Port_Menu , Erase_Menu );
  97.  
  98.                                    (* Get Baud Rate  *)
  99.    Baud_Menu.Menu_Size    := 8;
  100.    Baud_Menu.Menu_Row     := 11;
  101.    Baud_Menu.Menu_Column  := 30;
  102.    Baud_Menu.Menu_Tcolor  := Menu_Text_Color;
  103.    Baud_Menu.Menu_Bcolor  := BackGround_Color;
  104.    Baud_Menu.Menu_Fcolor  := Menu_Frame_Color;
  105.    Baud_Menu.Menu_Width   := 0;
  106.    Baud_Menu.Menu_Height  := 0;
  107.  
  108.    Case Baud_Rate Of
  109.       110 :  Baud_Menu.Menu_Default := 1;
  110.       150 :  Baud_Menu.Menu_Default := 2;
  111.       300 :  Baud_Menu.Menu_Default := 3;
  112.       600 :  Baud_Menu.Menu_Default := 4;
  113.       1200:  Baud_Menu.Menu_Default := 5;
  114.       2400:  Baud_Menu.Menu_Default := 6;
  115.       4800:  Baud_Menu.Menu_Default := 7;
  116.       9600:  Baud_Menu.Menu_Default := 8;
  117.    End (* Case *);
  118.  
  119.    For I := 1 to 8 Do
  120.       With Baud_Menu.Menu_Entries[I] Do
  121.       Begin
  122.          Menu_Item_Row    := I;
  123.          Menu_Item_Column := 2;
  124.          Case I Of
  125.             1:  Menu_Item_Text:= '110';
  126.             2:  Menu_Item_Text:= '150';
  127.             3:  Menu_Item_Text:= '300';
  128.             4:  Menu_Item_Text:= '600';
  129.             5:  Menu_Item_Text:= '1200';
  130.             6:  Menu_Item_Text:= '2400';
  131.             7:  Menu_Item_Text:= '4800';
  132.             8:  Menu_Item_Text:= '9600';
  133.          End (* Case *);
  134.       End;
  135.  
  136.    Baud_Menu.Menu_Title := 'Choose Baud Rate: ';
  137.  
  138.    Menu_Display_Choices( Baud_Menu );
  139.    Baud_Rate := Baud_Rates[ Menu_Get_Choice( Baud_Menu , Erase_Menu ) ];
  140.  
  141.                                    (* Get Bits per Character *)
  142.    Bits_Menu.Menu_Size    := 2;
  143.    Bits_Menu.Menu_Default := Data_Bits - 6;
  144.    Bits_Menu.Menu_Row     := 11;
  145.    Bits_Menu.Menu_Column  := 30;
  146.    Bits_Menu.Menu_Tcolor  := Menu_Text_Color;
  147.    Bits_Menu.Menu_Bcolor  := BackGround_Color;
  148.    Bits_Menu.Menu_Fcolor  := Menu_Frame_Color;
  149.    Bits_Menu.Menu_Width   := 0;
  150.    Bits_Menu.Menu_Height  := 0;
  151.  
  152.    For I := 1 to 2 Do
  153.       With Bits_Menu.Menu_Entries[I] Do
  154.       Begin
  155.          Menu_Item_Row    := I;
  156.          Menu_Item_Column := 2;
  157.          Case I Of
  158.             1:  Menu_Item_Text:= '7';
  159.             2:  Menu_Item_Text:= '8';
  160.          End (* Case *);
  161.       End;
  162.  
  163.    Bits_Menu.Menu_Title := 'Data Bits in Each Character: ';
  164.  
  165.    Menu_Display_Choices( Bits_Menu );
  166.    Data_Bits := Char_Bits[ Menu_Get_Choice( Bits_Menu , Erase_Menu ) ];
  167.  
  168.                                    (* Get stop bits *)
  169.    Stop_Menu.Menu_Size    := 2;
  170.    Stop_Menu.Menu_Default := Stop_Bits;
  171.    Stop_Menu.Menu_Row     := 11;
  172.    Stop_Menu.Menu_Column  := 30;
  173.    Stop_Menu.Menu_Tcolor  := Menu_Text_Color;
  174.    Stop_Menu.Menu_Bcolor  := BackGround_Color;
  175.    Stop_Menu.Menu_Fcolor  := Menu_Frame_Color;
  176.    Stop_Menu.Menu_Width   := 0;
  177.    Stop_Menu.Menu_Height  := 0;
  178.  
  179.    For I := 1 to 2 Do
  180.       With Stop_Menu.Menu_Entries[I] Do
  181.       Begin
  182.          Menu_Item_Row    := I;
  183.          Menu_Item_Column := 2;
  184.          Case I Of
  185.             1:  Menu_Item_Text:= '1';
  186.             2:  Menu_Item_Text:= '2';
  187.          End (* Case *);
  188.       End;
  189.  
  190.    Stop_Menu.Menu_Title := 'Number of Stop Bits: ';
  191.  
  192.    Menu_Display_Choices( Stop_Menu );
  193.    Stop_Bits := Stop_Data[ Menu_Get_Choice( Stop_Menu , Erase_Menu ) ];
  194.  
  195.                                    (* Get Parity *)
  196.    Parity_Menu.Menu_Size    := 3;
  197.  
  198.    Case Parity Of
  199.       'E' :  Parity_Menu.Menu_Default := 1;
  200.       'O' :  Parity_Menu.Menu_Default := 2;
  201.       'N' :  Parity_Menu.Menu_Default := 3;
  202.    End (* Case *);
  203.  
  204.    Parity_Menu.Menu_Row     := 11;
  205.    Parity_Menu.Menu_Column  := 30;
  206.    Parity_Menu.Menu_Tcolor  := Menu_Text_Color;
  207.    Parity_Menu.Menu_Bcolor  := BackGround_Color;
  208.    Parity_Menu.Menu_Fcolor  := Menu_Frame_Color;
  209.    Parity_Menu.Menu_Width   := 0;
  210.    Parity_Menu.Menu_Height  := 0;
  211.  
  212.    For I := 1 to 3 Do
  213.       With Parity_Menu.Menu_Entries[I] Do
  214.       Begin
  215.          Menu_Item_Row    := I;
  216.          Menu_Item_Column := 2;
  217.          Case I Of
  218.             1:  Menu_Item_Text:= 'Even';
  219.             2:  Menu_Item_Text:= 'Odd';
  220.             3:  Menu_Item_Text:= 'None';
  221.          End (* Case *);
  222.       End;
  223.  
  224.    Parity_Menu.Menu_Title := 'Choose Parity: ';
  225.  
  226.    Menu_Display_Choices( Parity_Menu );
  227.    Parity := Parities[ Menu_Get_Choice( Parity_Menu , Erase_Menu ) ];
  228.  
  229.                                    (* Get BackSpace Key Use *)
  230.    BS_Menu.Menu_Size    := 2;
  231.    BS_Menu.Menu_Row     := 11;
  232.    BS_Menu.Menu_Column  := 30;
  233.    BS_Menu.Menu_Tcolor  := Menu_Text_Color;
  234.    BS_Menu.Menu_Bcolor  := BackGround_Color;
  235.    BS_Menu.Menu_Fcolor  := Menu_Frame_Color;
  236.    BS_Menu.Menu_Width   := 0;
  237.    BS_Menu.Menu_Height  := 0;
  238.  
  239.    If BS_Char = CHR( BS ) Then
  240.       BS_Menu.Menu_Default := 1
  241.    Else
  242.       BS_Menu.Menu_Default := 2;
  243.  
  244.    For I := 1 To 2 Do
  245.       With BS_Menu.Menu_Entries[I] Do
  246.       Begin
  247.          Menu_Item_Row    := I;
  248.          Menu_Item_Column := 2;
  249.          Case I Of
  250.             1:  Menu_Item_Text:= 'Backspace (ASCII 08)';
  251.             2:  Menu_Item_Text:= 'Delete    (ASCII 127)';
  252.          End (* Case *);
  253.       End;
  254.  
  255.    BS_Menu.Menu_Title := 'Backspace key sends: ';
  256.  
  257.    Menu_Display_Choices( BS_Menu );
  258.  
  259.    Case Menu_Get_Choice( BS_Menu, Erase_Menu ) Of
  260.  
  261.       1:  Begin
  262.              BS_Char      := CHR( BS  );
  263.              Ctrl_BS_Char := CHR( DEL );
  264.           End;
  265.  
  266.       2:  Begin
  267.              BS_Char      := CHR( DEL );
  268.              Ctrl_BS_Char := CHR( BS  );
  269.           End;
  270.  
  271.    End (* Case *);
  272.  
  273.                                    (* Get terminal type to emulate *)
  274.    Emul_Menu.Menu_Size    := 2;
  275.  
  276.    Case Terminal_To_Emulate Of
  277.       Dumb: Emul_Menu.Menu_Default := 1;
  278.       VT52: Emul_Menu.Menu_Default := 2;
  279.    End (* Case *);
  280.  
  281.    Emul_Menu.Menu_Row     := 11;
  282.    Emul_Menu.Menu_Column  := 30;
  283.    Emul_Menu.Menu_Tcolor  := Menu_Text_Color;
  284.    Emul_Menu.Menu_Bcolor  := BackGround_Color;
  285.    Emul_Menu.Menu_Fcolor  := Menu_Frame_Color;
  286.    Emul_Menu.Menu_Width   := 0;
  287.    Emul_Menu.Menu_Height  := 0;
  288.  
  289.    For I := 1 to 2 Do
  290.       With Emul_Menu.Menu_Entries[I] Do
  291.       Begin
  292.          Menu_Item_Row    := I;
  293.          Menu_Item_Column := 2;
  294.          Case I Of
  295.             1:  Menu_Item_Text:= 'Dumb';
  296.             2:  Menu_Item_Text:= 'VT52';
  297.          End (* Case *);
  298.       End;
  299.  
  300.    Emul_Menu.Menu_Title := 'Terminal to emulate: ';
  301.  
  302.    Menu_Display_Choices( Emul_Menu );
  303.    Terminal_To_Emulate := Term_Data[ Menu_Get_Choice( Emul_Menu , Erase_Menu ) ];
  304.  
  305.                                    (* Initialize Comm Variables *)
  306.    Async_Init;
  307.                                    (* Open Communications Port  *)
  308.  
  309.    Set_Params := Async_Open( Comm_Port, Baud_Rate, Parity, Data_Bits,
  310.                              Stop_Bits );
  311.  
  312.    If First_Time Then ClrScr;
  313.  
  314. End   (* Set_Params *);
  315.