home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / T301AS.ZIP / T301_ASY.DOC next >
Encoding:
Text File  |  1989-01-04  |  7.9 KB  |  195 lines

  1. (*****************************************************************************
  2.  
  3.                  COPYRIGHT 1986, 1987 and 1988 by Gene Harris.
  4.  
  5.    First Release : March 10, 1986 by Gene Harris
  6.    Second Rel.   : December 19, 1988 by Gene Harris
  7.    Third Release : January 3, 1988 by Gene Harris
  8.  
  9.    This program is designed to allow your PC, XT, AT or jr to have access to
  10.    a full support RS-232 set of routines written in Turbo Pascal 3.01  This 
  11.    program is written completely in Turbo Pascal.  I suspect it will only 
  12.    handle baud rates of about 9600.  It has only been tested to 2400 baud.
  13.  
  14.    The routine has been tested on an IBM XT equipped with an NEC V20,
  15.    an XT clone running at six and eight MHz and an 8 MHz PC AT clone
  16.    successfully.  The OPENCOM routine must be changed to run with a jr.
  17.    Appropriate changes and intructions for implementing these changes is
  18.    included as comments.
  19.  
  20.    This code is copyrighted by M. Eugene Harris, Jr.  It is released to the
  21.    public domain, and may not be used for commercial gain.  The program is
  22.    user supported, and updates may be obtained from Remark BBS, in Oklahoma
  23.    City 405 728-2463.
  24.  
  25.    A new version of the program will be released in January, which will sup-
  26.    port 16 bit and 32 bit CRC's.
  27.  
  28.    Routines included in this code:
  29.  
  30.  *****************************************************************************
  31.  
  32.    InitComPort (iPort, InBufsize, OutBufsize) ;
  33.  
  34.    iPort : 1 or 2 only, no other serial ports supported.
  35.  
  36.    InBufSize   : Maximum Receive Buffer size for channel.
  37.  
  38.    OutBufsize  : Maximum Send Buffer size for channel.
  39.  
  40.    Purpose of the routine:  This routine sets up the interrupt vectors
  41.                             as well as initializing the communications
  42.                             buffers for RS232 i/o.  The maximum size of
  43.                             InBufsize and OutBufsize is MaxInt.  THIS MUST
  44.                             BE THE FIRST ROUTINE CALLED PRIOR TO USING THE
  45.                             COM PORTS!
  46.    
  47.  *****************************************************************************
  48.  
  49.    SetCom (ibaudrate,idatabits,istopbits:integer;
  50.                 iparity:char) ;
  51.  
  52.    ibaudrate : 110, 150, 300, 600, 1200, 2400, 4800, 9600 baud supported.
  53.  
  54.    idatabits : 5, 6, 7, 8 data bits supported.
  55.  
  56.    istopbits : 1 or 2 stopbits supported.
  57.  
  58.    iparity : 'E'ven, 'O'dd, 'N'one, 'M'ark, 'S'pace are supported.
  59.  
  60.    Purpose of the routine: User supplied communication port values are
  61.                            converted to the proper set values used by
  62.                            the asynch routines.  Sets are used internally
  63.                            to avoid var conflicts and improve speed.
  64.                            The routine returns an OpenError = TRUE if
  65.                            the specified COM port does not exist.  Therefore,
  66.                            the user code needs to check OpenError before
  67.                            preceding to the next logical phase.
  68.  
  69.  *****************************************************************************
  70.  
  71.    Break - No Parameters.
  72.  
  73.    Purpose : drop DTR to effectively hang up the modem.
  74.  
  75.  *****************************************************************************
  76.  
  77.    Purge - No Parameters.
  78.  
  79.    Purpose : Purge the circular queues.
  80.              Reset the 8250 interrupt control register.
  81.  
  82.  *****************************************************************************
  83.  
  84.    RS232ChrAvailable : Boolean ;
  85.  
  86.    Purpose : Returns true if there are characters in the RS232 input queue
  87.              otherwise returns false.
  88.  
  89.  ****************************************************************************
  90.  
  91.    Function ReadChar : char ;
  92.  
  93.    Purpose : Returns the next character in the RS232 input buffer.  If no
  94.              characters are present, the routine returns a null byte.  The
  95.              RS232ChrAvailable routine should ALWAYS be checked before
  96.              trying to read a character, otherwise you will not be able
  97.              to tell if the null returned is correct.  The routine is
  98.              designed to be used in the following format:
  99.  
  100.              begin
  101.                 auxoutptr := ofs(readchar) ; { Install device driver }
  102.              ....
  103.              program body
  104.              ....
  105.                 if RS232ChrAvailable then read( aux, byte or char) ;
  106.              ....
  107.              rest of program
  108.  
  109.  ***************************************************************************
  110.  
  111.    Procedure WriteChar ;
  112.  
  113.    Purpose : Writes the next character into the RS232 character buffer.
  114.              The Asynch_Interrupt routine will output the characters in
  115.              the queue as THRE interrupts are generated by the 8250.
  116.              This routine is intended to be a device driver for the logical
  117.              devices USR or AUX.
  118.  
  119.              EXAMPLE :
  120.                     begin
  121.                        auxinptr := ofs(WriteChar) ; { Install Device Driver. }
  122.                        . . . .
  123.                        . . . .
  124.                        Write (aux, variable) ; { Put in RS232 output queue }
  125.  
  126.  ***************************************************************************
  127.   
  128.   Procedure WriteBlock (var Block; size: integer) ;
  129.  
  130.   Purpose : Writes the array of bytes contained in Block to the output
  131.             ring buffer.  The THRE interrupt is then inabled, and proc-
  132.             essing continues without intefering with the calling program.
  133.  
  134.             EXAMPLE :
  135.                    var
  136.                        Block_Buffer : array [1..512] of byte ;
  137.                    
  138.                    begin
  139.                       ....
  140.                       WriteBlock (Block_Buffer, 512) ;
  141.  
  142.  ***************************************************************************
  143.   
  144.   Procedure WriteString (var String_Buffer: String_Type) ;
  145.  
  146.   Purpose : Writes the array of bytes contained in String to the output
  147.             ring buffer.  The THRE interrupt is then inabled, and proc-
  148.             essing continues without intefering with the calling program.
  149.  
  150.             EXAMPLE :
  151.                    var
  152.                        String_Buffer :  String[255];
  153.                    
  154.                    begin
  155.                       ....
  156.                       WriteString (String_Buffer) ;
  157.  
  158.  ***************************************************************************
  159.  
  160.    Procedure UseCTS ;
  161.  
  162.    Purpose : Enables the use of the CTS signal from the modem.  This is
  163.              primarily of use with high speed transfers at 9600 BAUD or
  164.              greater.  When CTS is enabled, nothing is transmitted to the
  165.              modem until the CTS line registers high in the modem status
  166.              register.
  167.  
  168.  ***************************************************************************
  169.  
  170.    Caveats : The Asynch_interrupt routine is written in pascal.  It is fast
  171.              enough to handle 1200 baud, and may handle 2400 baud.  You may
  172.              not get 4800 or 9600 baud support with this routine.
  173.  
  174.              The buffer input routine always checks that the variable
  175.              LSRstat is zero.  The LSRstat (Line Status Register) is utilized
  176.              to show buffer overflow on input.  Therefore, your program
  177.              must monitor LSRstat to determine if a buffer overflow has
  178.              occurred.  Bit 1 will be set if buffer overflow has occured.
  179.  
  180.              EXAMPLE :          if LSRstat <> 0 then begin
  181.                                    writeln('Line Status Error: ',LSRstat) ;
  182.  
  183.                                    . . . .
  184.                                    Handle LSR error condition. . .
  185.                                    . . . .
  186.  
  187.                                    { Reset LSRstat so that transmission can
  188.                                      begin again. Turn off bit 1. }
  189.  
  190.                                    LSRstat := LSRstat and $FD ;
  191.                                 end ;
  192.  
  193. *)
  194.  
  195.