home *** CD-ROM | disk | FTP | other *** search
- (*****************************************************************************
-
- COPYRIGHT 1986, 1987 and 1988 by Gene Harris.
-
- First Release : March 10, 1986 by Gene Harris
- Second Rel. : December 19, 1988 by Gene Harris
- Third Release : January 3, 1988 by Gene Harris
-
- This program is designed to allow your PC, XT, AT or jr to have access to
- a full support RS-232 set of routines written in Turbo Pascal 3.01 This
- program is written completely in Turbo Pascal. I suspect it will only
- handle baud rates of about 9600. It has only been tested to 2400 baud.
-
- The routine has been tested on an IBM XT equipped with an NEC V20,
- an XT clone running at six and eight MHz and an 8 MHz PC AT clone
- successfully. The OPENCOM routine must be changed to run with a jr.
- Appropriate changes and intructions for implementing these changes is
- included as comments.
-
- This code is copyrighted by M. Eugene Harris, Jr. It is released to the
- public domain, and may not be used for commercial gain. The program is
- user supported, and updates may be obtained from Remark BBS, in Oklahoma
- City 405 728-2463.
-
- A new version of the program will be released in January, which will sup-
- port 16 bit and 32 bit CRC's.
-
- Routines included in this code:
-
- *****************************************************************************
-
- InitComPort (iPort, InBufsize, OutBufsize) ;
-
- iPort : 1 or 2 only, no other serial ports supported.
-
- InBufSize : Maximum Receive Buffer size for channel.
-
- OutBufsize : Maximum Send Buffer size for channel.
-
- Purpose of the routine: This routine sets up the interrupt vectors
- as well as initializing the communications
- buffers for RS232 i/o. The maximum size of
- InBufsize and OutBufsize is MaxInt. THIS MUST
- BE THE FIRST ROUTINE CALLED PRIOR TO USING THE
- COM PORTS!
-
- *****************************************************************************
-
- SetCom (ibaudrate,idatabits,istopbits:integer;
- iparity:char) ;
-
- ibaudrate : 110, 150, 300, 600, 1200, 2400, 4800, 9600 baud supported.
-
- idatabits : 5, 6, 7, 8 data bits supported.
-
- istopbits : 1 or 2 stopbits supported.
-
- iparity : 'E'ven, 'O'dd, 'N'one, 'M'ark, 'S'pace are supported.
-
- Purpose of the routine: User supplied communication port values are
- converted to the proper set values used by
- the asynch routines. Sets are used internally
- to avoid var conflicts and improve speed.
- The routine returns an OpenError = TRUE if
- the specified COM port does not exist. Therefore,
- the user code needs to check OpenError before
- preceding to the next logical phase.
-
- *****************************************************************************
-
- Break - No Parameters.
-
- Purpose : drop DTR to effectively hang up the modem.
-
- *****************************************************************************
-
- Purge - No Parameters.
-
- Purpose : Purge the circular queues.
- Reset the 8250 interrupt control register.
-
- *****************************************************************************
-
- RS232ChrAvailable : Boolean ;
-
- Purpose : Returns true if there are characters in the RS232 input queue
- otherwise returns false.
-
- ****************************************************************************
-
- Function ReadChar : char ;
-
- Purpose : Returns the next character in the RS232 input buffer. If no
- characters are present, the routine returns a null byte. The
- RS232ChrAvailable routine should ALWAYS be checked before
- trying to read a character, otherwise you will not be able
- to tell if the null returned is correct. The routine is
- designed to be used in the following format:
-
- begin
- auxoutptr := ofs(readchar) ; { Install device driver }
- ....
- program body
- ....
- if RS232ChrAvailable then read( aux, byte or char) ;
- ....
- rest of program
-
- ***************************************************************************
-
- Procedure WriteChar ;
-
- Purpose : Writes the next character into the RS232 character buffer.
- The Asynch_Interrupt routine will output the characters in
- the queue as THRE interrupts are generated by the 8250.
- This routine is intended to be a device driver for the logical
- devices USR or AUX.
-
- EXAMPLE :
- begin
- auxinptr := ofs(WriteChar) ; { Install Device Driver. }
- . . . .
- . . . .
- Write (aux, variable) ; { Put in RS232 output queue }
-
- ***************************************************************************
-
- Procedure WriteBlock (var Block; size: integer) ;
-
- Purpose : Writes the array of bytes contained in Block to the output
- ring buffer. The THRE interrupt is then inabled, and proc-
- essing continues without intefering with the calling program.
-
- EXAMPLE :
- var
- Block_Buffer : array [1..512] of byte ;
-
- begin
- ....
- WriteBlock (Block_Buffer, 512) ;
-
- ***************************************************************************
-
- Procedure WriteString (var String_Buffer: String_Type) ;
-
- Purpose : Writes the array of bytes contained in String to the output
- ring buffer. The THRE interrupt is then inabled, and proc-
- essing continues without intefering with the calling program.
-
- EXAMPLE :
- var
- String_Buffer : String[255];
-
- begin
- ....
- WriteString (String_Buffer) ;
-
- ***************************************************************************
-
- Procedure UseCTS ;
-
- Purpose : Enables the use of the CTS signal from the modem. This is
- primarily of use with high speed transfers at 9600 BAUD or
- greater. When CTS is enabled, nothing is transmitted to the
- modem until the CTS line registers high in the modem status
- register.
-
- ***************************************************************************
-
- Caveats : The Asynch_interrupt routine is written in pascal. It is fast
- enough to handle 1200 baud, and may handle 2400 baud. You may
- not get 4800 or 9600 baud support with this routine.
-
- The buffer input routine always checks that the variable
- LSRstat is zero. The LSRstat (Line Status Register) is utilized
- to show buffer overflow on input. Therefore, your program
- must monitor LSRstat to determine if a buffer overflow has
- occurred. Bit 1 will be set if buffer overflow has occured.
-
- EXAMPLE : if LSRstat <> 0 then begin
- writeln('Line Status Error: ',LSRstat) ;
-
- . . . .
- Handle LSR error condition. . .
- . . . .
-
- { Reset LSRstat so that transmission can
- begin again. Turn off bit 1. }
-
- LSRstat := LSRstat and $FD ;
- end ;
-
- *)
-