Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Parallel Port Control with C# .NET 2.0

5.00/5 (11 votes)
17 Aug 2012CPOL2 min read 84K   14.4K  
Parallel port data register control with C# .NET 2.0 and inpout32.dll.

Sha-1 : 0976B8161468507304BC1B0F1FFF79263C71E10E

Image 1

Introduction

This is very simple application for data register out control with C#. When I interested control external electronical device I was looking such as application but I couldn't find any working properly and I wrote it. This article is about controlling data registers of parallel port (LPT port) with C#.net 2.0 and using inpout32.dll/inpout32.lib out32 function.

You can use this simple application for testing external electronic projects, tesing your parallel port's data registers, understand how they works.

1.How Inpout32.dll Works ?

Source code inpout32.dll http://code.google.com/p/stimqt/downloads/detail?name=inpout32.dll

The outstanding feature of Inpout32.dll is , it can work with all the windows versions without any modification in user code or the DLL itself. The Dll will check the operating system version when functions are called, and if the operating system is Win9X, the DLL will use _inp() and _outp functions for reading/writing the parallel port. On the other hand, if the operating system is WinNT, 2000 or XP, it will install a kernel mode driver and talk to parallel port through that driver. The user code will not be aware of the OS version on which it is running. This DLL can be used in WinNT clone operating systems as if it is Win9X. The flow chart of the program is given below.

Look for 64 bit support Inpoutx64.dll.

Image 2

Flowchart of inpout32.dll functions.

In this project used Out32 function from library.

C#
namespace ParallelPortControl
{
    class PortControl // Import dll to project
    {
        [DllImport("inpout32.dll", EntryPoint = "Out32")]
        public static extern void Output(int address, int value); // decimal
    }

    public partial class Form1 : Form 
    {
        int decData = 0;
        int decAdd = 888; // 378h Selected Default

        PortControl.Output(decAdd, decData);
    }
}

2.How to Learn Parallel Port Address on Windows ?

You can find you parallel port's address easly on Windows Operating Systems. Right click computer on Desktop, Manage > Device manager > Ports > LPT1 or LPT2.

Image 3

IEEE 1284 standard port addresses

Data Register

Status Register

Control Register

Range1

3BCh

3BDh

3BEh

Range2

378h

379h

37Ah

Range3

278h

279h

27Ah

3.Using Decimal Input

128 64 32 16 8 4 2 1
D7 D6 D5 D4 D3 D2 D1 D0

Image 4

If you want send 10010100 (1 is logic high voltage, 0 is logic low voltage) just add the decimal value which one is high(1) 128 + 16 + 4 = 148.

4.References

  1. logix4u.net
  2. Microsoft Developer Network

6.Contact

http://blog.armanasci.com.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)