4.2 Character Devices

A character device is any device that processes data one byte (one character) at a time. The computer's keyboard, screen, real-time clock, and serial and parallel ports are character devices.

Each character device has a name. MS-DOS uses the following names:

Name Description

AUX Auxiliary device, usually a serial communications port.
CLOCK$ Real-time clock.
COM1 First serial communications port. AUX is usually an alias for COM1.
COM2 Second serial communications port.
CON Keyboard and screen.
LPT1 First parallel printer port. PRN is usually an alias for LPT1.
LPT2 Second parallel printer port.
LPT3 Third parallel printer port.
NUL “Bit bucket” device that discards all output and provides no input.
PRN Printer device (also called a list device), usually a parallel communications port.

Programs open character devices by supplying the device names to Open File with Handle (Interrupt 21h Function 3Dh). The functions use the device names much as they use filenames, opening the device and returning a file handle. Once a program has a handle, it can read from, write to, and close the device by using such file-handle functions as Read File or Device (Interrupt 21h Function 3Fh), Write File or Device (Interrupt 21h Function 40h), and Close File with Handle (Interrupt 21h Function 3Eh).

Note:

A program cannot create a file with the same filename as a device (such as CON.TXT), regardless of the extension. Attempting to open or create a file with the same name as a device opens the device instead.