⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 async.doc

📁 用C++写的RS232串口异步通讯功能模块
💻 DOC
📖 第 1 页 / 共 5 页
字号:
         Returns: No return value

         Remarks: Async_restart resets the interrupt vector, UART regis-
                  ters, and 8259 interrupt controller mask to the values
                  necessary for interrupt driven operation.  It also
                  flushes the receive and transmit buffers and resets
                  the Stat1 byte.  Use this function to restart a comm
                  port after spawning a program that may have altered
                  the interrupt vector, UART regs, or interrupt mask.

                  See also async_stop.






         async_rts
         ---------------------------------------------------------------

         Purpose: Sets or resets the Request to Send signal.

         Format:  void async_rts(port, flag);
                   ASYNC *port;       Pointer to ASYNC structure
                   int flag;          Set/Reset RTS flag

         Example:

                  ASYNC *port;

                  if (WantToDropRTS)
                      async_rts(port, 0);
                  else if (WantRTShigh)
                      async_rts(port, 1);


         Returns: No return value

         Remarks: The RTS signal is primarily used for hardware hand-
                  shaking.  When a port is first opened RTS is set HIGH
                  (enabled).  When the port is closed, it is restored to
                  the condition it was in when the port was opened.  To
                  force RTS low when closing a port, regardless of its
                  state when the port was opened, AND the port member,
                  OldMCR with NOT B_RTS.  To force RTS to remain high
                  when the port is closed, OR OldMCR with B_RTS.

                    Force low:    port->OldMCR &= ~B_RTS;
                                  async_close(port);

                    Force high:   port->OldMCR |= B_RTS;
                                  async_close(port);






         async_rx
         ---------------------------------------------------------------

         Purpose: Gets one character from the receive ring buffer.

         Format:  int async_rx(port);
                   ASYNC *port;       Pointer to ASYNC structure

         Examples:

                  ASYNC *port;
                  int rxch;

                  rxch = async_rx(port);       /* rxch == Stat1/char */

                  rxch = async_rx(port) & 0xff;      /* rxch == char */

                   /* chk if char available & process only if it was */
                  if (!((rxch = async_rx(port)) & B_RXEMPTY)
                      procRxdChar(rxch & 0xff);

         Returns: Async_rx returns the character received as the low
                  byte and the Stat1 status byte as the high byte.  If
                  the receive ring buffer was empty when async_rx was
                  called the low byte will be 0 and the high byte will
                  have the B_RXEMPTY bit set.  The Stat1 byte is a bit
                  mapped value that reflects parity errors, framing
                  errors, character overrun errors, receive buffer
                  overflow errors, receive buffer empty, break signal
                  received, and carrier lost.  If no receive errors
                  have occurred, a break signal has not been received,
                  and a carrier is present, Stat1 will be 0.






         async_rx
         ---------------------------------------------------------------

         Remarks: Error bits set in the Stat1 byte are not necessarily
                  associated with the character just taken out of the
                  receive ring buffer.  In fact, they probably are not.
                  The error bits are set when the error is detected and
                  reset when async_reset is called.  For example:

                   1) 20 bytes of data are received with no errors.
                   2) Async_rx has been called 10 times so 10 characters
                      have been taken out of the ring buffer and 10 of
                      the bytes with no errors are still in the buffer.
                   3) A parity error occurs on the next byte received
                      from the UART -- the 11th byte in the receive ring
                      buffer.
                   4) The next byte taken out of the buffer, which is
                      the first of the 10 remaining good bytes will have
                      the parity error bit in the Stat1 byte.  It will
                      remain set until async_reset is called.

                  If the 'ignore characters with errors' bit is set (see
                  async_ignerr), then characters that have either parity
                  or framing errors are never placed in the receive ring
                  buffer.  They are read from the UART and discarded.
                  The error bits in Stat1 are set regardless of the
                  setting of the 'ignore characters with errors' bit.






         async_rxblk
         ---------------------------------------------------------------

         Purpose: Retrieves a block of characters from the receive ring
                  buffer.

         Format:  int async_rxblk(port, buf, maxchars);
                   ASYNC *port;       Pointer to ASYNC structure
                   char *buf;         Buffer for received data
                   int maxchars;      Maximum number of chars to read

         Example:

                  ASYNC *port;
                  char buf[256];
                  int bytesRead;

                  bytesRead = async_rxblk(port, buf, sizeof(buf));

         Returns: Async_rxblk returns the number of bytes read.  This
                  value will be 'maxchars' if there are that many bytes
                  available in the receive buffer.  If there are not
                  'maxchars' in the receive buffer, the entire contents
                  of the receive buffer will be moved to 'buf' and the
                  return value will be the number of bytes that were in
                  the buffer.

         Remarks: Very fast way to read data.  See also async_rx and
                  async_rxblkch.






         async_rxblkch
         ---------------------------------------------------------------

         Purpose: Retrieve bytes from the receive ring buffer until the
                  specified character is found, 'maxchars' are read, or
                  the receive ring buffer is emptied.

         Format:
           int async_rxblkch(port, buf, maxchars, keychar, includekey);
            ASYNC *port;      Pointer to ASYNC structure
            char *buf;        Destination for bytes read
            int maxchars;     Maximum number of chars to read
            char keychar;     Character to scan for
            int includekey;   Flag set if 'keychar' is to be read also

         Example:

           ASYNC *port;
           char buf[256];
           int bytesRead;
           int foundkey;

           bytesRead = async_rxblkch(port, buf, sizeof(buf), '\n', 1);
           if (bytesRead < 0)
               bytesRead = -bytesRead, foundkey = TRUE;
            else
               foundkey = FALSE;

         Returns: This function returns the number of bytes read if the
                  'keychar' is not found.  If the 'keychar' is found the
                  2's complement of the number of bytes read is
                  returned.






         async_rxblkch
         ---------------------------------------------------------------

         Remarks: The 'includekey' flag, which is the last argument of
                  the function, determines whether or not the 'keychar'
                  is to be included if it is found.  If the flag is 1
                  and the 'keychar' is found it will be the last char-
                  acter in the user buffer.  If this flag is 0 and the
                  'keychar' is found, the 'keychar' is left in the re-
                  ceive ring buffer and will be the first character read
                  when you next call one of the async_rx type functions.
                  This can cause a problem if you set this flag to 0 and
                  the 'keychar' is the first character in the receive
                  buffer.  The function will return 0, which would seem
                  to indicate that there were no bytes in the buffer.
                  Actually the character was found but since you are not
                  taking it out of the ring buffer zero bytes are read.
                  There are two ways to check for this condition.  You
                  can first call async_rxcnt to verify there are bytes
                  in the receive buffer and then call async_rxblkch.  If
                  async_rxblkch returns 0, the 'keychar' is there and is
                  the first byte in the buffer.  The other method is to
                  use async_peek to see what the next character in the
                  receive buffer is before calling async_rxblkch.

                  A 2's complement value of the bytes read is returned
                  by async_rxblkch when the 'keychar' is found.  For
                  actual bytes use:
                      bytes = async_rxblkch( ....);
                      if (bytes < 0)
                          bytes = -bytes;
                  A byte count less than zero is the signal the
                  'keychar' was found.  (Except for the circumstance
                  noted in the previous paragraph).

                  See async_rx, async_rxblk, async_rxcnt, async_peek.






         async_rxcnt
         ---------------------------------------------------------------

         Purpose: Returns the number of bytes in the receive ring
                  buffer.

         Format:  int async_rxcnt(port);
                   ASYNC *port;       Pointer to ASYNC structure

         Example:

                  ASYNC *port;

                  BytesInRxBuf = async_rxcnt(port);

         Returns: Number of bytes in the receive ring buffer

         Remarks: This function is implemented as a macro.






         async_rxerr
         ---------------------------------------------------------------

         Purpose: Checks if a receive error has been detected.

         Format:  int async_rxerr(port);
                   ASYNC *port;       Pointer to ASYNC structure

         Example:

                  ASYNC *port;
                  int rxerr_status;

                  rxerr_status = async_rxerr(port);

         Returns: ZR if no receive errors have been detected, NZ if
                  receive error has been detected.

         Remarks: Types of receive errors that are detected by this
                  function are parity errors, framing errors, UART
                  receive register overflow, and receive ring buffer
                  overflow.  This information is also returned as the
                  high byte of the async_rx and async_stat functions.
                  This function is implemented as a macro.

                  See also async_rx, async_stat.






         async_rxflush
         ---------------------------------------------------------------

         Purpose: Empties out the receive ring buffer.

         Format:  void async_rxflush(port);
                   ASYNC *port;       Pointer to ASYNC structure

         Example:

                  ASYNC *port;

                  async_rxflush(port);

         Returns: This function does not have a return value

         Remarks: Clears the receive ring buffer and -- if a 16550 is
                  present in the system with its FIFOs activated --
                  resets the receiver FIFOs.  All data that was in the
                  buffer is lost.  If XON/XOFF flow control is being
                  used and an XOFF has been sent to the remote, this
                  function automatically sends an XON.  An XON is not
                  ALWAYS sent -- only if XFLOW control is in use and the
                  async interrupt routine has sent an XOFF.  It will not
                  clear false XOFFs the remote may have received.






         async_rxfree (5.40)
         ----------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -