Coding to do the interfacing
We can easily program the parallel port in DOS. But as we know, DOS programs have their own limitations.
So, if you want to move from DOS to Windows, go through this article.
This is an introduction to program the parallel port in VC++. You need not have much knowledge about VC++.
This article is designed for one who know basics of parallel port and beginners of VC++.
If you don't know anything about parallel port, read my first article "Parallel port programming with C (Part 1)".
There you get basic information about parallel port and programming the port in Turbo C or Borland C.
Download Source Code + inpout32.dll files
We used inpout32.dll in us program for interoping.
You can download the inpout32.dll after get it to
path name is "Windows/System32 ".
Note: I am importing it with the reference of http://www.logix4u.net/ So for further info about the driver check out the site
Creatting Public Class PortAccess with Import DLL
In Form1.cs is main form that you will coding in view code window by used the following thus below.
If you have already to import inpout32.dll to your debug or release directory.
Private class PortAccess
Call OutPut function from DLL file.
public static extern void Output(int adress, int value);
Call Input functionfrom DLL file
public static extern void Input( int adress);
By the way, the main thing in us Form1.cs is PortAccess.Output.
It takes two variables which are address and value. If your data ports
are set in "0x378" (see Part 1) you will have to write "888" because "378"
Hexadecimal is equal to "888" in decimal. (Default LPT1 is set to "378") If you
are using LPT2 which is "0x278" you have to write for the address "632" For ex:
for full signaling to pins we have to call the Output method of
And for null data we have to send "0" to the Output
I wrote a func for reseting the LEDs which is:
private void Reset_LEDs()
I didn't use loops for checkboxes and pictureboxes you can also enumerate
these for quick coding. First, I do like that but after I changed to several
if-else statements because I had to change the GUI. But I left them on the code
for performance issues anyone who want speed can use these.
You can always use this program to test the parallel port. Now, make a circuit connecting all the input pins to switches, all the output pins to LEDs with 2.2K or 10K resisters. If you press switch, corresponding pin value should change in the screen, If you change state of any output pin, corresponding LED should glow.
Every thing is ok. But as you know, this program will run only in win9x. If your program is needed to run in windows xp and higher versions, you need to write a kernel mode device driver. Do not worry if you are not up to that level. There are DLL files available freely for such drivers. You can use those files and call them from your program.
Running the Project:
- Microsoft Visual Studio.NET Professional or greater.
- Windows 2000 or Windows XP.
- A modem installed on one of the Comm Ports. (for example most laptops include a modem).
To run the Project:
- Unzip the code into a directory of your choice.
- Open ParallelPortInterfacing.sln file.
- Click the buttons on the form to test the functionality.
- Examine the code in the project to understand how the code works.