Programming a parallel port as digital I/O

cparallelport

I'm trying to use a parallel port from a computer as a form of cheap digital output to do various things (control motors, light LEDs, read limit switches, ect).

I want to know how to control the 8 data pins on a parallel port using C++, however there's a catch. Since I'm using a modern computer with a modern OS, this presents a few problems.

First of all, modern windows OS's don't allow direct access to parallel port pins, I must go through a driver. I have been pointed to using Inpout32 to do this, however the sample program compiled and ran properly but my attached hardware didn't respond. Another person has pointed me to using Windows API. I have searched the MSDN and found only mentions of the appropriate function but without some sample code, I'm lost (maybe I'm searching in the wrong places).

The second problem is that my new computer doesn't have any parallel ports. I must use USB to parallel ports instead (cheap and direct from China, $5 each, shipping and taxes all included). The ports are recognized by the computer as IEEE-1284 controllers and the appropriate drivers were automatically installed and the computer reports the device as "working properly". From what i have seen online, there seems to be a wide variety of opinions on the usefulness of these USB to parallel port connectors. One person says it works perfectly fine like any regular parallel port soldered to the motherboard, another says it will work with some hardware hacks, one says it can write but not read, and finally another says it won't work at all because they are not designed to work the same way as "real" parallel ports.

I have already done a great deal of research before coming here (sort of as a last resort I guess, StackOverflow didn't yield any answers even after applying a bounty). Pretty much all the information I found on programming parallel ports is outdated and assumes that you have either a parallel port on your motherboard, a pre-Windows-NT OS, or both.

If anyone has any idea how to do this, would you please share it with me?

Thanks,

-Faken

Note: I'm running Windows 7 x64 OS on a Core i7 860. I'm programming in C++ on Visual Studio 2008 pro. The USB to parallel port connectors are connected via USB 2.0 ports.

Best Answer

Parallel port is dead, and USB microcontrollers are really the future IMO. If you use the HID or CDC profile you don't even need any driver on your PC. Eg the Teensy for $18, you get 25 I/O, of which all can be used as digital I/O, or up to 12 of them as analog inputs and 7 of them PWM channels. The Teensy is more general purpose, if you want something specifically to provide communication between your PC and electronics, there are other devices targeted more towards that, like the Bus Pirate. Or, if you don't need too many I/O's, you could use the standard, fairly simple FT232R USB chip in 'bit-bang' mode, and get 8 digitial I/O out of it.

If you absolutely refuse to listen to reason, then what you need is a PCI card which adds a parallel port, like this one. You'll need a PCI slot (not PCI-Express), most motherboards still have one these days, but they are starting to get phased out.

USB to Parallel adaptors will have all sorts of problems. The main one is latency...standard parallel port latency is measured in microseconds, whereas USB latency is measured in milliseconds. The other is that many USB to Parallel adaptors are designed only for printers, and lack the extra circuitry needed to individually control the address lines in the way you want.