_bios_serialcom
Performs serial I/O.
Defined in header <bios.h>
Syntax
#include <bios.h>
unsigned _bios_serialcom(int cmd, int port, char ahyte);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ |
Remarks
_bios_serialcom performs various RS-232 communications over the I/O port given in port.
A port value of 0 corresponds to COMl, 1 corresponds to COM2, and so forth.
The value of cmd can be one of the following values (defined in bios.h):
| COM INIT | Sets the communications parameters to the value in abyte. |
| COM SEND | Sends the character in abyte out over the communications line. |
| COM RECEIVE | Receives a character from the communications line. The abyte argument is ignored. |
| _ | COM _ | STATUS | Returns the current status of the communications port. The abyte argument is ignored. |
When cmd is _COM_INIT, abyte is a OR combination of the following bits:
Select only one of these:
| _COM_CHR7 | 7 data bits |
| _COM_CHR8 | 8 data bits |
Select only one of these:
| _COM_STOPl | 1 stop bit |
| _COM_STOP2 | 2 stop bits |
Select only one of these:
| _COM_NOPARITY | No parity |
| _COM_ODDPARITY | Odd parity |
| _COM_EVENPARITY | Even parity |
Select only one of these:
| COM 110 | 110 baud |
| COM_150 | 150 baud |
| COM.300 | 300 baud |
| COM600 | 600 baud |
| COM1200 | 1200 baud |
| COM_2400 | 2400 baud |
| COM_4800 | 4800 baud |
| COM9600 | 9600 baud |
| For example, a value of (_COM_9600 | I _COM_ODDPARITY | I |
| _COM_STOPl | I _COM_CHR8 | ) for abijte sets the communications port to |
9600 baud, odd parity, 1 stop bit, and 8 data bits. _bios_serialcom uses the BIOS 0x14 interrupt.
Return value
For all values of cmd, _bios_serialcom returns a 16-bit integer of which the upper 8 bits are status bits and the lower 8 bits vary, depending on the value of cmd. The upper bits of the return value are defined as follows:
Bit 15 Time out Bit 14 Transmit shift register empty Bit 13 Transmit holding register empty Bit 12 Break detect Bit 11 Framing error Bit 10 Parity error Bit 9 Overrun error Bit 8 Data ready
If the abyte value could not be sent, bit 15 is set to 1. Otherwise, the remaining upper and lower bits are appropriately set. For example, if a framing error has occurred, bit 11 is set to 1.
| With a cmd value of _COM_RECElVE, | the byte read is in the lower bits of |
the return value if there is no error. If an error occurs, at least one of the upper bits is set to 1. If no upper bits are set to 1, the byte was received without error.
| With a cmd value of _COM_INIT | or _COM_ST | ATUS, the return value has |
the upper bits set as defined, and the lower bits are defined as follows:
Bit 7 Received line signal detect Bit 6 Ring indicator Bit 5 Data set ready Bit 4 Clear to send Bit 3 Change in receive line signal detector Bit 2 Trailing edge ring detector Bit 1 Change in data set ready Bit 0 Change in clear to send
Example
#include <bios.h>
#include <conio.h>
#define COMl 0
Mefine DATA_READY 0x100
#define TRUE 1
#define FALSE 0
tdefine SETTINGS (_COM_1200 I _C0M_CHR7 I _C0M_ST0P1 I _COM_NOPARITY)
int main (void)
{
unsigned in, out, status;
_bios_serialcom(_COM_INIT, COMl, SETTINGS);
cprintfC... _BIOS_SERIALCOM [ESC] to exit ...\r\n");
for (;;) {
status = _bios_serialcom(_COM_STATUS, COMl, 0);
if (status & DATA_READY)
if ((out = _bios_serialcoin(_COM_RECEIVE, COMl, 0) & 0x7F) !=
putch(out) ;
if (kbhitO) {
if ((in = getchO) == '\xlB')
break;
_bios_serialcom(_COM_SEND, COMl, in);
return
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `bios serialcom` read as `_bios_serialcom`
Stable link: /3.1/bios.h/_bios_serialcom/
· short form /3.1/_bios_serialcom/