Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>_bios_serialcom() access serial communications i/o services</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _bios_serialcom()       Access serial communications I/O services

 #include   <bios.h>

 unsigned _bios_serialcom(service, port, outbyte);
  unsigned service;      Serial communication service desired -- use one of
                         the manifest constants described below.
  unsigned port;         Serial port to use (COM1 = 0, COM2 = 1, etc.)
  unsigned outbyte;      Value to send to serial port

    _bios_serialcom() uses ROM-BIOS interrupt 14h to access RS-232 serial
    communications services to initialize a port, send and receive data,
    and check the port status. Specify the service desired by using one
    of the following manifest constants defined in bios.h:

   _COM_INIT    This service sets up the specified serial port to send or
                receive data. The desired configuration is selected by
                ORing together one of the manifest constants from each of
                the four groups below (baud rate, parity, stop bits,
                length) to use as the outbyte argument.

   Baud rate    _COM_110    110 baud
                _COM_150    150 baud
                _COM_300    300 baud
                _COM_600    600 baud
                _COM_1200   1200 baud
                _COM_2400   2400 baud
                _COM_4800   4800 baud
                _COM_9600   9600 baud

      Parity    _COM_NOPARITY      No parity checking
                _COM_EVENPARITY    Even parity
                _COM_ODDPARITY     Odd parity

   Stop bits    _COM_STOP1    One stop bit used
                _COM_STOP2    Two stop bits used

      Length    _COM_CHR7     Seven-bit characters (standard ASCII)
                _COM_CHR8     Eight-bit characters

                The return value contains line status information in the
                high-order byte, and modem status information in the low-
                order byte. See _COM_STATUS below for the meaning of
                individual bits.

   _COM_SEND    This service sends one character, 'outbyte', to the
                serial port specified by the port argument, and reports
                the success or failure of the operation. If the character
                was sent successfully, the entire high-order byte of the
                return value is zero. A non-specific send error is
                indicated if bit 15 of the return value is set to 1. To
                determine which  error occurred it is recommended that
                service _COM_STATUS, below, be used.

 _COM_RECEIVE   This service receives one character from the serial port
                specified by the port argument, and reports the success
                or failure of the operation. If the character was
                received successfully, the entire high-order byte of the
                return value is zero, and the low-order byte contains the
                character. A non-specific send error is indicated if bit
                15 of the return value is set to 1. To determine which
                error occurred it is recommended that service
                _COM_STATUS, below, be used.

 _COM_STATUS    This service determines the status of the specifed serial
                port. It provides line control status in the high-order
                byte of the return value, and modem status, if one is
                connected, in the low order byte. The errors reported by
                services _COM_SEND and _COM_RECEIVE are a subset of these
                because they use bit 15 (high-order byte, bit 7) as a
                general error flag.

                    High-Order Byte       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

                    Low-Order Byte        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 line signal
                    . . . . . 1 . .       Trailing edge ring detector
                    . . . . . . 1 .       Change in data set ready
                    . . . . . . . 1       Change in clear to send

                    If bit 15 (high-order byte, bit 7) is set, then the
                    rest of the bits are unpredictable.

    Returns:    Varies by service - see descriptions above.

      Notes:    If service _COM_SEND is invoked when there is a time-out
                or other problem at the serial port, the system will halt
                normal processing until the situation is corrected.
                Similarly, _COM_RECEIVE will halt processing if there are
                no characters ready at the serial port. To avoid these
                problems, check serial port status with _COM_STATUS
                before sending or receiving characters.

                Early versions of the ROM-BIOS for the original PC had a
                programming error that would cause "time-out" errors to
                be reported as "transfer shift register empty" and
                "break-detect" errors. This has been corrected in all
                other versions of the ROM-BIOS.

      Speed:    The ROM-BIOS serial I/O services are somewhat faster than
                MS-DOS interrupt 21h, functions 03h and 04h (called
                through intdos() and intdosx()). However, with 4.77 MHz
                PC's the upper reliable limit is probably 4800 baud, even
                for the ROM-BIOS services. For the PS/2 and its extended
                serial port support, use int86() or int86x() to access
                functions 04h and 05h of ROM-BIOS interrupt 14h.

 Portability:   MS-DOS and true PC compatibles only.

------------------------------- Example ---------------------------------

 This program checks the status of serial port COM1 to see if data is ready
 to receive, and reports its findings.

           #include <bios.h>

           #define COM1 0

           main()
           {
              union {
                  unsigned rtrn;
                  struct {
                      /* Modem status bits */
                      unsigned cts_change : 1;
                      unsigned dsr_change : 1;
                      unsigned ter_detector : 1;
                      unsigned rls_change : 1;
                      unsigned clear_send : 1;
                      unsigned dset_ready : 1;
                      unsigned ring_ind : 1;
                      unsigned rls_detect : 1;
                      /* Line status bits */
                      unsigned data_ready : 1;
                      unsigned overrun : 1;
                      unsigned parity : 1;
                      unsigned framing : 1;
                      unsigned break_det : 1;
                      unsigned hold_reg : 1;
                      unsigned shift_reg : 1;
                      unsigned time_out : 1;
                  } s;
              } status;
              unsigned outbyte = 0;

              status.rtrn = _bios_serialcom ( _COM_STATUS, COM1, outbyte);

              if (!status.s.data_ready)
                  printf("\n\tNo data ready at line . . . ");

              if (!status.s.dset_ready)
                  printf("\n\tNo data ready at modem . . . ");

              /* Other bits can be checked similarly */

              printf("\n\n\tContinue with other processing until COM1
           ready");
              printf("\n\n\tStatus return byte = %u", status.rtrn);

           }


See Also: int86() int86x() intdos() intdosx()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson