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

📄 rs232.doc

📁 RS232.C was written to provide all of the basic functionality needed to employ serial I/O in any a
💻 DOC
📖 第 1 页 / 共 4 页
字号:

             To determine the appropriate I/O address for a given COM port's
             UART, rs_initport first uses the BIOS data area and, failing
             this, uses the "standard" I/O addresses.  Standard IRQ's are also
             assumed.  If a serial adapter has been installed with other than
             the standard I/O addresses and IRQ's, rs_initport will not find
             the UART and will fail.  The standard addresses and IRQ's assumed
             are:
                  port          I/O address            IRQ
                  COM1          3F8                    4
                  COM2          2F8                    3
                  COM3          3E8 (PS/2 = 3220)      4 (PS/2 = 3)
                  COM4          2E8 (PS/2 = 3228)      3 (PS/2 = 4)

             If the port argument is '0' (the character, not the integer),
             rs_initport makes no attempt to determine the base I/O
             address of the UART nor the IRQ.  Instead, the values defined
             by the struct rs_user are used.  If rs_user was never
             initialized, rs_initport returns -3.  The structure has the
             following form, and it's members may be accessed globally by
             the application.  For more information, see the section at
             the end of this document file regarding use of more than one
             port simultaneously.

                   struct rs_userport{
                     int base;
                     char irq;
                     }rs_user;

             If a UART capable of FIFO buffering is detected, this feature is
             automatically enabled.  This can greatly reduce the amount of
             overhead due to interrupts and can prevent "lost characters" due
             to receive overruns at higher transmission speeds.

             rs_initport does not alter the state of any of the modem control
             output lines (DTR or RTS).  They must be explicitly controlled
             using rs_modctrl.


      >   rs_sndbyt
        >   Purpose:
              Sends a single byte.

        >   Prototype:
              int rs_sndbyt(int rs_snd);

        >   Arguments:
              The byte to send (int converted to char).

        >   Return Value:
              Returns 0 if the byte was successfully written to the output
              buffer.  Returns -1 no port open or byte could not be written.

        >   Examples:

            if(rs_sndbyt('A'))
              printf("Unable to send message\n");

            rs_sndbyt(getche());

        >   Notes:
              rs_sndbyt writes the character into the output buffer and
              returns immediately without waiting for the character to
              actually be transmitted.  If there is no room in the output
              buffer, rs_sndbyt will wait until there is room unless output is
              currently disabled via flow control.  In this case, rs_sndbyt
              returns -1 to indicate failure.
              If transmit interrupts are disabled by defining RS_POLLED_XMIT,
              the buffer is not used and the character is sent when the UART
              is free to send it.  If output is disabled via flow control,
              the character is not sent and rs_sndbyt returns -1.

      >   rs_sndstr

        >   Purpose:
              Sends a string of bytes.

        >   Prototype:
              int rs_sndstr(int rs_sndcnt, char *rs_sndstr);

        >   Arguments:
              rs_sndcnt indicates the number of bytes to be sent - if a number
              other than 0 is specified, the string need not be nul
              terminated.  If rs_sndcnt is 0, rs_sndstr is treated as a nul
              terminated string and characters will be sent up to but not
              including the terminating nul.  rs_sndstr is a character pointer
              to the string to be sent.  rs_sndstr can be larger than the size
              of the output buffer and up to 32767 bytes.

        >   Return Value:
              Function returns 0 on success.  If no port is open, it returns
              -1.  If the entire string could not be written to the output
              buffer, the number of characters written is returned.

        >   Examples:

              rs_sndstr(0, "Hello, world.");

              if(rs_sndstr(strlen(msg),msg)
                printf("Message could not be sent\n");

        >   Notes:
              Like rs_sndbyt, rs_sndstr writes the characters to the output
              buffer and returns immediately - it does not wait for the
              characters to actually be transmitted.  If there is insufficient
              room in the output buffer, it waits until there is unless output
              is currently disabled via flow control.  In this case, rs_sndbyt
              returns the number of characters that were written to the
              buffer.
              If transmit interrupts are disabled by defining RS_POLLED_XMIT,
              the output buffer is not used and the function does not return
              until the entire string has been sent or output becomes disabled
              via flow control.

      >   rs_getbyt

        >   Purpose:
              Gets a single byte.

        >   Prototype:
              int rs_getbyt(void);

        >   Arguments:
              none

        >   Return Value:
              Returns the next received byte (converted to int) available.  If
              no characters are currently waiting to be read from the input
              buffer, returns -1.

        >   Examples:

              while(rs_inrcvd()
                putch(rs_getbyt());

              if((ch = rs_getbyt()) < 0)
                printf("No received character\n");

        >   Notes:
              rs_getbyt does not wait for incoming characters - it returns -1
              immediately if no received characters are available.

      >   rs_getstr

        >   Purpose:
              Gets a string of bytes.

        >   Prototype:
              int rs_getstr(int rs_getcnt, char *rs_getbuf);

        >   Arguments:
              rs_getcnt is the number of characters to be read from the input
              buffer.  If rs_getcnt is 0, characters are read from the input
              buffer until a nul character is encountered, which is included
              in rs_getbuf.  rs_getbuf is a character pointer to the string
              which the received characters will be written in to.  rs_getbuf
              must be large enough to hold the entire string plus a
              terminating nul character.  rs_getstr can be used to get a
              string up to the input buffer size.

        >   Return Value:
              Returns -1 if no port is open or the number of characters read
              from the input buffer and written to the target string.

        >   Examples:

              if(rs_getstr(8,msg) < 8)
                printf("Message incomplete\n");

        >   Notes:
              If the requested number of characters are not available,
              rs_getstr does not wait for them to become available but instead
              reads as many as are available and returns the number copied.

      >   rs_inrcvd

        >   Purpose:
              Returns number of bytes which been received.

        >   Prototype:
              unsigned rs_inrcvd(void);

        >   Arguments:
              none

        >   Return Value:
              Returns the number of characters which have been received and
              are ready to be read from the input buffer by rs_getbyt or
              rs_getstr.

        >   Examples:

              in_cnt = rs_inrcvd();

              rs_getstr(rs_inrcvd(),msg);

        >   Notes:
              rs_inrcvd will never return a value greater than the input
              buffer size specified when rs_initport was called, even if an
              input buffer overflow has occurred.  Use rs_error to determine
              if there has been an overflow.

      >   rs_peek

        >   Purpose:
              Returns next available character from input buffer.  Leaves
              character in buffer.

        >  Prototype:
              int rs_peek(void);

        >  Arguments:
              none

        >  Return Value:
              Next available character in input buffer.  If there is not
              currently a port open, or if there are no characters waiting
              to be read from the buffer, returns -1.

        >  Examples:

              next_char = rs_peek();

              if(rs_peek() >= 0){
                if(rs_peek() == JUNK)
                  rs_getbyt();
                else
                  message = rs_getbyt();
                }


      >   rs_outfre

        >   Purpose:
              Returns amount of free space remaining in output buffer.  If
              RS_POLLED_XMIT is defined, this function will not return a
              meaningful value.

        >   Prototype:
              unsigned rs_outfre(void);

        >   Arguments:
              none

        >   Return Value:
              Unsigned integer indicating current amount of free space in
              bytes that are available in the output buffer.

        >   Examples:

              if(rs_outfre() == 0)
                printf("Serial port busy - try again later\n");

              printf("%u bytes are currently buffered for output\n",
                         output_buffer_size - rs_outfre());

      >   rs_scanin

        >   Purpose:
              Scans characters not yet read from input buffer for the
              specified string.

        >   Prototype:
              int rs_scanin(char *);

        >   Arguments:
              Character pointer of string to search for.

        >   Return Value:
              Int containing either the offset into the buffer of the
              first occurence of the search string (if found) or -1 if the
              string was not found.

        >   Examples:

              if(rs_scanin("CONNECT") < 0)
                printf("No connect message from modem\n");

              offset = rs_scanin("BYE");
              if(offset)
                rs_getstr(offset + 1,buf);


      >   rs_error

        >   Purpose:
              Returns code for last error detected.

        >   Prototype:
              int rs_error(void);

        >   Arguments:
              none

        >   Return Value:
              Returns integer whose bit pattern indicates the last error which

⌨️ 快捷键说明

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