• About
  • Articles
  • Projects
AboutArticlesProjects

© 2026 John Aldrin Plata. All rights reserved.

Drive a Parallel Port using C#

August 8, 2021

Parallel Port

Before USB and HDMI ports were a thing, the world was dominated by long and unusual shaped ports like Serial and Parallel ports. Serial ports, as the name suggests, provide a serial communication using one line while on the other hand Parallel ports uses parallel connection which means it sends a large data over multiple connection.

Because of this design, Parallel ports are able to transfer at a much faster rate than that of Serial port and the main reason why it's mostly used for printers, hard drives and cd-drives.

Parallel Port source: https://commons.wikimedia.org/wiki/File:Parallel_port_pinouts.svg

Another major differences from the two is the number of pins.

In this project, we will be focusing on how to read and write data to and from a Parallel Port using C#.

The inpout32.dll

Windows provides various DLL for every specific part of the OS, one of which is the inpout32.dll. This library allows us to easily control the ports in the system. It exposes two methods that we will use: Output which takes the parallel port's address and a value to send; Read where we can fetch the value currently written out in a specific address.

[DllImport("inpout32.dll", EntryPoint = "Out32")]
public static extern void Output(int address, int value);
 
[DllImport("inpout32.dll", EntryPoint = "Inp32")]
public static extern char Read(int address);

Parallel Port Address

Computers has a range of various ports each assigned an address. We need to identify which address our parallel port uses in order to drive it. To determine which address the parallel port is assigned to, follow the guide below:

  1. From the Start menu, choose Settings -> Control Panel
  2. Click the Multimedia icon, and then click the Devices tab
  3. Select Sentinel for i386 Systems from the Other Multimedia Devices pull-down menu.
  4. Click Properties and then click Settings to open the Settings dialog box. The parallel port address is shown as the Physical Address in the Settings dialog box.

My address is in hex!

Both methods that the inpout32.dll exposes requires the address to be in decimal.

Don't worry, use the following calculator to convert from hexadecimal to decimal and take note of the result.

Reading and Writing to Parallel port

// Read port data
int data = Read(address);
 
// Write to port
Output(address, data);

Heres the final code

class ParallelPort
{
    [DllImport("inpout32.dll", EntryPoint = "Out32")]
    public static extern void Output(int adress, int value);
 
    [DllImport("inpout32.dll", EntryPoint = "Inp32")]
    public static extern char Read(int address);
 
    private int Address;
 
    public ParallelPort(int address)
    {
        this.Address = address;
    }
 
    public int Get()
    {
        return Read(this.Address);
    }
 
    public void Write(int data)
    {
        Output(this.Address, data);
    }
}

Usage

class Program
{
    static void Main(string[] args)
    {
        var port = new ParallelPort(4240);
        port.Write(255);
        int data = port.Get();
    }
}

You may also find the project here on GitHub. And if you're interested, I made a desktop application that allows you to visually control the individual pins and can send Morse code.