LOGIX4U.NET

...

  • Increase font size
  • Default font size
  • Decrease font size

How to read Parallel/Serial Port address from BIOS

E-mail Print PDF

To write an interfacing program with parallel port or serial port, we need to know the base address of the corresponding port in advance. Normally the base address of LPT1 will be 0x378 and that of LPT2 will be 0x3F8. And most of the home PCs will have only one parallel port with base address 0x378.

To write an interfacing program with parallel port or serial port, we need to know the base address of the corresponding port in advance. Normally the base address of LPT1 will be 0x378 and that of LPT2 will be 0x3F8. And most of the home PCs will have only one parallel port with base address 0x378. If only one port is present on the system we can probably assume that the base address is 0x378. And this can be confirmed by checking the Parallel Port properties in Device Manager. To do this, right click on My Computer, select Manage. Select Device Manager from the Computer Management console. Choose Parallel Port from the device tree, right click on it and select "Properties". Go to the "Resources" tab. Here you can find the Base address of the parallel port. A sample parallel port properties window is shown below. The Base address is highlighted in red circle.

Even though it is possible to get the parallel port base address from the properties dialogue, it will be much convenient, if we can retrieve the address of the available parallel ports programatically. DOS allowed applications to read information directly from BIOS. And that was the most popularly used method to identify parallel/Serial port address in DOS applications. But windows do not allow user mode applications to read BIOS directly. For a Windows application, this can be done with the help of a device driver only. The device driver can map the address in to the user mode process's address space and read the contents safely.


Logix4u introduces a library (hwinterface32) to access Physical memory directly from user mode application. Obviously, a device driver is involved in the process, but it is hidden from the user. Just like the Inpout32.dll , the device driver is embedded in the DLL and will be installed and configured automatically at the very first call made to the library (DLL). As a programmer, all that you need to do is, copy the DLL to relevant directory (system directory or application directory) and Call the exported functions. No driver installation, no hassles. Current Beta version of this library supports all the functions available in Inpout32.dll (Inp32() and Out32()), The library also contains functions Inpw32()/OutW32 which reads/writes 16 bit word and InpD32()/OutD32 which reads/writes 32 but DWords. Apart from I/O functions this library contains memory access functions also. Please refer the table below to see all functions supported by this library.

Function Description
short Inp32(short PortAddress) Reads a single Byte from the specified I/O address.
void Out32(short PortAddress, short data)
Writes a single Byte to the specified I/O address.
short InpW32(short PortAddress) Reads a Word from the specified I/O address.
void OutW32(short PortAddress, short data) Writes a Word to the specified I/O address.
long InpD32(short PortAddress) Reads a DWord from the specified I/O address.
void OutD32(short PortAddress, long data) Writes a DWord to the specified I/O address.
long ReadMemChar(ULONG Address) Reads a single Byte from the specified memory address.
long ReadMemShort(ULONG Address) Reads a 16 bit word from the specified memory address.
long ReadMemLong(ULONG Address) Reads a 32 bit Dword from the specified memory address.
void WriteMemChar(ULONG Address, UCHAR data ) Writes a single Byte to the specified memory address.
void WriteMemShort(ULONG Address, USHORT data) Writes a single Word to the specified memory address.
void WriteMemLong(ULONG Address, ULONG data) Writes a single DWord to the specified memory address.



Reading Parallel/Serial Port Address from BIOS

Typically, The addresses of Parallel and Serial ports present on a PC is stored in BIOS. An application can read this data to determine the presence of ports and there base addresses. The addresses of serial ports can be found starting from address 400H in BIOS. And the addresses of parallel port can be found starting from the address 408H in BIOS. The table below lists the BIOS address at which base address of each serial/parallel port can be found.

Address Port
400H Base I/O address for serial port 1 (COM 1)
402H Base I/O address for serial port 2 (COM 2)
404H Base I/O address for serial port 3 (COM 3)
406H Base I/O address for serial port 4 (COM 4)
408H Base I/O address for parallel port 1 (LPT 1)
40AH Base I/O address for parallel port 2 (LPT 2)
40CH Base I/O address for parallel port 3 (LPT 3)



It is easy to get the base address of Parallel/Serial port by reading the above addresses listed. The picture below shows the screen shot of a VB sample application which prints the base addresses of Parallel ports and serial ports with the help of hwinterface32 library.



Download Hwinterface32 library with sample program