This is a wrapper for the inpout32.dll/inpout32.lib class which is available at Logix4u.net. For a little theory, please visit Logix4u.net.
This class is useful if you wish to control the 12 output pins of your computer's parallel port under Windows XP/NT (e.g., driving LEDs, motors and all). This means, the control pins are used as output. The LPT port has 8 data pins, 4 control pins, and 5 status pins (input), but unfortunately, the basic functions (Console and Port I/O Routines) do not support direct access to the control pins. For this reason, I have developed this project: to have more freedom and functionality using the LPT port.
Almost all functions have the same interface as PARAPIN functions, so this class is useful too if you are adapting your linux code included PARAPIN to Windows enviroment. Hopefully you will find
This C++ class was inspired by PARAPIN, A Parallel Port Pin Programming Library for Linux, which was developed by Jeremy Elson and Al Hooton.
The realization of this work can never been done without the inpout32.dll/inpout32.lib from Logix4u.net.
Using the code
If you are using WinXP, do the following steps:
- Execute regedit.exe:
- Find the following registry key:
- Insert a new key named "Parameters" (if it does not exist).
- Insert a new double word named "
DisableWarmPoll" into "
Parameters" with value "1".
- Restart Windows.
After this. WinXP will not disturb the output if you are switching the status pins.
- Copy the DLL file inpout32.dll and the lib file inpout32.lib to the project folder.
- From the Project menu, select Settings, go to the tab Link, in Object/ Library Modules, write inpout32.lib.
You may use
CPaPiC in different ways. For example, you can:
- create a static or dynamic object, or
- derive your class from
At first, I will show you how to create a static object and use its member functions and definitions. In this case, it is possible to use more then one object and control only the selected pins without the danger of disturbing the others. Let me declare a
CPaPiC object like this:
The constructor sets the default port LPT1, and selects all the input and output port pins that are active:
Two additional definitions that refer to all I/O pins are
LP_OUTPUT_PINS. The LPT port can be changed by the
lpt_init_user() function. For example:
Furthermore, you may give different memory addresses. (But only
LPT2 are defined.) If you want to select the pins to control, you can do it this way:
papi.pin_input_mode( LP_PIN10 | LP_PIN11 | LP_PIN12 );
papi.pin_output_mode( LP_PIN01 | LP_PIN02 );
papi.pin_mode( LP_PIN10 | LP_PIN11 | LP_PIN12, LP_INPUT );
papi.pin_mode( LP_PIN01 | LP_PIN02, LP_OUTPUT );
Now, only the 10, 11, 12 input pins and the 1, 2 output pins will be available for the
papi object. The port address and active pins are revisable any time. Controlling the selected pins is very simple. Just have a look at these (PARAPIN-like) functions:
papi.set_pin( LP_PIN01 );
papi.invert_pin( LP_PIN01 | LP_PIN02 );
pins = papi.pin_is_set( LP_PIN10 | LP_PIN11 | LP_PIN12 );
for( int i = 10; i < 13; i++)
if( pins & LP_PIN[i] == 0 )
printf( "pin %d is low\n", i );
printf( "pin %d is high\n", i );
In the demo program, you can specify the pin parameters of a function using check boxes (parameter of
pin_is_set(..) contains all input pins):
I have derived the
CPaPiCDlg class from
CPaPiC, so my dialog has all the properties of
CPaPiC. So, I can use all its functions instead of creating a separate
Points of interest
While writing the code, I learned how important the bit operations are.
I graduated at University of Veszprem, Hungary and I'm working at Continental Teves as a software developer for brake systems. I like sports (swimming, hiking, jogging) and reading scientific books.