                     RAYON PCIPORT DOCUMENTATION FOR DOS
               ------------------------------------------------

         Copyright (c) 2003 by RAYON Technologies Co, Ltd. Taipei, Taiwan

                             TEL : 886-2-8285-8362
                             FAX : 886-2-8285-7065
                            E-Mail : rayon@ms1.hinet.net


                        <<<<   C O N T E N T S   >>>>


        Chapter 1.      Introduction
        Chapter 2.      Check List
        Chapter 3.      Driver Installation and Release Guide
        Chapter 4.      Programming Architecture
        Chapter 5.      Programmer's Guide for Assembly Interface
        Chapter 6.      Programmer's Guide for C Interface
        Chapter 7.      The DEMO Program : DEMO.EXE



        Chapter 1.      INTRODUCTION

           This Device driver support RAYON's PCIPORT & INDPORT card.
        PCIPORT & INDPORT  are enhanced eight port and four port card.
        INDPORT card include one isolated RS422/RS485 interface .


        Chapter 2.      CHECK LIST

           This DOS driver is bundle in one diskette.  Once you unpack
        the package, make a copy quickly. The following list describes the
        contents in the floppy.


                In (\DOS) directory :

                PCIPORT.COM     - Combined PCIPORT Driver.
                FREEPCI.COM     - Free the Driver to release system memory.
                READ.ME         - Documentation.

                In \DEMO directory :

                DEMO.C          - Main program.
                PCI.H           - Include file for DEMO.C.
                SCR.C           - Screen Processing Module.
                TOOL.ASM        - Screen Processing Module.
                PCICALL.C       - 'C' programmer's interface.
                PCICALL.H       - Include file for PCICALL.C.
                MAKEFILE        - Make file for building DEMO program.
                DEMO.EXE        - Execution file


        Chapter 3.      DRIVER INSTALLATION AND RELEASE GUIDE

                To install the PCIPORT driver on your system, following the
        steps described as follow:

                [1]. Set the DIP switch in the INDPORT. This DIP switch allows
                     you to select the target interface for PortD in P514 card
                     and Port H in P518 card to be RS422 (ON) or RS485 (OFF).

                [2]. Power off your PC and plug the PCIPORT/INDPORT card on a
                     slot,  plug the cable into the D-Type connector of
                     Adapter.

                [3]. Install the PCIPORT driver.Type the  following command at
                     the DOS prompt :

                        A>PCIPORT [ENTER]

                     To Release the PCIPORT driver,  type  the  following
                     command at the DOS prompt :

                        A>FREEPCI [ENTER]

                NOTE: You may be in the directory with our full DOS driver
                      files.

        Chapter 4.      PROGAMMING ARCHITECTURE

                Before programming for the PCIPORT/INDPORT, You should know
        the basic architecture and the data flow among the applications,
        the PORT driver,the PORT program (runs in card) and the devices.

                                +---------------+
                                |  Application  |
                                +-------+-------+
                                        |
                                +---------------+
                 API            |    INT 14H    |
                                +-------+-------+
                 PORT driver    | System Buffer |
                                +---------------+
                                        |
                                     +------+
                 Adapter             | P588 |
                                     +------+

                Each port has an input queue and an output queue in  system
        RAM to store the data stream between application program and Adapter
        side. The queue space is dynamic adjusted, according to the  number of
        ports installed. Anyone who want to transmit data to a  specific  port
        has to determine the output queue space.We must confirm the output
        queue size is large enough to acept the target data size to be
        transmitted. Or we may just accept the queue size and the other lost.
        The incomming data would be stored in input queue until the application
        program read them out.


        Chapter 5.      PROGRAMMER'S GUIDE FOR ASSEMBLY INTERFACE


                If you want to develop application programs that use one of the
        PCIPORT cards to be the communication device,   this  chapter  will
        give you the specification  of  PCIPORT  driver  function  calls.If you
        are familiar with  'C' programming, see the chapter "Programmer's guide
        for C interface" that will give you the better way to use this driver.


                                BASIC SERIAL FUNCTIONS
                                ----------------------

        =======================================================================
        INT 14h,  00h   --  Initialize Serial Port Parameters
        =======================================================================
        Description : Initializes the baud rate, parity, stop-bit, and word
                      length parameters for a serial port, and returns the
                      status for the port.

        BOX :         NONE (for COM1 and COM2)

        INPUT :       AH         00h

                      AL         Communications parameters.

                         7  6  5     4  3       2          1  0
                      +-----------+--------+-----------+-------------+
                      | Baud Rate | Parity | Stop Bits | Word Length |
                      +-----------+--------+-----------+-------------+
                        |              |             |           |
                        [0 0 0] : 110  [0 0] : None  [0] : One  [1 0] : 7 bits
                        [0 0 1] : 150  [0 1] : Odd   [1] : Two  [1 1] : 8 bits
                        [0 1 0] : 300  [1 0] : None
                        [0 1 1] : 600  [1 1] : Even
                        [1 0 0] : 1200
                        [1 0 1] : 2400
                        [1 1 0] : 4800
                        [1 1 1] : 9600

                      DX         Serial port number (0 - COM1, 1 - COM2, etc.)

        OUTPUT :      AX         Line and modem status (see Service 03h)



        =======================================================================
        INT 14h,  01h     --  Send One Character
        =======================================================================
        DESCRIPTION : Sends one character to the specified serial port.

        BOX :         NONE (for COM1 and COM2)

        INPUT :       AH         01h

                      AL         send Character

                      DX         Serial port number (0 - COM1, 1 - COM2, etc.)

        OUTPUT :      AH         Line status (see Service 03h)

        NOTE :        If an error occurs, bit 7 of AH will be set.  Since bit 7
                      is used as a general error flag,  this service is  unable
                      to identify a  time-out error.  For  complete  diagnostic
                      information, use Service 03h (Get serial port status).


        =======================================================================
        INT 14h,  02h     --   Receive One Character
        =======================================================================
        DESCRIPTION : Receives one character from a specific serial port.

        BOX :         NONE (for COM1 and COM2)

        INPUT :       AH         02h
                      DX         Serial port number (0 - COM1, 1 - COM2, etc.)

        OUTPUT :      AL         Character
                      AH         Line status (See service 03h)

        NOTE :        This service waits for a character.  If  no  character is
                      available or an error occurs,  no character  is  returned
                      and bit 7 of AH is set.

                      If an error occurs, bit 7 of AH will be set.  Since bit 7
                      is used as a general error flag,  this service is  unable
                      to identify a  time-out error.   For  complete diagnostic
                      information, use Service 03h (Get serial port status).

        =======================================================================
        INT 14h,  03h      --  Get Serial Port Status
        =======================================================================
        DESCRIPTION : Returns  line status  and  modem status information for a
                      specified serial port.

        BOX :         NONE (for COM1 and COM2)

        INPUT :       AH         03h
                      DX         Serial port number (0 - COM1, 1 - COM2, etc.)

        OUTPUT :      AX         Line and Modem status (See below)

                      AH (Line status)
                      7 6 5 4 3 2 1 0
                      1 . . . . . . .       Time-out error
                      . 1 . . . . . .       Transfer shift register empty
                      . . 1 . . . . .       Transfer holding register empty
                      . . . 1 . . . .       Break-detect error
                      . . . . 1 . . .       Framing error
                      . . . . . 1 . .       Parity error
                      . . . . . . 1 .       Overrun error
                      . . . . . . . 1       Data ready

                      AL (Modem status)
                      7 6 5 4 3 2 1 0
                      1 . . . . . . .       Received line signal detect
                      . 1 . . . . . .       Ring indicator
                      . . 1 . . . . .       Data set ready
                      . . . 1 . . . .       Clear to send
                      . . . . 1 . . .       Change in receive signal detected
                      . . . . . 1 . .       Trailing edge ring detector
                      . . . . . . 1 .       Change in data set ready
                      . . . . . . . 1       Change in clear to send

        NOTE :        If bit 7 of the Line status  byte  (AH) is set,  then the
                      rest of the bits in AH and AL are unpredictable.



                        EXTENSION FUNCTIONS FOR PCIPORT
                        -------------------------------

        =======================================================================
        INT 14h,  C0h           Open a port.
        =======================================================================
        DESCRIPTION : Initializes the baud  rate,  parity,  stop-bit,  and word
                      length parameters for a PCI port, and open to work.

        INPUT :       AH         C0h

                      BX         Serial communications parameters (see below)

                                 Bit 3 2 1 0  :  Baud Rate
                                     0 0 0 0  :  110
                                     0 0 0 1  :  150
                                     0 0 1 0  :  300
                                     0 0 1 1  :  600
                                     0 1 0 0  :  1200
                                     0 1 0 1  :  2400
                                     0 1 1 0  :  4800
                                     0 1 1 1  :  9600
                                     1 0 0 0  :  19200
                                     1 0 0 1  :  38400
                                     1 0 1 0  :  57600
                                     1 0 1 1  :  115200
                                     1 1 0 0  :  50
                                     1 1 0 1  :  75
                                     1 1 1 0  :  100
                                     1 1 1 1  :  200

                                 Bit 7 6 5 4  :  Parity check
                                     -------
                                     0 0 0 0  :  NoParity
                                     0 0 0 1  :  OddParity
                                     0 0 1 0  :  EvenParity


                                 Bit 11 10  9  8  :  Word Length
                                     -----------
                                     0  0  0  0   :  5
                                     0  0  0  1   :  6
                                     0  0  1  0   :  7
                                     0  0  1  1   :  8


                                 Bit 15 14 13 12  :  Number of stop bits
                                     -----------
                                     0  0  0  0   :  One stop bits
                                     0  0  0  1   :  Two stop bits

     #####################################################################
     #  NOTE: For other combination is reserved for other function. User #
     #        must specify every bit to meet above setting. Or they may  #
     #        have "open fail" result.                                   #
     #####################################################################

                      DX          port number
                                 (DH:Card-No DL:Port-No)

                                 Card-No:start from 1 upto 8

                                 Port-No:start from 0 for port A
                                               upto 7 for port H

                      CX         Input Control Modes (see below)

                                 Bit  0  :  software flow  control
                                 --------
                                      0  :  no action
                                      1  :  enable XON/XOFF function

                                 Bit  1  :  Hardware flow control
                                 --------
                                      0  :  no action
                                      1  :  enable RTS/CTS function

        OUTPUT :      AH         Open Status

                                 -1 : Fail
                                 00 : Successful
                                 01 : port not exist
                                 02 : Busy (already opened)

        =======================================================================
        INT 14h,  C1h            Send One Character (PUTC)
        =======================================================================
        DESCRIPTION : Sends one character to the specified port.

        INPUT :       AH         C1h

                      AL         Send Character

                      DX         Port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No:start from 1
                                 Port-No:start from 0 for port A

        OUTPUT :      AX = 0     Success
                      AX = -1    port not exist  (Fail)

        =======================================================================
        INT 14h,  C2h            Receive One Character (GETC)
        =======================================================================
        DESCRIPTION : Receives one character from the specified serial port.

        INPUT :       AH         C2h

                      DX         Port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No:start from 1
                                 Port-No:start from 0 for port A

        OUTPUT :      AL =       Received Character
                      AH = -1    Fail
                         =  0    success

        =======================================================================
        INT 14h,  C3h            Send Characters (WRITE)  (multi-byte mode)
        =======================================================================
        DESCRIPTION : Sends characters in buffer to the specified serial port.

        INPUT :       AH         C3h

                      CX         Byte Count  (1 is 1 byte, maximum 65534)

                      DX         Port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No: start from 1
                                 Port-No: start from 0 for port A

                      ES:BX      Buffer pointer to hold data

        OUTPUT :      AX         Actually write data byte count
                      AX = -1    Write error, port not exist , flow control
                                 TRUE

        =======================================================================
        INT 14h,  C4h            Receive Characters (READ)  (multi-byte mode)
        =======================================================================
        DESCRIPTION : Receives characters from the specified serial port.

        INPUT :       AH         C4h

                      CX         Byte Count  (1 is 1 byte,maximum 65534)

                      DX         Port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No: start from 1
                                 Port-No: start from 0 for port A


                      ES:BX      Buffer pointer to hold data

        OUTPUT :      AX         Actural read data byte count
                      AX = -1    read error, port not exist , flow control
                                 TRUE

        =======================================================================
        INT 14h,  C5h            Get Port Status
        =======================================================================
        DESCRIPTION : Returns status information for a specified port.

        INPUT :       AH         C5h
                      DX         Port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No: start from 1
                                 Port-No: start from 0 for port A

        OUTPUT :      AX         Port status (See below)
                      AX=0FFFFh  Port not exist

              AH               AL
        7 6 5 4 3 2 1 0  7 6 5 4 3 2 1 0
        X . . . . . . .  . . . . . . . .      Reserved
        . X . . . . . .  . . . . . . . .      Reserved
        . . X . . . . .  . . . . . . . .      Reserved
        . . . X . . . .  . . . . . . . .      Reserved
        . . . . 1 . . .  . . . . . . . .      TXEMP (controller chip)
        . . . . . 1 . .  . . . . . . . .      RXRDY (controller chip)
        . . . . . . X .  . . . . . . . .      Reserved
        . . . . . . . X  . . . . . . . .      Reserved
        . . . . . . . .  X . . . . . . .      Reserved
        . . . . . . . .  . 1 . . . . . .      IsOpen
        . . . . . . . .  . . 1 . . . . .      Underrun (output Queue empty)
        . . . . . . . .  . . . 1 . . . .      Overflow (input Queue full)
        . . . . . . . .  . . . . ? ? ? ?      Baud Rate (See C0h)

        =======================================================================
        INT 14h,  C6h            Get Output Queue Available Space
        =======================================================================
        DESCRIPTION : Returns avaliable space of output queue for a specified
                      port.

        INPUT :       AH         C6h
                      DX         Port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No: start from 1
                                 Port-No: start from 0

        OUTPUT :      AX         Available space byte count
                      AX = -1    Port not exist

        =======================================================================
        INT 14h,  C7h            Get Input Queue Available character count
        =======================================================================
        DESCRIPTION : Return avaliable charaters in input queue for a specified
                      port.

        INPUT :       AH         C7h
                      DX         Serial port number
                                 (DH:Card-No DL: Port-No)
                                 Card-No:start from 1
                                 Port-No:start from 0 for port A
        OUTPUT :      AX         Available Byte Count in input queue
                      AX = -1    Port not exist


        =======================================================================
        INT 14h,  C8h            Get Current Installed Card Count
        =======================================================================
        DESCRIPTION : Returns current installed card count.

        INPUT :       AH         C8h

        OUTPUT :      AL         Available Card Count


        =======================================================================
        INT 14h,  C9h            Get Current Installed Port Count Of Specified
                                 Card
        =======================================================================
        DESCRIPTION : Returns current installed port count of specified card
                      number.

        INPUT :       AH         C9h

                      AL         Specified Card Number (1 thru 4)

        OUTPUT :      AX         Available Port Count


        =======================================================================
        INT 14h,  CAh            Reset Output Queue Of Specified Port Number
        =======================================================================
        DESCRIPTION : Flush all data in output queue

        INPUT :       AH         CAh

                      DX         Serial port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No:start from 1
                                 Port-No:start from 0 for port A

        OUTPUT :      AX = 0     Success
                      AX = -1    Port not exist


        =======================================================================
        INT 14h,  CBh            Reset Input Queue Of Specified Port Number
        =======================================================================
        DESCRIPTION : Clear all data in input queue

        INPUT :       AH         CBh
                      DX         Port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No:start from 1
                                 Port-No:start from 0

        OUTPUT :      AX = 0     Success
                      AX = -1    Port not exist


        =======================================================================
        INT 14h,  CCh            Reset PCIPORT
        =======================================================================
        DESCRIPTION : Reset PCIPORT (ReStart)

        INPUT :       AH         CCh

        OUTPUT :      None

        =======================================================================
        INT 14h,  CDh            Close specified port
        =======================================================================
        DESCRIPTION : Close port.

        INPUT :       AH         CDh
                      DX         Port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No:start from 1
                                 Port-No:start from 0 for port A

        OUTPUT :      AX = 0     Success
                      AX = -1    Port not exist

        =======================================================================
        INT 14h,  CEh           Get Port LSR,MSR Status
        =======================================================================
        DESCRIPTION : Returns port LSR,MSR status information for a specified
                      port.

        INPUT :       AH         CEh
                      DX         Serial port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No:start from 1
                                 Port-No:start from 0 for port A

        OUTPUT :      AX         Port status (See below)
                      AX = -1    Port not exist

                AH= LSR register read from 16550.
                AL= MSR register read from 16550.

              AH               AL
        7 6 5 4 3 2 1 0  7 6 5 4 3 2 1 0
        1 . . . . . . .  . . . . . . . .      FIFO data error
        . 1 . . . . . .  . . . . . . . .      Transmit both empty
        . . 1 . . . . .  . . . . . . . .      Transmit FIFO empty
        . . . 1 . . . .  . . . . . . . .      Break condition
        . . . . 1 . . .  . . . . . . . .      Frame error
        . . . . . 1 . .  . . . . . . . .      Parity error
        . . . . . . 1 .  . . . . . . . .      Overrun error
        . . . . . . . 1  . . . . . . . .      RXRDY  REceive FIFO available
        . . . . . . . .  1 . . . . . . .      DCD (active high)
        . . . . . . . .  . 1 . . . . . .      RI  (active high)
        . . . . . . . .  . . 1 . . . . .      DSR (active high)
        . . . . . . . .  . . . 1 . . . .      CTS (active high)
        . . . . . . . .  . . . . 1 . . .      DCD changed
        . . . . . . . .  . . . . . 1 . .      RI changed
        . . . . . . . .  . . . . . . 1 .      DSR changed
        . . . . . . . .  . . . . . . . 1      CTS changed



        =======================================================================
        INT 14h,  CFh            Turn DTR of specified port to ON or OFF
        =======================================================================
        DESCRIPTION : Change Data Terminal Ready state

        INPUT :       AH         CFh

                      AL         0 : OFF
                                 1 : ON

                      DX         Serial port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No:start from 1
                                 Port-No:start from 0  for port A

        OUTPUT :      AX = 0     Success
                      AX = -1    Port not exist

        =======================================================================
        INT 14h,  D0h            Turn RTS of specified port to ON or OFF
        =======================================================================
        DESCRIPTION : Change RTS hardware signal state

        INPUT :       AH         D0h

                      AL         0 : OFF
                                 1 : ON

                      DX         Serial port number
                                 (DH:Card-No DL:Port-No)
                                 Card-No:start from 1
                                 Port-No:start from 0  for port A

        OUTPUT :      AX = 0     Success
                      AX = -1    Port not exist



        Chapter 6.      PROGRAMMER'S GUIDE FOR C INTERFACE


                This C interface to PCIPORT driver may be used by  programmers
        who write applications for all of the PCIPORTs. After one of the
        PCIPORT driver was installed, You may link this interface module to
        your applications. To  call  the functions in this module just like
        to call the driver.

        This C Interface contains 2 files :

                1. PCICALL.C  --   Source file for Turbo C.
                2. PCICALL.H  --   Include file


                             FUNCTION  CALLS
                             ---------------


        *-----[ PciPortOpen ]-----------------------------------------------------

        FUNCTION :  Open a specific port.

        PROTOTYPE : INT PciPortOpen(WORD card, WORD port, WORD cflag, WORD iflag)

        ARGUMENTS : card  -- card number ( 1 <= card <= 4 )
                    port  -- port number ( 0 <= port <= max port - 1 )
                    cflag -- Communication parameters (see below)
                    iflag -- software flow control or headware flow control

         15  14  13  12  11  10  9  8   7  6  5  4   3  2  1  0
       +--------------+--------------+------------+-------------+
       |  stop  bits  |  word Length |   parity   |  Baud  Rate |
       +--------------+--------------+------------+-------------+
           |              |             |              |
        Stop bits         |             |              0 0 0 0  :  110
         0 0 0 0 : One    |            Parity          0 0 0 1  :  150
         0 0 0 1 : Two    |            0 0 0 0 : None  0 0 1 0  :  300
                          |            0 0 0 1 : Odd   0 0 1 1  :  600
                       Word Length     0 0 1 0 : Even  0 1 0 0  :  1200
                       0 0 0 0 : 5                     0 1 0 1  :  2400
                       0 0 0 1 : 6                     0 1 1 0  :  4800
                       0 0 1 0 : 7                     0 1 1 1  :  9600
                       0 0 1 1 : 8                     1 0 0 0  :  19200
                                                       1 0 0 1  :  38400
                                                       1 0 1 0  :  57600
        RETURN :   00 -- Success                       1 0 1 1  :  115200
                   Fail -- parameter error             1 1 0 0  :  50
                   01 -- port Not exist                1 1 0 1  :  75
                   02 -- Busy (already openned)        1 1 1 0  :  100
                                                       1 1 1 1  :  200

        EXAMPLE :  This example opens port 0 of card 1, giving  parameters 9600
                   baud rate, 8-bit data,  enable receiver,  and  hangup  after
                   close. Input enables XON/XOFF flow control.

                   #include "pciport.h"

                   main ()
                   {
                        WORD    cflag, iflag;

                        cflag = CHR8 | B9600 | NOPARITY | STOP1;
                        iflag = IXON;

                        /* P588 */

                        if (PciPortOpen(1, 0, cflag, iflag) != 0) {
                                printf("Error openning P588 Card 1 port 0 !\n");
                                exit(0)
                        }
                        /* port operations */
                        .
                        .
                   }


        *-----[ PciPortPutc ]-----------------------------------------------------

        FUNCTION :  Write a character to a specific serial port.

        PROTOTYPE : INT PciPortPutc(WORD card, WORD port, BYTE c)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )
                    port -- port number ( 0 <= port <= max port - 1 )
                    c    -- character to be written

        RETURN :    FAIL -- error
                    TRUE   -- success

        EXAMPLE :   This example sends "GLOBAL" to port 0 of card 1 (P588).

                    #include "pciport.h"

                    CHAR buffer[6] = {'G','L','O','B','A','L'};
                    main ()
                    {
                        INT     i;

                        /* Call PciPortOpen() */
                        for (i = 0; i < 6; i++) {

                                /* P588 */
                                if (PciPortPutc(1, 0, buffer[i]) != OK) {
                                        printf("Character write error !\n");
                                        exit(0);
                                }
                        }
                        /* Call PciPortClose() */
                    }


        *-----[ PciPortGetc ]-----------------------------------------------------

        FUNCTION :  Read a character from a specific serial port.

        PROTOTYPE : INT PciPortGetc(WORD card, WORD port)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )
                    port -- port number ( 0 <= port <= max port - 1 )

        RETURN :    FAIL -- port not exist
                    character -- Received Character

        EXAMPLE :   This example read characters from port 0 of card 1 (P588)
                    and write them back.

                    #include "pciport.h"
                    main ()
                    {
                        BYTE    c,char;

                        /* call PciPortOpen() */
                        while (1) {
                                 /*P588 */
                                  PciPortPutc(1, 0, c);
                                char=PciPortGetc(1, 0);
                            if(char == c)
                              printf("Received Character OK!\n");
                        }
                        /* call PciPortClose() */
                    }

        *-----[ PciPortWrite ]----------------------------------------------------
        FUNCTION :  Write characters in buffer to a specific port.

        PROTOTYPE : INT PciPortWrite(WORD card, WORD port, BYTE far *buffer,
                                  INT count)

        ARGUMENTS : card   -- card number ( 1 <= card <= 4 )
                    port   -- port number ( 0 <= port <= max port - 1 )
                    buffer -- buffered characters to be written
                    count  -- number of bytes want to write

        RETURN :    Number of bytes Actually be written
                    FAIL -- error

        EXAMPLE :   This example writes "GLOBAL" to port 0 of card 1.

                    #include "pciport.h"

                    main()
                    {
                        /* call PciPortOpen() */
                                /*P588 */
                        if (PciPortWrite(1, 0,"GLOBAL", 6) < 6)
                                printf("Write error !\n");
                        /* call PciPortClose() */
                    }


        *-----[ PciPortRead ]-----------------------------------------------------

        FUNCTION :  Read characters from a specific serial port.

        PROTOTYPE : INT PciPortRead(WORD card, WORD port, BYTE far *buffer,
                                 INT count)

        ARGUMENTS : card   -- card number ( 1 <= card <= 4 )
                    port   -- port number ( 0 <= port <= max port - 1 )
                    buffer -- buffer to store the received characters
                    count  -- number of bytes want to receive

        RETURN :    Number of bytes really be received.
                    FAIL -- error

        EXAMPLE :   This example read characters and write them back.

                    #include "pciport.h"

                    BYTE far buffer[100];
                    main()
                    {
                        INT     len;

                        /* call PciPortOpen() */
                        while (1) {    /*P588 */
                                if ( (len = PciPortRead(1, 0, buffer, 100)) > 0 )
                                        PciPortWrite(1, 0, buffer, len);
                                else
                                        break;
                        }
                        /* call PciPortClose() */
                    }

        *-----[ PciPortStatus ]---------------------------------------------------

        FUNCTION :  Get the status of a specific port.

        PROTOTYPE : WORD PciPortStatus(WORD card, WORD port)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )
                    port -- port number ( 0 <= port <= max port - 1 )

        RETURN :    The communication status of this port (see below,  all bits
                    are defined in PCIPORT.H

                    0xFFFF -- Port not exists.
                    1      -- Get status error.

          15  14  13  12  11  10  9   8   7   6   5   4   3  2  1  0
        +---+---+---+---+---+---+---+---+---+---+---+---+------------+
        | x | x | x | x | T | R | x | x | x | O | V | F | Baud Rate  |
        +---+---+---+---+---+---+---+---+---+---+---+---+------------+
                          |   |               |   |   |       |
                          TX  RX             OPEN |   |     see PciPortOpen()
                                                  |  Overflow
                                                 Overrun
        NOTE : x : Reserved

        EXAMPLE :   This example checks if port 0 of card 1 (P588) was opened.

                    #include "pciport.h"

                    main()
                    {         /*P588 */
                        if (PciPortStatus(1, 0) & S_OPEN)
                                printf("Port 0 was opened.\n");
                        else
                                printf("Port 0 was not opened.\n");
                    }

        *-----[ PciPortDoqSpace ]------------------------------------------------

        FUNCTION :  Get the output queue space of a specific serial port.
                    Call this function to make sure the output queue  space  is
                    enough to carry the data before calling PciPortWrite().

        PROTOTYPE : INT PciPortDoqSpace(WORD card, WORD port)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )
                    port -- port number ( 0 <= port <= max port - 1 )

        RETURN :    Number of space available in output queue for transmitting
                    FAIL -- error

        *-----[ PciPortDiqCount ]------------------------------------------------

        FUNCTION :  Get the number of characters in input queue.
                    Before calling PciPortRead(), call this function to make  sure
                    there are characters in the input queue.

        PROTOTYPE : INT PciPortDiqCount(WORD card, WORD port)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )
                    port -- port number ( 0 <= port <= max port - 1 )

        RETURN :    Number of bytes in the input queue that can be received
                    FAIL -- error

        *-----[ PciPortMaxCard ]--------------------------------------------------

        FUNCTION :  Report number of cards on the main board.

        PROTOTYPE : INT PciPortMaxCard(VOID)

        ARGUMENTS : None

        RETURN :    Number of card installed.

        *-----[ PciPortMaxPort ]--------------------------------------------------

        FUNCTION :  Return number of ports on specific card.

        PROTOTYPE : INT PciPortMaxPort(WORD card)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )

        RETURN :    Number of ports on the specified card


        *-----[ PciPortResetDoq ]-------------------------------------------------
        FUNCTION :  Flush all the data in the output queue.
                    Before calling PciPortClose, you  may  call  this  function to
                    make sure all data in output queue was flushed.

        PROTOTYPE : INT PciPortResetDoq(WORD card, WORD port)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )
                    port -- port number ( 0 <= port <= max port - 1 )

        RETURN :    FAIL -- error
                    TRUE -- success

        *-----[ PciPortResetDiq ]-------------------------------------------------
        FUNCTION :  Clear all the data in the input queue.

        PROTOTYPE : INT PciPortResetDiq(WORD card, WORD port)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )
                    port -- port number ( 0 <= port <= max port - 1 )

        RETURN :    FAIL -- error
                    TRUE -- success

        *-----[ PciPortReset ]----------------------------------------------------
        FUNCTION :  Restart PCIPORT (Reinitialize)

        PROTOTYPE : VOID PciPortReset(VOID)

        ARGUMENTS : None

        RETURN :    None

        *-----[ PciPortClose ]----------------------------------------------------
        FUNCTION :  Close a specific serial port.

        PROTOTYPE : INT PciPortClose(WORD card, WORD port)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )
                    port -- port number ( 0 <= port <= max port - 1 )

        RETURN :    FAIL -- error
                    TRUE -- success

        *-----[ PciPortSetDTR ]---------------------------------------------------
        FUNCTION :  Turn DTR of a specific port ON or OFF.

        PROTOTYPE : INT PciPortSetDTR(WORD card, WORD port, INT flag)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )
                    port -- serial port number ( 0 <= port <= max port - 1 )
                    flag -- ON  :  turn on
                            OFF :  turn off
                            ON and OFF were defined in PCIPORT.H
        RETURN :    FAIL -- error
                    TRUE   -- success
        *-----[ PciPortSetRTS ]---------------------------------------------------

        FUNCTION :  Turn RTS of a specific port ON or OFF.

        PROTOTYPE : INT PciPortSetRTS(WORD card, WORD port, INT flag)

        ARGUMENTS : card -- card number ( 1 <= card <= 4 )
                    port -- serial port number ( 0 <= port <= max port - 1 )
                    flag -- ON  :  turn on
                            OFF :  turn off
                            ON and OFF were defined in PCIPORT.H
        RETURN :    FAIL -- error
                    TRUE   -- success


        *-----[ PciPortInstall ]--------------------------------------------------
        FUNCTION :  Check to see if PCIPORT driver was installed.
                    Before calling any function of driver, you need to check if
                    the PCIPORT driver was installed.

        PROTOTYPE : INT PciPortInstall(VOID)


        RETURN :    TRUE  -- Installed
                    FALSE -- Not installed

                                  EXAMPLE
                                  =======

                This example illustrates the usage of the most of the functions
        in this module, it opens all the ports on card 1,  and  polls each port
        input queue.  If there's any data comes in the input queue, read it and
        then write back. Use CONTROL-C key to terminate this program.

        #include <stdio.h>
        #include <dos.h>
        #include "pciport.h"

        #define MAXLINE 128

        BYTE    RxBuffer[200];
        WORD    status[MAXLINE];

        main()
        {
                WORD    Cflag, Iflag;
                int     maxline;
                int     i, j;
                WORD    stus;
                int     c, len;

                /* Check driver installed or not */
                if ( !PciPortInstall() ) {
                        printf("PCIPORT driver was not installed!\n");
                        exit(0);
                }

                /* Set open parameters (8 bit data, baud 9600, enable receive,
                   hangup when close */
                Cflag = CHR8 | B9600 | NOPARITY | STOP1;
                Iflag = 0;

                /* Get maxmum port of card 1 */
                maxline = PciPortMaxPort(1);

                /* Open all ports of card 1 */
                for (i=0; i<maxline; i++)
                        Status[i] = PciPortOpen(1, i, Cflag, Iflag);

                /* Check if open was successful */
                for (i=0; i<maxline; i++)
                {
                        if ( (Status[i] != 0) )
                        {
                                printf("PORT[%d] --> OPEN FAIL\n", i);
                                for (i=0; i < maxline; i++)
                                        PciPortClose(1, i);
                                exit(0);
                        }
                        printf("PORT[%d] --> OPEN SUCCESS\n", i);
                }

                /* Wait for all ports carry on */
                for (i=0; i < maxline; i++)
                        for (j=0; j < 1000; j++);

                for (i=0; i < maxline; i++)
                {
                        /* press CONTROL-C to terminate the program */
                        if(bioskey(1))
                        {
                                c = bioskey(0) & 0xff;
                                if(c == 0x03)
                                        break;
                        }

                        /* Get port status */
                        stus = PciPortStatus(1, i)
                        if ((stus&S_OPEN) && (stus&S_CARR))
                        {
                                /* Read from port */
                                len=PciPortRead(1, i, (BYTE far *)RxBuffer, 180);

                                /* Write back */
                                if (PciPortDoqSpace(1, i) > len)
                                        PciPortWrite(1,i,(BYTE far *)RxBuffer,len);

                        }
                }

                /* Flush all ports and close them */
                for (i=0; i < maxline; i++)
                {
                        PciPortResetDoq(1, i);
                        PciPortClose(1, i);
                }
        }


        Chapter 7.      DEMO PROGRAM : DEMO.EXE


                The DEMO program  DEMO.EXE is used to test the functionality of
        PCIPORT. programmers can learn how to work  with PCIPORT card and it's
        driver.  This program was written for TURBOC C compiler.

        The DEMO program contains the following files in \DEMO directory :

                        1. DEMO.C       --  Main Module of DEMO program.
                        2. PCI.H        --  Include file for DEMO.C.
                        3. SCR.C        --  Screen Processing Module.
                        4. TOOL.ASM     --  Screen Precessing Module.
                        5. PCIFUN.C     --  'C' Callable interface to driver.
                        6. PCIFUN.H     --  Include file for PCIFUN.C.
                        7. MAKEFILE     --  Makefile for building DEMO program.
                        8. DEMO.EXE     --  Execution file

        [ RUNNING ]

                Before running this DEMO program,  make sure you have installed
        the PCIPORT driver (see the chapter "Driver Installation and Deinstallat-
        ion Guide").  If the PCIPORT driver was installed, You could run the DEMO
        program now :

                A> DEMO <baud> <card>

                <baud> : baud rate, can be 300, 1200, 2400, 4800, 9600,
                         19200, 38400, 56000, 115200

                <card> : 1 - 4 piece card

                Example : A> DEMO 9600

                Now you can see all PCIPORT card information on the mainboard

                Example : A> DEMO 9600 1

                Now you can see the port information for you choose card
                number.

         There are 3 bars in each window that shows the input data count,
         output data count,  baud rate . (max is 16 ports)

         "ESC" : Exit form the DEMO program to the DOS.


