Click here to Skip to main content
6,305,776 members and growing! (18,287 online)
Email Password   helpLost your password?
General Reading » Hardware & System » Hardware     Intermediate License: The Code Project Open License (CPOL)

Parallel Port Pin Control Library (PaPiC)

By gordius

Controlling the twelve output pins and the five input pins of the LPT port.
VC6Win2K, WinXP, Win2003, Dev
Posted:29 Jun 2007
Updated:16 Nov 2007
Views:40,889
Bookmarked:50 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
11 votes for this article.
Popularity: 4.19 Rating: 4.02 out of 5
1 vote, 9.1%
1
2 votes, 18.2%
2

3
3 votes, 27.3%
4
5 votes, 45.5%
5

Screenshot - papic1.gif

Introduction

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 CPaPiC useful.

Background

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

Important!

If you are using WinXP, do the following steps:

  1. Execute regedit.exe:
  2. Find the following registry key:
  3. [HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\CurrentControlSet\\\\Services\\\\Parport]
  4. Insert a new key named "Parameters" (if it does not exist).
  5. Insert a new double word named "DisableWarmPoll" into "Parameters" with value "1".
  6. Restart Windows.

After this. WinXP will not disturb the output if you are switching the status pins.

Before using CPaPiC:

  1. Copy the DLL file inpout32.dll and the lib file inpout32.lib to the project folder.
  2. 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:

  1. create a static or dynamic object, or
  2. derive your class from CPaPiC.

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:

CPaPiC papi;

The constructor sets the default port LPT1, and selects all the input and output port pins that are active:

Parallel port pins

Physically:

Parallel port

Two additional definitions that refer to all I/O pins are LP_INPUT_PINS and LP_OUTPUT_PINS. The LPT port can be changed by the lpt_init_user() function. For example:

papi.lp_init_user(LPT2); // papi will control port LPT2

Furthermore, you may give different memory addresses. (But only LPT1 and 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 );
// Set input pins 10, 11 and 12 active

papi.pin_output_mode( LP_PIN01 | LP_PIN02 );
// Set output pins 1 and 2 active

// Equivalent code:

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:

Pin control functions

For example:

papi.clear_pin(LP_OUTPUT_PINS);
// Set all pins low (if not all have
// been selected, set only selected)

papi.set_pin( LP_PIN01 ); // Set pin 1 high

papi.invert_pin( LP_PIN01 | LP_PIN02 ); // Invert pins 1 and 2


// Loading the values of input pin registers:

lp_pin pins; // Creat a new lp_pin varible

pins = papi.pin_is_set( LP_PIN10 | LP_PIN11 | LP_PIN12 );
// ask the state of the registers of pins 10, 11 and 12

for( int i = 10; i < 13; i++)
    if( pins & LP_PIN[i] == 0 )
        printf( "pin %d is low\n", i );
        // the pin number i is low

    else
        printf( "pin %d is high\n", i ); // the pin number i is high

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):

Giving parameters

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 CPaPiC object.

Points of interest

While writing the code, I learned how important the bit operations are.

License

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

About the Author

gordius


Member
I study information technology at University of Pannonia in Hungary. In my free time I'm developing computer controlled telescope driving system and CNC.
Occupation: Web Developer
Location: Hungary Hungary

Other popular Hardware & System articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
GeneralInput Using Data Pin Pinmemberyuzizali18:16 29 Apr '09  
GeneralRe: Input Using Data Pin Pinmembergordius11:09 2 May '09  
Questionim unable to find the proj menu Pinmemberaisshu20:21 25 Mar '09  
AnswerRe: im unable to find the proj menu Pinmembergordius10:02 27 Mar '09  
GeneralPrecise timing using parallel port. PinmemberRoccivic4:58 3 Oct '08  
Questionsending data through parallel port Pinmembersuncrest7:14 10 Sep '08  
AnswerRe: sending data through parallel port Pinmembergordius11:02 10 Sep '08  
QuestionRe: sending data through parallel port Pinmembersuncrest19:44 10 Sep '08  
AnswerRe: sending data through parallel port Pinmembergordius9:32 11 Sep '08  
GeneralFIle missing in source PinmemberMember 456899915:40 7 Sep '08  
GeneralRe: FIle missing in source Pinmembergordius11:53 9 Sep '08  
QuestionI need to "catch" the output for a printer in another computer Pinmemberluixilva12:47 9 Oct '07  
AnswerRe: I need to "catch" the output for a printer in another computer Pinmembergordius4:40 10 Oct '07  
GeneralRe: I need to "catch" the output for a printer in another computer Pinmemberluixilva12:15 10 Oct '07  
GeneralRe: I need to "catch" the output for a printer in another computer Pinmembergordius3:25 11 Oct '07  
GeneralSome trouble Pinmembergordius4:08 24 Sep '07  
AnswerProblem solved Pinmembergordius4:30 30 Sep '07  
Generalhi i am unable to write any value on control pins where is the problem Pinmemberrajbhansingh4:10 11 Jul '07  
GeneralRe: hi i am unable to write any value on control pins where is the problem Pinmembergordius1:07 12 Jul '07  
GeneralRe: hi i am unable to write any value on control pins where is the problem Pinmembergordius9:52 12 Jul '07  
GeneralA little misleading .. PinmemberGarth J Lancaster15:42 29 Jun '07  
GeneralRe: A little misleading .. Pinmembergordius11:08 1 Jul '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 Nov 2007
Editor: Smitha Vijayan
Copyright 2007 by gordius
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project