home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ASYNCH13.ZIP / ASYNC.DOC < prev    next >
Encoding:
Text File  |  1990-11-28  |  43.3 KB  |  955 lines

  1.           ASYNCx.LIB 1.30 Documentation                         11/28/90
  2.  
  3.                                   HISTORY:
  4.           Version 1.00 - 3/7/89:
  5.             This version supports the basic functions of interrupt
  6.             driven asyncronous communications on the IBM PC and PS/2. It
  7.             supports COM1 and COM2 on PCs and COM1 through COM8 on
  8.             microchannel machines. XON/XOFF control routines and logic
  9.             exist, but do not work. But since everything else tests out
  10.             OK, I'm going ahead and releasing the library without the
  11.             XON/XOFF stuff fixed. (Just don't turn on XON/XOFF
  12.             handling.)
  13.  
  14.           Version 1.01 - 4/25/89:
  15.             Oops. I forgot to provide a way to modify the communications
  16.             parameters of a port while it's open. The a_params function
  17.             has been added for this purpose.
  18.  
  19.           Version 1.02 - 4/28/89:
  20.             More oversights sighted. This version adds 6 new functons
  21.             (a_getlcr, a_getlsr, a_getmcr, a_getmsr, a_setlcr, and
  22.             a_setmcr) to handle direct read and writing to control and
  23.             status ports of the UART.
  24.  
  25.           Version 1.03 - 11/30/89:
  26.             This version fixes an initialization problem that was
  27.             experienced on some machines. On these machines, if a
  28.             character was received before one was sent, no interrupt
  29.             would be generated for the character to be read from the
  30.             UART'd data buffer and over-run error would result from any
  31.             further data received. This has been fixed.
  32.  
  33.             Also, the a_putc() function has been mostly re-written. See
  34.             the description of this function where it is listed in the
  35.             FUNCTIONS: section of this document for more details.
  36.  
  37.           Version 1.10 - 11/06/89
  38.             The only real change in this version is an extra parameter
  39.             for the a_waitquiet() function. I provided a way for the
  40.             programmer to specify a maximum amount of time to wait for
  41.             the desired gap in the incomming data stream. (Previous
  42.             versions of a_waitquiet() would never return if presented
  43.             with a continual stream of incomming data.)
  44.  
  45.           Version 1.20 - 12/11/89
  46.             The XON/XOFF flow control has finally been added. Because of
  47.             this, I have changed the interfaces to some of the functions
  48.             of this library. The modifications are detailed in the
  49.             disucussions of the appropriate functions, but here is a
  50.             summary of the changes made:
  51.  
  52.             1. int a_puts(char *s,ASYNC *p) now returns the number of
  53.                characters that it successfully transmitted. If an XOFF
  54.                character is received in the middle of the transmission,
  55.                this count may fall short of the length of the string.
  56.  
  57.             2. int a_iflush(ASYNC *p) sends an XON character if an XOFF
  58.                character has allready been sent. If the XON character
  59.                cannot be added to the output buffer (under the same
  60.                constraints that apply to a_getc), the buffer is not
  61.                flushed and a value of -1 is returned. Otherwise, the
  62.                buffer is flushed and a value of 0 is returned.
  63.  
  64.             A few of the other functions received a minor logical face-
  65.             lift. The a_open function does not turn on XON/XOFF flow
  66.             control. If you want to take advantage of XON/XOFF, you must
  67.             set XON and XOFF buffer threshold levels using the setxonoff
  68.             function.
  69.  
  70.           Version 1.21 - 01/17/89
  71.             The a_gets() function has been modified so that it will only
  72.             return a value of NULL (to indicate an EOF state on the
  73.             async port) if no characters at all are received over that
  74.             port. In previous versions, NULL would be returned if a
  75.             blank line was received.
  76.  
  77.           Version 1.30 - 01/18/89
  78.             The a_open() function no longer takes DTR and RTS down and
  79.             back up during initialization of the async port. It just
  80.             leaves both up. Also, a_close() has sprouted a new parameter
  81.             that allows the application closing an async port to control
  82.             whether DTR and RTS are left up or down when the port is
  83.             closed.
  84.  
  85.                                  PHILOSOPHY:
  86.           The interface to the routines in this library is closely
  87.           analogous to the interface used with the ANSI C streem I/O
  88.           functions. I made every effort to allow you to handle the
  89.           async ports of the computer in the same way in which you would
  90.           handle a stream opened in binary (as opposed to text) mode.
  91.           While the nature of an asyncronous environment forced certain
  92.           concessions in the conformity vs. practicality battles, I
  93.           believe C programmers will find the interface to these
  94.           functions familiar and intuitive.
  95.  
  96.           If you were wondering: I'm not asking for any money for this.
  97.           I'm making no claim that these routines are suitable for you.
  98.           I don't even claim that the use (proper or otherwise) will not
  99.           harm (or even destroy) hardware or software that you value.
  100.           One last thing that I don't do is tell you who I am, where I
  101.           live, or how to get in touch with me for support. I wrote this
  102.           async library because I needed it; not to make a fast buck.
  103.           Just think of me as a philanthropic programmer who wants to
  104.           give other programmers a leg up in communications programming.
  105.  
  106.                                   FEATURES:
  107.  
  108.           o All source is available. Turbo C 2.0 or higher is required
  109.             for recompilation.
  110.  
  111.           o Supports COM1 and COM2 on PC/XTs and COM1 through COM8 on
  112.             PS/2s.
  113.  
  114.           o Bit rates from 300 to 19200,
  115.             Even, odd, mark, space, and no parity,
  116.             1 or 2 stop bits, and
  117.             from 5 to 8 data bits per word.
  118.  
  119.           o Input and output buffering for support of the higher bit
  120.             rates.
  121.  
  122.           o Output buffering can be turned off to make programming in an
  123.             async environment a little simpler.
  124.  
  125.           o XON/XOFF flow control with individually adjustable
  126.             thresholds is supported.
  127.  
  128.  
  129.                            A LITTLE MORE TECHNICAL:
  130.           COM1 is handled via INT 0xC (IRQ 4) and COM2 through COM8 are
  131.           handled via INT 0xB (IRQ 3). The base port addresses for COM1
  132.           through COM8 are 0x3f8, 0x2f8, 0x3220, 0x3228, 0x4220, 0x4228,
  133.           0x5220, and 0x5228, respectively. When the a_open function
  134.           opens a port, the UART corresponding to that port is told to
  135.           generate an interrupt whenever a character is sent or
  136.           received, but not when an error or line-level change occurs.
  137.           This, of course, is turned off when the port is closed. The
  138.           routines in this async library completely bypass BIOS INT 14h.
  139.           This allows reliable communication at speeds up to 19200 baud.
  140.  
  141.        ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  142.        ▒▒ NOTE: When a you open a port with the a_open function, you are ▒▒
  143.        ▒▒ changing either interrupt vector 0xB or 0xC, depending on what ▒▒
  144.        ▒▒ port you open. If you fail to close the port with the a_close  ▒▒
  145.        ▒▒ function, these vectors will never be restored to their        ▒▒
  146.        ▒▒ original values. If you allow your program to end without      ▒▒
  147.        ▒▒ EXPLICITLY CLOSING ALL OPENED PORTS, your machine will         ▒▒
  148.        ▒▒ probably crash the next time there is any activity on your     ▒▒
  149.        ▒▒ async line (or modem or whatever).                             ▒▒
  150.        ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  151.  
  152.                       Creation and use of ASYNCx.LIB files:
  153.           The batch file CREASYNC.BAT has been provided to compile each
  154.           of the modules into a .OBJ form and to put each .OBJ file into
  155.           the ASYNCx.LIB file. CREASYNC.BAT takes one single-character
  156.           parameter on its command line. This character is t for tiny, s
  157.           for small, m for medium, c for compact, l for large, or h for
  158.           huge memory model and will replace the x in ASYNCx.LIB to
  159.           produce ASYNCT.LIB, ASYNCS.LIB, ASYNCM.LIB, ASYNCC.LIB,
  160.           ASYNCL.LIB, and ASYNCH.LIB, respectively.
  161.  
  162.           These 6 library files (assuming that you create all 6 of them)
  163.           should be copied to where ever it is that you keep the rest of
  164.           the .LIB files. This way Turbo C will know where to find them
  165.           when it wants them.
  166.  
  167.           To compile and link a program that uses one of the ASYNCx.LIB
  168.           files, issue a command similar to the following:
  169.  
  170.             tcc -ms myprog.c asyncs.lib
  171.  
  172.           Note that the -ms option (for small memory model) will only
  173.           work with ASYNCS.LIB and not any of the other 5 ASYNCx.LIB
  174.           libraries. If you want to use the huge memory model, you would
  175.           issue a command similar to the following:
  176.  
  177.             tcc -mh myprog.c asynch.lib
  178.  
  179.           A program called MYPROG.C has been provided for you. It is a
  180.           very rudimentary communications package. It's heavily
  181.           commented and I hope it'll help you to get started with the
  182.           ASYNC library.
  183.  
  184.                                     FUNCTIONS:
  185.  
  186.           This is a list of all the functions in the ASYNC library. Each
  187.           is described in detail on the following pages. (The functions
  188.           are listed in alphabetical order by function name.)
  189.  
  190.           int a_break(ASYNC *p, int t);
  191.  
  192.           ASYNC *a_close(ASYNC *p,int fc);
  193.  
  194.           int a_eof(ASYNC *p,int t);
  195.  
  196.           int a_icount(ASYNC *p);
  197.  
  198.           int a_iflush(ASYNC *p);
  199.  
  200.           int a_getc(ASYNC *p);
  201.  
  202.           int a_getlcr(ASYNC *p);
  203.  
  204.           int a_getlsr(ASYNC *p);
  205.  
  206.           int a_getmcr(ASYNC *p);
  207.  
  208.           int a_getmsr(ASYNC *p);
  209.  
  210.           char *a_gets(char *s,int n,ASYNC *p,int t);
  211.  
  212.           int a_ocount(ASYNC *p);
  213.  
  214.           int a_oflush(ASYNC *p);
  215.  
  216.           ASYNC *a_open(int port,int baud,int par,int dbits,int sbits,
  217.                         int ibufsize,int obufsize);
  218.  
  219.           int a_params(ASYNC *p,int baud,int par,int dbits,int sbits);
  220.  
  221.           int a_portno(ASYNC *p);
  222.  
  223.           int a_printf(ASYNC *p,char *format,...);
  224.  
  225.           int a_putc(int c,ASYNC *p);
  226.  
  227.           int a_puts(char *s,ASYNC *p);
  228.  
  229.           int a_read(void *buf,int s,int n ASYNC *p,int t);
  230.  
  231.           void a_setlcr(ASYNC *p,int newval);
  232.  
  233.           void a_setmcr(ASYNC *p,int newval);
  234.  
  235.           a_setxonoff(ASYNC *p,int xon,int xoff);
  236.  
  237.           int a_ungetc(int c,ASYNC *p);
  238.  
  239.           int a_waitfor(ASYNC *p,char *s,int t,int mode);
  240.  
  241.           void a_waitquiet(ASYNC *p,int t,int max,int mode);
  242.  
  243.           int a_write(void *buf,int s,int n,ASYNC *p);
  244.  
  245.  
  246.           ┌───────┐
  247.           │a_break│
  248.           └───────┘
  249.           Function: Turn on the BREAK signal for a specified duration.
  250.  
  251.           Syntax:   int a_break(ASYNC *p, int t);
  252.  
  253.           Remarks:  a_break holds the transmit line of the async port in
  254.                     the BREAK state for t 18ths of a second.
  255.  
  256.           Return:   a_break returns 0 if port p is open. A value of -1
  257.                     is returned if port p has not been opened. (An
  258.                     unopened port is recognized by a NULL value in p.)
  259.  
  260.           ┌───────┐
  261.           │a_close│
  262.           └───────┘
  263.           Function: Close an async port.
  264.  
  265.           Syntax:   ASYNC *a_close(ASYNC *p,int fc);
  266.  
  267.           Remarks:  a_close closes port p. This involves deallocating
  268.                     the memory occupied by its input buffer, output
  269.                     buffer (if one was allocated for it), and by the
  270.                     ASYNC structure itself. Also, the interrupt that
  271.                     was enabled when the port was opened is disabled
  272.                     (provided that no other port is using it).
  273.  
  274.                     Value of fc may be any combination of the bits of
  275.                     MCR_DTR and MCR_RTS to leave the DTR and/or RTS
  276.                     signals active after the port is closed.
  277.  
  278.           Return:   a_close always returns NULL. This is to facilitate
  279.                     resetting the ASYNC pointer variable to NULL. For
  280.                     instance, you might close a port by saying:
  281.  
  282.                                  port=a_close(port,0);
  283.  
  284.                     This would close the async port, drop DTR and RTS,
  285.                     and give port a value of NULL at the same time.
  286.                     While a_close(port,0) would work all by itself,
  287.                     setting port to NULL at the same time is the
  288.                     preferred method of closing a it.
  289.  
  290.           ┌─────┐
  291.           │a_eof│
  292.           └─────┘
  293.           Function: Determine whether or not data has stopped comming in
  294.                     over a given port.
  295.  
  296.           Syntax:   int a_eof(ASYNC *p,int t);
  297.  
  298.           Remarks:  a_eof waits for up to t 18ths of a second for data
  299.                     to arrive in the input buffer of port p.
  300.  
  301.           Return:   If data appears in the input buffer before the
  302.                     specified interval expires, a value of 0 is
  303.                     returned. Otherwise a value of 1 is returned to
  304.                     indicate that the specified port is in an EOF state.
  305.  
  306.           ┌────────┐
  307.           │a_icount│
  308.           └────────┘
  309.           Function: Return the number of characters in the input buffer
  310.                     of an async port.
  311.  
  312.           Syntax:   int a_icount(ASYNC *p);
  313.  
  314.           Remarks:  a_icount is a macro that returns the value of the
  315.                     icount field of the ASYNC structure to which p
  316.                     points.
  317.  
  318.           Return:   a_icount returns the number of characters waiting to
  319.                     be read from the input buffer of port p.
  320.  
  321.           ┌────────┐
  322.           │a_iflush│
  323.           └────────┘
  324.           Function: Discard any data in a port's input buffer.
  325.  
  326.           Syntax:   int a_iflush(ASYNC *p);
  327.  
  328.           Remarks:  Any characters in the input buffer of port p are
  329.                     removed. If an XOFF character has been sent out, an
  330.                     XON character is sent when the input buffer is
  331.                     emptied. This lets the equipment on the other end of
  332.                     the line know that it's ok to send data again.
  333.  
  334.           Returns:  a_iflush returns 0 if the operation is successful.
  335.                     Otherwise, a value of -1 is returned.
  336.  
  337.           ┌──────┐
  338.           │a_getc│
  339.           └──────┘
  340.           Function: Retrieve a character from an async port.
  341.  
  342.           Syntax:   int a_getc(ASYNC *p);
  343.  
  344.           Remarks:  a_getc attempts to retrieve one character from the
  345.                     given async port.
  346.  
  347.           Return:   If a character is in the input buffer of the
  348.                     specified port, the value of that character (without
  349.                     sign extension) is returned as an integer. If no
  350.                     character is available from the specified port, a
  351.                     value of -1 is returned.
  352.  
  353.           ┌────────┐
  354.           │a_getlcr│
  355.           └────────┘
  356.           Function: Get the value of the Line Control Register.
  357.  
  358.           Syntax:   int a_getlcr(ASYNC *p);
  359.  
  360.           Remarks:  a_getlcr gets the value of the Line Control
  361.                     Register. The bitwise encoding of this register is
  362.                     as follows:
  363.  
  364.                     Bits 1 & 0 - Word length:
  365.                                  00 = 5 bits
  366.                                  01 = 6 bits
  367.                                  10 = 7 bits
  368.                                  11 = 8 bits
  369.                     Bit 2      - Number of stop bits:
  370.                                  0 = 1 stop bit
  371.                                  1 = 2 stop bits (1.5 if 5-bit word)
  372.                     Bit 3      - Parity enable:
  373.                                  0 = no parity.
  374.                                  1 = parity enabled and checked.
  375.                     Bits 4 & 5 - Parity mode:
  376.                                  00 = odd parity
  377.                                  01 = even parity
  378.                                  10 = mark parity
  379.                                  11 = space parity
  380.                     Bit 6      - Break enable:
  381.                                  0 = normal operation
  382.                                  1 = Transmit line held active.
  383.                     Bit 7      - Divisor latch access
  384.                                  0 = Bottom 2 port addresses used for
  385.                                      transmitting and receiving data
  386.                                      and for IRQ enable.
  387.                                  1 = Bottom 2 port addresses used for
  388.                                      LSB and MSB of baud rate divisor.
  389.  
  390.                     The a_params functions allows access to bits 0
  391.                     through 5 and bit 7 in a much more intuitive way.
  392.                     a_break allows timed access to bit 6. The a_getlcr
  393.                     function is provided so that you can query the
  394.                     communications port about its communications
  395.                     parameters directly.
  396.  
  397.           Return:   a_getlcr returns an integer with bits 0 through 7
  398.                     set to those of the line control register. Bits 8
  399.                     through 15 are set to 0.
  400.  
  401.           ┌────────┐
  402.           │a_getlsr│ << New >>
  403.           └────────┘
  404.           Function: Get the value of the Line Status Register.
  405.  
  406.           Syntax:   int a_getlsr(ASYNC *p);
  407.  
  408.           Remarks:  a_getlsr gets the value of the Line Status Register.
  409.                     The bitwise encoding of this register is as follows:
  410.  
  411.                     Bit 0 - Data received.
  412.                     Bit 1 - Data Overrun.
  413.                     Bit 2 - Parity Error.
  414.                     Bit 3 - Framing Error.
  415.                     Bit 4 - Break received.
  416.                     Bit 5 - Can accept another word to transmit.
  417.                     Bit 6 - Finished transmitting the last word.
  418.                     Bit 7 - Always 0.
  419.  
  420.                     a_getlsr provides a way for you to verify the
  421.                     integrity of the incomming data. If any of bits 1
  422.                     through 3 is set to 1, you can assume that at least
  423.                     one word of data has been lost.
  424.  
  425.                     The "data received" bit is set when the
  426.                     communications port receives one whole word from the
  427.                     async line and has made it available to the
  428.                     computer. Since this also triggers an interrupt that
  429.                     reads the data from the port, you should never see
  430.                     this bit in an active state.
  431.  
  432.                     The "break received" bit can be used to test for
  433.                     break signals received from equipment at the other
  434.                     end of the async line.
  435.  
  436.                     Bit 5 has a value of 1 when the async port is ready
  437.                     to receive a word to be transmitted. It holds this
  438.                     word in a Transmit Buffer Register until it is ready
  439.                     to actually transmit the word.
  440.  
  441.                     Bit 6 has a value of 1 when the async port has
  442.                     finished transmitting a word and is able to start on
  443.                     the next one. The next word will come from the
  444.                     Transmit Buffer Register to be stored in the
  445.                     Transmit Shift Register while it is being
  446.                     transmitted.
  447.  
  448.           Return:   a_getlsr returns an integer with bits 0 through 7
  449.                     set to those of the line status register. Bits 8
  450.                     through 15 are set to 0.
  451.  
  452.           ┌────────┐
  453.           │a_getmcr│ << New >>
  454.           └────────┘
  455.           Function: Get the value of the Modem Control Register.
  456.  
  457.           Syntax:   int a_getmcr(ASYNC *p);
  458.  
  459.           Remarks:  a_getmcr gets the value of the modem control
  460.                     register. The bitwise encoding of this register is
  461.                     as follows:
  462.  
  463.                     Bit 0 - Data Terminal Ready (DTR)
  464.                     Bit 1 - Request to Send (RTS)
  465.                     Bit 2 - Modem Reset (OUT1)
  466.                     Bit 3 - Interrupt Enable
  467.                     Bit 4 - Loopback Enable
  468.  
  469.                     MCR_DTR, MCR_RTS, MCR_OUT1, and MCR_LOOP are
  470.                     #defined in async.h to 1, 2, 4, and 16 for your
  471.                     convenience.
  472.  
  473.                     For almost all communications applications, DTR and
  474.                     RTS should be held high (set to a value of 1)
  475.                     whenever the application is ready to accept data.
  476.                     Some serial equipment is smart enough to stop
  477.                     sending data to a device that is holding it DTR
  478.                     and/or RTS lines low.
  479.  
  480.                     The OUT1 line can be used to reset some modems. Most
  481.                     modems, however, have a command-set oriented method
  482.                     for performing this function.
  483.  
  484.                     Bit 3 (interrupt enable) must remain high (set to 1)
  485.                     for a port's interrupt handler to put incomming data
  486.                     into the input buffer. This is the only way to
  487.                     handle data at baud rates above 1200 baud. DON'T
  488.                     TURN OFF THIS BIT!
  489.  
  490.                     Bit 4 (loopback enable) is for testing the port. If
  491.                     this bit is high (set to 1), the async port will
  492.                     echo back all characters that you send it to be
  493.                     transmitted. One possible use for this feature to
  494.                     test for the existance of an async port. If the
  495.                     loopback feature fails to echo back to you the
  496.                     characters that you send, the port is either missing
  497.                     or broken.
  498.  
  499.           Return:   a_getmcr returns an integer with bits 0 through 4
  500.                     set to those of the modem control register. Bits 5
  501.                     through 15 are set to 0.
  502.  
  503.           ┌────────┐
  504.           │a_getmsr│ << New >>
  505.           └────────┘
  506.           Function: Get the value of the Modem Status Register.
  507.  
  508.           Syntax:   int a_getmsr(ASYNC *p);
  509.  
  510.           Remarks:  a_getmsr gets the value of the Modem Status
  511.                     Register. The bitwise encoding of this register is
  512.                     as follows:
  513.  
  514.                     Bit 0 - CTS changed
  515.                     Bit 1 - DSR changed
  516.                     Bit 2 - RI has gone low
  517.                     Bit 3 - CD changed
  518.                     Bit 4 - Clear To Send (CTS)
  519.                     Bit 5 - Data Set Ready (DSR)
  520.                     Bit 6 - Ring Indicator (RI)
  521.                     Bit 7 - Carrier Detect (CD)
  522.  
  523.                     Bits 4 through 7 may be examined to determine the
  524.                     current status of CTS, DSR, RI, or CD. Bits 0
  525.                     through 3 may be examined to detect an change in
  526.                     CTS, DSR, RI, or CD.
  527.  
  528.           Return:   a_getmsr returns an integer with bits 0 through 7
  529.                     set to those of the modem control register. Bits 8
  530.                     through 15 are set to 0.
  531.  
  532.           ┌──────┐
  533.           │a_gets│
  534.           └──────┘
  535.           Function: Retrieve a string from an async port.
  536.  
  537.           Syntax:   char *a_gets(char *s,int n,ASYNC *p,int t);
  538.  
  539.           Remarks:  a_gets reads up to n-1 characters from port p into
  540.                     the buffer pointed to by s. This function stops
  541.                     reading the string when a \r character is read. The
  542.                     \r is replaced with a null terminator in the string
  543.                     buffer. Any \n characters or \0 characters that are
  544.                     read from the async port are ignored. a_gets will
  545.                     wait for up to t 18ths of a second for the string to
  546.                     arrive in the input buffer.
  547.  
  548.           Return:   If at least one character is read from the port's
  549.                     input buffer, the address of the string buffer is
  550.                     returned, whether any characters actually made it
  551.                     into the string or not. If no characters are read
  552.                     from the input buffer at all during the specified
  553.                     interval, a value of NULL is returned to indicate
  554.                     and eof condition.
  555.  
  556.           ┌────────┐
  557.           │a_ocount│
  558.           └────────┘
  559.           Function: Return the number of characters in the output buffer
  560.                     of an async port.
  561.  
  562.           Syntax:   int a_ocount(ASYNC *p);
  563.  
  564.           Remarks:  a_ocount is a macro that returns the value of the
  565.                     ocount field of the ASYNC structure to which p
  566.                     points. This value is real handy if you have just
  567.                     send a command over the port and would like to wait
  568.                     for it to be transmitted before you start looking
  569.                     for the reply.
  570.  
  571.           Return:   a_ocount returns the number of characters waiting to
  572.                     be transmitted from port p. A value of 0 is always
  573.                     returned if output buffering was not enabled when
  574.                     the port was opened.
  575.  
  576.           ┌────────┐
  577.           │a_oflush│
  578.           └────────┘
  579.           Function: Discard any data in a port's output buffer.
  580.  
  581.           Syntax:   int a_oflush(ASYNC *p);
  582.  
  583.           Remarks:  Any characters in the output buffer of port p are
  584.                     removed.
  585.  
  586.           Returns:  a_oflush returns 0 if the operation is successful.
  587.                     Otherwise, a value of -1 is returned.
  588.  
  589.           ┌──────┐
  590.           │a_open│
  591.           └──────┘
  592.           Function: Open an async port for use.
  593.  
  594.           Syntax:   ASYNC *a_open(int port,int baud,int par,int dbits,
  595.                                   int sbits,int ibufsize,int obufsize);
  596.  
  597.           Remarks:  a_open opens an async port for use with the given
  598.                     characteristics. This involves allocating space in
  599.                     memory for its ASYNC control structure, input
  600.                     buffer, and output buffer (if one is specified).
  601.                     port may be any integer in the range from 1 to 8
  602.                     corresponding to the COM1 through COM8
  603.                     specifications that DOS uses. (COM3 through COM8 are
  604.                     only available on PS/2s.) baud specifies the baud
  605.                     rate to be used for this port and may be any integer
  606.                     from 300 to 19200. (But stick to the more common
  607.                     baud rates if you want your software to work with
  608.                     other software.) par specifies the parity to be used
  609.                     for this port. The choices are #defined in ASYNC.H
  610.                     as PAR_NONE, PAR_ODD, PAR_EVEN, PAR_MARK, and
  611.                     PAR_SPACE. dbits is the number of data bits to use
  612.                     and must be in the range from 5 to 8. sbits is the
  613.                     number of stop bits to use and must be either 1 or
  614.                     2. ibufsize is the number of bytes to allocate for
  615.                     the input buffer for this port. Make it large enough
  616.                     to avoid allowing it to overflow. (From 4000 to 8000
  617.                     bytes is generally a good number, but mileage may
  618.                     vary.) obufsize is the number of bytes to allocate
  619.                     for the output buffer for this port. If this number
  620.                     is 0, no output buffering will be used. (Note: You
  621.                     MUST specify an output buffer size greater than 0 if
  622.                     you intend to use XON/XOFF handshaking in your
  623.                     program.)
  624.  
  625.           Return:   a_open returns a pointer to the ASYNC control
  626.                     structure for the port being opened. If, however,
  627.                     the port cannot be opened (because of insufficient
  628.                     memory for the buffers), a value of NULL will be
  629.                     returned.
  630.  
  631.           ┌────────┐
  632.           │a_params│ << New >>
  633.           └────────┘
  634.           Function: Change the communications parameters of a port that
  635.                     has already been opened.
  636.  
  637.           Syntax:   int a_params(ASYNC *p,int baud,int par,
  638.                                  int dbits,int sbits);
  639.  
  640.           Remarks:  This function can only be used on a port that is
  641.                     already open. p identifies the port to modify. Each
  642.                     of the other parameters of this function are the
  643.                     same as the corresponding parameters of the a_open
  644.                     function.
  645.  
  646.           Return:   a_params returns 0 if all goes well. It does no
  647.                     range-checking on the parameter data, but if the
  648.                     port has not been opened, a_params returns a value
  649.                     of -1.
  650.  
  651.           ┌────────┐
  652.           │a_portno│
  653.           └────────┘
  654.           Function: Return the port number (1 through 8) of a given
  655.                     port.
  656.  
  657.           Syntax:   int a_portno(ASYNC *p);
  658.  
  659.           Remarks:  Find the number of the port with which p is
  660.                     associated.
  661.  
  662.           Return:   a_portno returns an integer from 1 to 8 to indicate
  663.                     the number of the port with which p is associated.
  664.                     If p is not found to be associated with any port, a
  665.                     value of 0 is returned.
  666.  
  667.           ┌────────┐
  668.           │a_printf│
  669.           └────────┘
  670.           Function: Send formatted text to an async port.
  671.  
  672.           Syntax:   int a_printf(ASYNC *p,char *format,...);
  673.  
  674.           Remarks:  a_printf works exactly like fprintf except that the
  675.                     first parameter points to an ASYNC structure instead
  676.                     of a FILE structure. The length of the resulting
  677.                     output string is limited to 1023 characters and its
  678.                     is a really bad idea to imbed a null character in
  679.                     the middle of it.
  680.  
  681.           Return:   a_printf returns 0 if the the port has been opened
  682.                     or -1 if it has not.
  683.  
  684.           ┌──────┐
  685.           │a_putc│
  686.           └──────┘
  687.           Function: Send a character to an async port.
  688.  
  689.           Syntax:   int a_putc(int c,ASYNC *p);
  690.  
  691.           Remarks:  a_putc attempts to send the character value of c to
  692.                     port p. If the port is ready to transmit a
  693.                     character, the character is transmitted immediately.
  694.                     Otherwise, if an output buffer was allocated for
  695.                     this port when it was opened, the character is put
  696.                     into the output buffer. If no output buffer was
  697.                     allocated for this port, a_putc waitw until the port
  698.                     is ready to transmit another character, and
  699.                     transmits the character value of c when the port is
  700.                     ready.
  701.  
  702.           Return:   If the character is successfully transmitted,
  703.                     a_putc() returns the value passed to it in c. If the
  704.                     port is invalid (not opened), a value of -1 is
  705.                     returned. If XON/XOFF (which is not currently
  706.                     supported) is turned on, and an XOFF character has
  707.                     been received, and the output buffer is full, a
  708.                     value of -1 will also be returned.
  709.  
  710.                     Note: In versions prior to 1.03 of the ASYNC
  711.                     library, a -1 would be returned if the an XOFF
  712.                     character had been received (regardless of the state
  713.                     of the output buffer) or if the output buffer was
  714.                     full. Now, unless an XOFF character has been
  715.                     received, a_putc will wait for the output buffer to
  716.                     have room for the character it is trying to send.
  717.                     This means that a -1 is only returned if an XOFF
  718.                     character has been received and the output buffer is
  719.                     full.
  720.  
  721.           ┌──────┐
  722.           │a_puts│
  723.           └──────┘
  724.           Function: Send a string to an async port to be transmitted.
  725.  
  726.           Syntax:   int a_puts(char *s,ASYNC *p);
  727.  
  728.           Remarks:  a_puts sends the null-terminated string of
  729.                     characters pointed to by s to port p. It calls the
  730.                     a_putc function to do this. Only the characters
  731.                     actually in the string are sent. No \r or \n
  732.                     characters are appended.
  733.  
  734.           Return:   If the string is empty, return a value of 0.
  735.                     Otherwise, return the value of the last character
  736.                     transmitted. If the p is not a valid port, return a
  737.                     value of -1.
  738.  
  739.           ┌──────┐
  740.           │a_read│
  741.           └──────┘
  742.           Function: Read a block of data from an async port.
  743.  
  744.           Syntax:   int a_read(void *buf,int s,int n ASYNC *p,int t);
  745.  
  746.           Remarks:  a_read reads n objects consisting of s bytes each
  747.                     from port p into the buffer pointed to by buf. This
  748.                     routine will wait for a maximum or t 18ths of a
  749.                     second for the block to be read.
  750.  
  751.           Return:   The number of whole objects (not necessarily bytes)
  752.                     received is returned. If no data arrives at all or
  753.                     if the port is not valid, a value of 0 is returned.
  754.  
  755.           ┌────────┐
  756.           │a_setlcr│ << New >>
  757.           └────────┘
  758.           Function: Set the value of the Line Control Register.
  759.  
  760.           Syntax:   void a_setlcr(ASYNC *p,int newval);
  761.  
  762.           Remarks:  a_setlcr sets the value of the Line Control
  763.                     Register. The bitwise encoding of this register is
  764.                     as follows:
  765.  
  766.                     Bits 1 & 0 - Word length:
  767.                                  00 = 5 bits
  768.                                  01 = 6 bits
  769.                                  10 = 7 bits
  770.                                  11 = 8 bits
  771.                     Bit 2      - Number of stop bits:
  772.                                  0 = 1 stop bit
  773.                                  1 = 2 stop bits (1.5 if 5-bit word)
  774.                     Bit 3      - Parity enable:
  775.                                  0 = no parity.
  776.                                  1 = parity enabled and checked.
  777.                     Bits 4 & 5 - Parity mode:
  778.                                  00 = odd parity
  779.                                  01 = even parity
  780.                                  10 = mark parity
  781.                                  11 = space parity
  782.                     Bit 6      - Break enable:
  783.                                  0 = normal operation
  784.                                  1 = Transmit line held active.
  785.                     Bit 7      - Divisor latch access
  786.                                  0 = Bottom 2 port addresses used for
  787.                                      transmitting and receiving data
  788.                                      and for IRQ enable.
  789.                                  1 = Bottom 2 port addresses used for
  790.                                      LSB and MSB of baud rate divisor.
  791.  
  792.                     The a_params functions allows access to bits 0
  793.                     through 5 and bit 7 in a much more intuitive way.
  794.                     a_break allows timed access to bit 6. The a_setlcr
  795.                     function is provided so that you can have complete
  796.                     control over the break signal controled by bit 6.
  797.  
  798.           ┌────────┐
  799.           │a_setmcr│ << New >>
  800.           └────────┘
  801.           Function: Set the value of the Modem Control Register.
  802.  
  803.           Syntax:   void a_setmcr(ASYNC *p,int newval);
  804.  
  805.           Remarks:  a_setmcr sets the value of the modem control
  806.                     register. The bitwise encoding of this register is
  807.                     as follows:
  808.  
  809.                     Bit 0 - Data Terminal Ready (DTR)
  810.                     Bit 1 - Request to Send (RTS)
  811.                     Bit 2 - Modem Reset (OUT1)
  812.                     Bit 3 - Interrupt Enable
  813.                     Bit 4 - Loopback Enable
  814.  
  815.                     MCR_DTR, MCR_RTS, MCR_OUT1, and MCR_LOOP are
  816.                     #defined in async.h to 1, 2, 4, and 16 for your
  817.                     convenience.
  818.  
  819.                     For almost all communications applications, DTR and
  820.                     RTS should be held high (set to a value of 1)
  821.                     whenever the application is ready to accept data.
  822.                     Some serial equipment is smart enough to stop
  823.                     sending data to a device that is holding it DTR
  824.                     and/or RTS lines low.
  825.  
  826.                     The OUT1 line can be used to reset some modems. Most
  827.                     modems, however, have a command-set oriented method
  828.                     for performing this function. This bit is set and
  829.                     then cleared when a port is opened with the a_open
  830.                     function. This is necessary to reset the UART so
  831.                     that it will generate the appropriate interrupts.
  832.  
  833.                     Bit 3 (interrupt enable) must remain high (set to 1)
  834.                     for a port's interrupt handler to put incomming data
  835.                     into the input buffer. This is the only way to
  836.                     handle baud rates above 1200 baud unless the
  837.                     communications application is to run on a fairly
  838.                     fast machine. <<< DON'T CLEAR THIS BIT! >>> At the
  839.                     risk of infuriating some programmers, I wrote
  840.                     a_setmcr() in such a way that it can't be used to
  841.                     clear bit 3.
  842.  
  843.                     Bit 4 (loopback enable) is for testing the port. If
  844.                     this bit is high (set to 1), the async port will
  845.                     echo back all characters that you send it to be
  846.                     transmitted. One possible use for this feature to
  847.                     test for the existance of an async port. If the
  848.                     loopback feature fails to echo back to you the
  849.                     characters that you send, the port is either missing
  850.                     or broken.
  851.  
  852.           ┌───────────┐
  853.           │a_setxonoff│ << Not yet operational >>
  854.           └───────────┘
  855.           Function: Set the levels at which XON and XOFF characters will
  856.                     be sent. Xon and Xoff can also be turn off with this
  857.                     function.
  858.  
  859.           Syntax:   a_setxonoff(ASYNC *p,int xon,int xoff);
  860.  
  861.           Remarks:  XON/XOFF is handled by the ASYNC routines in the
  862.                     following way: If there are at least xoff characters
  863.                     in the input buffer, an XOFF character will be
  864.                     sent. If this has already happened and the number of
  865.                     characters in the input buffer drops to or below
  866.                     xon, an XON will be sent.
  867.                     To turn off XON/XOFF, set both xon and xoff to 0. If
  868.                     XON/XOFF is being turned off and an XOFF character
  869.                     has been sent, an XON character is sent so that
  870.                     communications will not be frozen.
  871.  
  872.           Return:   Returns 0 if p, xon, and xoff are all valid. Returns
  873.                     -1 otherwise.
  874.  
  875.           ┌────────┐
  876.           │a_ungetc│
  877.           └────────┘
  878.           Function: Put a character into the input buffer of an async
  879.                     port so that it will be the next character read from
  880.                     that buffer.
  881.  
  882.           Syntax:   int a_ungetc(int c,ASYNC *p);
  883.  
  884.           Remarks:  a_ungetc puts character c into the input buffer used
  885.                     by port p so that it will be the next character read
  886.                     from that port. This operation may be performed
  887.                     until the input buffer is full.
  888.  
  889.           Return:   The value of c is returned if the operation was
  890.                     successful. If p is invalid or if the input buffer
  891.                     for port p is full, a value of -1 is returned.
  892.  
  893.           ┌─────────┐
  894.           │a_waitfor│
  895.           └─────────┘
  896.           Function: Wait for a given string to arrive from an async
  897.                     port.
  898.  
  899.           Syntax:   int a_waitfor(ASYNC *p,char *s,int t,int mode);
  900.  
  901.           Remarks:  a_waitfor waits for the string pointed to by s to be
  902.                     received from port p for up to t 18ths of a second.
  903.                     If mode is 0, the string must match exactly. If mode
  904.                     is 1, the case of the received string may vary from
  905.                     that of the string s points to. All data received
  906.                     from the input buffer up to and including the string
  907.                     being searched for is discarded. Any data that
  908.                     arrives in the input buffer after the string is
  909.                     found is left in the buffer.
  910.  
  911.           Return:   A value of 0 is returned if a matching string was
  912.                     found. If no match was found, or if p is not valid,
  913.                     a value of -1 is returned.
  914.  
  915.           ┌───────────┐
  916.           │a_waitquiet│
  917.           └───────────┘
  918.           Function: Wait for no characters to arrive in the input buffer
  919.                     of an async port for a given time interval.
  920.  
  921.           Syntax:   void a_waitquiet(ASYNC *p,int t,int max,int mode);
  922.  
  923.           Remarks:  a_waitquiet waits for up to max 18ths of a second
  924.                     for t 18ths of a second to elapse without any
  925.                     characters arriving at port p. If mode is set to 0,
  926.                     any characters that do arrive during the execution
  927.                     of this routine are discarded and the input buffer
  928.                     for port p is empty when this routine returns. If
  929.                     mode is set to 1, characters arriving at port p are
  930.                     detected but not discarded. Be careful of buffer
  931.                     overflow if you use mode 1. If the buffer overflows,
  932.                     the least recent data will be lost and the newest
  933.                     data will be retained.
  934.  
  935.           Return:   This function returns a value of 0 if t 18ths of a
  936.                     second were found to elapse between characters
  937.                     arriving at port p within max 18ths of a second. If
  938.                     no appropriate break in the incomming data stream is
  939.                     found within max 18ths of a second, a value of -1 is
  940.                     returned.
  941.  
  942.           ┌───────┐
  943.           │a_write│
  944.           └───────┘
  945.           Function: Write a block of data to an async port.
  946.  
  947.           Syntax:   int a_write(void *buf,int s,int n,ASYNC *p);
  948.  
  949.           Remarks:  a_write sends n objects, each of which consists of s
  950.                     bytes, to port p from the buffer pointed to by buf.
  951.  
  952.           Return:   This function returns the number of whole objects,
  953.                     not necessarily bytes, written to port p. If p is
  954.                     not valid, a_write returns a value of 0.
  955.