Electronic – Parallel port output in C++ on Win7 x64

cledparallelportprogramming

First of all, I have searched the internet all day long, including here on stackexchange, and couldn't find a clear solution. Only ambiguous answers and dead links.

  • Let's start with what I have: my PC has a motherboard from 2007, with
    an onboard parallel port. I bought a parallel port connector and
    soldered a wire to pin 2 and 25 ( first data pin and ground). I've
    put an appropriate resistor and an LED.
  • I started with the idea of using Processing first. After a bit of searching I found the PortIO library. I installed it and tried the blinking example. No success. The program seems to work( I inserted a print("Blink!"); after every delay and it displays the message), but the LED doesn't light up. I have to mention that, when I restart the computer, the LED briefly lights up. So the port is working, but I can't control it.
  • Then I moved to the idea of using C++. As I searched I found out that newer versions of Windows severely limit program access to hardware. Well, I found out about inpout32.dll, and downloaded it from this page(Binaries only – x86 & x64 DLLs and libs).
  • It seems the driver successfully installed, but I can't find out how to use the files. I use Visual Studio 2012, but I'm not really accustomed to working with external libraries and dlls. Where do I have to put the inpout32.dll, inpout32.h and inpout32.lib files and how do I link them?

And the biggest question is this: How do I actually use inpout32.dll? I can't find any example! It's either for Basic or C#, or even more frustrating, dead links!
For starters, I'd Like to simply turn on and off the LED. Then I can figure out more complicated projects.

Best Answer

First off getting access to the parallel port in Win7, Vista and even WinXP is a major effort. Microsoft took away the ability for normal user code to be able to directly access the hardware registers. Instead they virtualized the accesses and if you try to do they they normally appear to have executed but they do not end up touching the hardware. To get access some special device driver solutions were devised, InpOut32.DLL is one example, that let user code indirectly access the port because the driver runs in system mode. I have previously used InpOut32 for some experiments and found that it adds quite a bit of latency to the accesses such that even on rather high speed machines the fastest available toggle rate of parallel port pins was on the order of less than 22KHz. When I used it I was coding in an unmanaged coding environment.

When you start writing code in something like VS2012 using managed code under Microsoft's .NET framework you have to jump through a lot of hoops to get add-on drivers such as InpOut32 to work (and it is not even certain that that particular driver is even workable in Win7's 64-bit environment). I have not attempted it in my current 64-bit environment because it is just not worth the effort to try to eek it into functionality because there is an additional loss of performance when calling an unmanaged driver from managed user code. One's time is much more well spent using one of the multitude of USB choices available to get access to external I/O via a USB bridge I/O device.

[EDIT: Added USB Port Output Idea]

One really easy little board that you can build into project and connect to a PC with a Mini-B USB cable is the USB Bit Whacker from Sparkfun Electronics. This little board shows up on the PC as a virtual Comm port and is able to accept very simple text commands that will toggle the outputs on and off or monitor the inputs.

enter image description here