home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / pibasy.zip / DUMBTRM.PAS < prev    next >
Pascal/Delphi Source File  |  1987-11-11  |  9KB  |  219 lines

  1. (*$U-,R-,V-,S-*)
  2. PROGRAM DumbTrm;
  3.  
  4. (*--------------------------------------------------------------------------*)
  5. (*                                                                          *)
  6. (*   Program:   DumbTrm                                                     *)
  7. (*                                                                          *)
  8. (*   Author:    Philip R. Burns                                             *)
  9. (*                                                                          *)
  10. (*   Date:      November 11, 1987.                                          *)
  11. (*                                                                          *)
  12. (*   Purpose:   Dumb terminal emulator to demonstrate PibAsync routines.    *)
  13. (*                                                                          *)
  14. (*   Usage:     Compile to .EXE file using Turbo Pascal and execute the     *)
  15. (*              .EXE file by typing  DUMBTRM  at the DOS prompt.            *)
  16. (*                                                                          *)
  17. (*              You will be prompted for the required communications        *)
  18. (*              parameters.  If the serial port can be opened successfully, *)
  19. (*              then a dumb terminal mode is entered.                       *)
  20. (*                                                                          *)
  21. (*              To exit dumb terminal mode, type ^C (ascii 03).  To send    *)
  22. (*              a break, type ^B (ascii 02).                                *)
  23. (*                                                                          *)
  24. (*   Needs:     See includes below for files included from PibAsync.Arc.    *)
  25. (*                                                                          *)
  26. (*   Remarks:   This program doesn't check for input mistakes when the      *)
  27. (*              communications parameters are being entered.                *)
  28. (*                                                                          *)
  29. (*--------------------------------------------------------------------------*)
  30.  
  31.                                    (* Get global types *)
  32.                                    (* Get declarations for async i/o *)
  33. USES
  34.    Crt, Dos, GlobType, PibTimer, PibAsync;
  35.  
  36. VAR
  37.    Baud_Rate   : WORD              (* Baud rate for connection, e.g., 1200  *);
  38.    Com_Port    : INTEGER           (* Which port, e.g., 1 for COM1:         *);
  39.    Parity      : CHAR              (* Parity, e.g., E for even parity       *);
  40.    Data_Bits   : INTEGER           (* How many bits per character, e.g., 8  *);
  41.    Stop_Bits   : INTEGER           (* How many stop bits -- nearly always 1 *);
  42.  
  43. VAR
  44.    InBufSize   : INTEGER           (* Size of input buffer                  *);
  45.    OutBufSize  : INTEGER           (* Size of output buffer                 *);
  46.    Do_XonXoff  : CHAR              (* 'Y' to do XON/XOFF flow control       *);
  47.    Do_HardWired: CHAR              (* 'Y' to do XON/XOFF flow control       *);
  48.    Do_CTS      : CHAR              (* 'Y' to do CTS checking                *);
  49.    Do_DSR      : CHAR              (* 'Y' to do DSR checking                *);
  50.  
  51.  
  52. (*--------------------------------------------------------------------------*)
  53.  
  54. PROCEDURE Get_Comm_Params;
  55.  
  56. VAR
  57.    YesNo : CHAR;
  58.  
  59. BEGIN (* Get_Comm_Params *)
  60.  
  61.    WRITELN;
  62.  
  63.    WRITE('Enter com port (1,2,3,4):                             ');
  64.    READLN( Com_Port );
  65.  
  66.    WRITE('Enter baud rate (300,1200,2400,4800,9600,19200,38400):');
  67.    READLN( Baud_Rate );
  68.  
  69.    WRITE('Enter parity (E=even, N=one, O=odd, M=mark, S=space): ');
  70.    READLN( Parity );
  71.  
  72.    Parity := UpCase( Parity );
  73.  
  74.    WRITE('Enter bits per character (7 or 8):                    ');
  75.    READLN( Data_Bits );
  76.  
  77.    WRITE('Enter stop bits (usually 1):                          ');
  78.    READLN( Stop_Bits );
  79.  
  80.    WRITE('Enter size in bytes of async receive buffer:          ');
  81.    READLN( InBufSize );
  82.  
  83.    WRITE('Enter size in bytes of async output buffer:           ');
  84.    READLN( OutBufSize );
  85.  
  86.    WRITE('Use XON/XOFF flow control (Y/N)?                      ');
  87.    READLN( Do_XonXoff );
  88.  
  89.    WRITE('Do CTS checking (Y/N)?                                ');
  90.    READLN( Do_CTS );
  91.  
  92.    WRITE('Do DSR checking (Y/N)?                                ');
  93.    READLN( Do_DSR );
  94.  
  95.    WRITE('Is connection hard-wired (Y/N)?                       ');
  96.    READLN( Do_HardWired );
  97.  
  98. END   (* Get_Comm_Params *);
  99.  
  100. (*--------------------------------------------------------------------------*)
  101.  
  102. FUNCTION Initialize_Communications : BOOLEAN;
  103.  
  104. BEGIN (* Initialize_Communications *)
  105.  
  106.                                    (* Set CTS checking *)
  107.  
  108.    Async_Do_CTS         := ( UpCase( Do_CTS ) = 'Y' );
  109.  
  110.                                    (* Set DSR checking *)
  111.  
  112.    Async_Do_DSR         := ( UpCase( Do_DSR ) = 'Y' );
  113.  
  114.                                    (* Set XON/XOFF to user request *)
  115.  
  116.    Async_Do_XonXoff     := ( UpCase( Do_XonXoff ) = 'Y' );
  117.  
  118.                                    (* Set hard-wired as user requests *)
  119.  
  120.    Async_Hard_Wired_On  := ( UpCase( Do_HardWired ) = 'Y' );
  121.  
  122.                                    (* Set half-second break duration *)
  123.    Async_Break_Length   := 500;
  124.  
  125.                                    (* Let XON/XOFF break points default. *)
  126.  
  127.    Async_Init( InBufSize, OutBufSize, 0, 0, 0);
  128.  
  129.                                    (* If com port 3 or 4, make sure     *)
  130.                                    (* port address specified in memory. *)
  131.    IF ( Com_Port > 2 ) THEN
  132.       IF ( NOT Async_Port_Address_Given( Com_Port ) ) THEN
  133.          Async_Setup_Port( Com_Port, -1, -1 );
  134.  
  135.                                    (* Try opening the serial port.   *)
  136.  
  137.    IF ( NOT Async_Open( Com_Port, Baud_Rate, Parity, Data_Bits, Stop_Bits ) ) THEN
  138.       BEGIN
  139.          WRITELN('Cannot open serial port.');
  140.          Initialize_Communications := FALSE;
  141.       END
  142.    ELSE
  143.       BEGIN
  144.          WRITELN('Serial port opened, DumbTrm ready.');
  145.          Initialize_Communications := TRUE;
  146.       END;
  147.  
  148. END   (* Initialize_Communications *);
  149.  
  150. (*--------------------------------------------------------------------------*)
  151.  
  152. PROCEDURE Emulate_Dumb_Terminal;
  153.  
  154. VAR
  155.    Kch: CHAR;
  156.    Ch : CHAR;
  157.  
  158. BEGIN (* Emulate_Dumb_Terminal *)
  159.  
  160.                                    (* Begin loop over serial port   *)
  161.                                    (* and keyboard.                 *)
  162.    REPEAT
  163.                                    (* Pick up and display character *)
  164.                                    (* from port, if any.            *)
  165.  
  166.       IF Async_Receive( Ch ) THEN
  167.          IF ( Ch <> CHR( 0 ) ) THEN
  168.             WRITE( Ch );
  169.                                    (* Read character from keyboard  *)
  170.                                    (* and send out port, unless it  *)
  171.                                    (* is ^B or ^C.                  *)
  172.                                    (*                               *)
  173.                                    (* ^B -- send a break            *)
  174.                                    (* ^C -- quit                    *)
  175.       IF KeyPressed THEN
  176.          BEGIN
  177.             KCh := ReadKey;
  178.             CASE KCh OF
  179.                ^B: Async_Send_Break;
  180.                ^C: ;
  181.                ELSE
  182.                   Async_Send( Kch );
  183.             END (* CASE *);
  184.          END;
  185.  
  186.    UNTIL ( Kch = ^C );
  187.  
  188. END   (* Emulate_Dumb_Terminal *);
  189.  
  190. (*--------------------------------------------------------------------------*)
  191.  
  192. PROCEDURE Finish_Communications;
  193.  
  194. BEGIN (* Finish_Communications *)
  195.                                    (* Close port and drop DTR *)
  196.    Async_Close( FALSE );
  197.                                    (* Release space allocated for buffers *)
  198.    Async_Release_Buffers;
  199.  
  200. END   (* Finish_Communications *);
  201.  
  202. (*--------------------------------------------------------------------------*)
  203.  
  204. BEGIN (* DumbTrm *)
  205.  
  206.                                    (* Request serial port parameters     *)
  207.    Get_Comm_Params;
  208.                                    (* Initialize port                    *)
  209.  
  210.    IF Initialize_Communications THEN
  211.       BEGIN
  212.                                    (* Emulate dumb terminal until ^C hit *)
  213.          Emulate_Dumb_Terminal;
  214.                                    (* Close down port                    *)
  215.          Finish_Communications;
  216.  
  217.       END;
  218.  
  219. END   (* DumbTrm *).