Click here to Skip to main content
Click here to Skip to main content

Reading from Parallel Port using Inpout32.dll

, 8 Aug 2006
Rate this:
Please Sign up or sign in to vote.
Using the Signal Port to read in data instead of Data Port

Introduction

This is a good tutorial about interfacing with the parallel port; more inportantly reading from the port. Other articles I've seen only shown how to write to the port.

Before I get ahead of myself, the parallel port I used is an ECP (Extended Capability Port).  Find out if your port is the same as mine, yours could be an EPP or SPP. 

 

Go to “Control Panel / System /  Hardware Tab / Device Manager / Ports (Com & LPT) / Printer Port (LPT1 or LPT2) /”

 

It should indicate what type you have.  You can also go to the ‘Resource’ Tab to indicate the range of your port: mine is I/O Range 0378 – 037F, ignore the other I/O range.

 

For the ECP, there are some over headers if I was to use the data port as both input and output.  Instead, I used the signal port for data processing.

 

If by any odd reason you don't understand the tutorial.  Please refer to the explaination towards the bottom of the page.  Or just email me. 
 
Note that all information regarding the inpout.dll is on http://www.logix4u.net/  
 
>>Please Vote so I can get an indication weither it's worth my time to update.<<

 

 

Testing

 

As mention before, I used a DMM to test out the ports (nothing connected to the ports yet) and I used the read function from the inpout32.dll, .ie In(Port Address), my particular port address was:

 

Sample screenshot 

 

[Data Port]         Addres:  0x378H or in VB Express &H378S

[Status Port]      Addres:  0x379H or in VB Express &H379S

[Control Port]    Addres:  0x37AH or in VB Express &H37AS

 

   *note these port address are in HEX 


Data Pins          Status Pins            Control Pins

Pin 9: D7            Pin 10: S6               Pin 1  : C0

Pin 8: D6            Pin 11: S7               Pin 14: C1   

Pin 7: D5            Pin 12: S5               Pin 16: C2   

Pin 6: D4            Pin 13: S4               Pin 17: C3   

Pin 5: D3            Pin 15: S3                  

Pin 4: D2                                

Pin 3: D1                                

Pin 2: D0                                

 


Tutorial #1

 

Note that this was done in VB 2005 Express Edition.

The 1st Tutorial: Writing to the 'data' port and reading what we wrote on it.

The 2nd Tutorial: Reading from the 'status' port externally.  

 

Step 1: Basically; once you download the inpout32.dll file. Copy it to your system directory.  .ie C:\WINDOWS\system32
 
Step 2: Then in VB; Open a New File
 
Sample screenshot 

 

 

Step 3: In the text box, write a name for this project.  I called my 'Port_Testing'
 
Sample screenshot 
 
 
Step 4: "Drag" a button to your form window and then "Double Click" on the button.
 
Sample screenshot

 

 

Step 5: Once your in the code editor declare this at follows at the beginning of your code:
<FONT color=#0000ff size=2><P>Option</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Strict</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Off</P><P>Option</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Explicit</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>On</P><P>Module</FONT><FONT size=2> InpOut32_Declarations</P><P></FONT><FONT color=#008000 size=2>'Inp and Out declarations for port I/O using inpout32.dll.</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Declare</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Function</FONT><FONT size=2> Inp </FONT><FONT color=#0000ff size=2>Lib</FONT><FONT size=2> </FONT><FONT color=#800000 size=2>"inpout32.dll"</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Alias</FONT><FONT size=2> </FONT><FONT color=#800000 size=2>"Inp32"</FONT><FONT size=2> (</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> PortAddress </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Short</FONT><FONT size=2>) </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Short</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Declare</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> Out </FONT><FONT color=#0000ff size=2>Lib</FONT><FONT size=2> </FONT><FONT color=#800000 size=2>"inpout32.dll"</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Alias</FONT><FONT size=2> </FONT><FONT color=#800000 size=2>"Out32"</FONT><FONT size=2> (</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> PortAddress </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Short</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> Value </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Short</FONT><FONT size=2>)</P></FONT><FONT color=#0000ff size=2><P>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Module</P></FONT></FONT></FONT>

Sample screenshot

 
Step 5: Scroll down to the 'event handler,' of Button1. 

 

<FONT color=#0000ff size=2><P>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Class</FONT><FONT size=2> Form1</P><P></FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> Button1_Click(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> System.Object, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> System.EventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> Button1.Click</P><P></P><P></FONT><FONT color=#0000ff size=2></FONT> </P><P><FONT color=#0000ff size=2>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</P><P>End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Class</FONT></P>
Step 6: Now within the event handler code, write the next following 3 lines of code: 
<FONT size=2><P>Out(&H378S, &HFFS)           </FONT><FONT color=#008000 size=2>'Print '1' to D7-D0 or 255 in Decimal</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> Value1 </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2>           </FONT><FONT color=#008000 size=2>'String named Value1</P></FONT><FONT size=2><P>Value1 = Inp(&H378S)         </FONT><FONT color=#008000 size=2>'Now Value1 has the values in 'data port'</P></FONT><FONT size=2><P>MessageBox.Show(Value1)   </FONT><FONT color=#008000 size=2>'A popup will indicate the current value written</P></FONT>

Sample screenshot 

Step 7: Run It!!! Using 'F5 Key' or going to 'Debug/Start Debugging.'

 

Sample screenshot

 

Here is the result of our hard earn work! 255 should appear on the messagebox.  If not, you screwed up.  Go back and repeat.  To see different results you can also modify the code by writing in any other number in hex within the 'Out(&H378S, [HEX CODE: Only from &H0S to &HFFS ]).' *Note that the range is 0 (zero)  to FF hex & not O.

 

Sample screenshot

 

 

 

Tutorial #2

 

 

Step 1: If you haven't gone through Tutorial #1 and your a novice.  I suggest that you should scroll up.
 
Step 2: Go to the 'Design Tab' and drag another button to the form window.
 

Sample screenshot 

Step 3: Next, double click on it and then add the following code in the 'eventhandler' for Button2.

 

<FONT size=2><P></FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> Value2 </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2>          </FONT><FONT color=#008000 size=2>'String named Value2</P></FONT><FONT size=2><P>Value2 = Inp(&H379S)        </FONT><FONT color=#008000 size=2>'Now Value2 has the values in 'signal port'</P></FONT><FONT size=2><P>MessageBox.Show(Value2)  </FONT><FONT color=#008000 size=2>'A popup will indicate the current value written</P></FONT>

 

Sample screenshot

 

Step 4: Run It!!! Press F5 or go to Debug/Start Debugging.

 

Step 5: Click on Button2 and watch for the popup window.  It should read 120 Decimal.

 

Sample screenshot

 


 

Explaination

 

What are Hex, Bin, Dec?

They are representations of numbers at differnt bases.

 

Hex = Hexidecimal Numbers (Base 16)

Bin = Binary Numbers (Base 2)

Dec = Decimal Numbers (Base 10)

 

We are most familar with base 10 since we count in decimal however computers are only familary with base 2; .ie 1's and 0's or 'on' and 'off.'  I'm not going to elaborate more than this.  To change between bases, simply use Microsoft Calculator that is already built in.  Just remember to change it from the 'Standard View' to the 'Scientific View.'  Write in the numbers and then simply click on what base you would like to see the number represent in.

Using the Status Port?

 

In Tutorial #1; we saw the MessageBox popup window showing a value of 255.  You might ask yourself, why is that.  First of all, DUH! We wrote 255 Decimal or FF Hex to it and ofcourse we can write anything else (0 - FF).

 

In Tutorial #2; we saw the MessageBox popup window showing a value of 120.  Again you might as yourself, why is that.  The answer is not as obvious.  You might think the value should be '0' since we wrote nothing to it & we didn't connect anything to our parallel port yet.  The answer is that Bit 7 (S7) of the signal port is inverted! (Ahhhhh) and S7 - S3 are always high enable.  (Yes!)

 

S7' = 1' = 0

S6 = 1

S5 = 1              

S4 = 1

S3 = 1

S2 = 0

S1 = 0

S0 = 0 

01111000bin = 120dec 

So you might ask yourself, how do we use the status port!!!

 

Just tie any of your status pins (any red pin) to ground (any green pins) and you should see a value change when you run my program again.

Sample screenshot

You see, on the status line; the pins are 'high' .ie 5V.  To enble them for reading purpose you'll have to ground your status pins. (OOOOOHHH!!!)

 

Examples:

 

Example 1: Nothing Connected to Status Pins

Sample screenshot

 

The result should be: 120

S7

S6

S5

S4

S3

S2

S1

S0

0

1

1

1

1

0

0

0

 

Example 2: Status Port (S7), pin 11 is grounded

Sample screenshot

 

The result should be: 248

S7

S6

S5

S4

S3

S2

S1

S0

1

1

1

1

1

0

0

0

Example 3: Status Port (S5), pin 12, is grounded

Sample screenshot

 

 

The result should be: 88

S7

S6

S5

S4

S3

S2

S1

S0

0

1

0

1

1

0

0

0

 

 

 

Comments & Sourcecode

 

There you go!  I know this was very long, but I hoped it helps.  If you need the code, I’ll be happy to share.  It’s in VB Express although. 

 

Download sourcecode

 

Email me at phebejtsov@yahoo.com for questions.

 

 

Regards

 

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

phebejtsov

United States United States
No Biography provided

Comments and Discussions

 
QuestionThe program shows an Error PinmemberMember 107215583-Apr-14 20:47 
QuestionCoding Problem PinmemberMember 107215583-Apr-14 3:16 
QuestionStatus Pin Problem PinmemberAYYANZ1113-Jan-13 23:25 
Questionexception in input and output commands Pinmembermomina sheikh1-Oct-12 8:22 
GeneralWorking or not depending on PC Pinmemberlukeer12-Jul-12 20:16 
GeneralRe: Working or not depending on PC Pinmemberlukeer16-Jul-12 21:53 
Questionreading from p PinmemberJembatan24-Jan-12 2:11 
Dear everybody,
 
I have made in vb6 a program using the inpout.dll for controling my modeltrain via the parallel port.
Now I have the situation that the parallelport is missing on my laptop.
Before I buy a usb to parallel convertor cable I like to know if the software is still working or in case not what to do to make it working again ?
 
thanks for your attention
 
Rob
GeneralMy vote of 5 Pinmemberbiondi_roma9-Nov-11 19:33 
QuestionProblem with result Pinmemberkamrul102-Oct-11 3:14 
AnswerRe: Problem with result Pinmemberlukeer12-Jul-12 20:04 
GeneralRe: Problem with result Pinmembermustafa98212-Jun-13 13:01 
GeneralRe: Problem with result Pinmemberlukeer12-Jun-13 23:02 
GeneralRe: Problem with result Pinmembermustafa98213-Jun-13 1:29 
GeneralRe: Problem with result Pinmemberlukeer13-Jun-13 19:22 
GeneralRe: Problem with result Pinmembermustafa98214-Jun-13 10:19 
GeneralRe: Problem with result Pinmemberlukeer16-Jun-13 19:46 
QuestionParallel Port Problem Need Urgent Help PinmemberSaddam Khan20-Sep-11 17:33 
QuestionPort Address PinmemberPinkPurple3-Sep-11 5:41 
GeneralHow to set parallel port in VB6 programming? Pinmembersaathis26-Apr-11 23:53 
GeneralHow to set parallel port in VB programming? Pinmembersaathis26-Apr-11 23:53 
GeneralThanks! PinmemberC1sc03-Sep-10 13:56 
GeneralMy vote of 3 Pinmembergotohellda4-Jul-10 23:11 
GeneralThanx PinmemberKhalido8r27-Apr-10 21:22 
NewsParallel Port Digital Oszilloscope and Logic Analyzer PinmvpElmue24-Apr-10 3:49 
QuestionReading port status change event Pinmembersairfan113-Dec-09 3:58 
GeneralIt is working in vb 2008 also PinmemberHarshadwasu15-Nov-09 7:49 
GeneralRe: It is working in vb 2008 also Pinmembermomina sheikh1-Oct-12 8:26 
Generalhi this code really works Pinmemberfred0702-Oct-09 16:08 
GeneralRe: hi this code really works Pinmembermomina sheikh1-Oct-12 8:35 
QuestionCan not work normally PinmemberRick Pan21-Apr-09 5:27 
AnswerRe: Can not work normally Pinmemberfred0702-Oct-09 16:09 
GeneralRe: Can not work normally Pinmembermomina sheikh2-Oct-12 2:26 
GeneralPIC based project Pinmembermaelan09141-Jan-09 3:38 
GeneralS0, S1 and S2 Pinmemberjavier_nicolasYahoo7-Dec-08 8:04 
Generalinout32.dll not working Pinmemberbobbyaryan1604-Dec-08 20:01 
Generalcontling micrcontroller Pinmemberbobbyaryan16023-Nov-08 19:30 
Generalwe screwed up - general hang Pinmembermackel0111-Sep-08 13:28 
GeneralRe: we screwed up - general hang PinmemberAimica10-Sep-10 7:56 
Generaladd button switch PinmemberQurex16-Jun-08 0:20 
Generalit's not working :S Pinmembermalalation29-Feb-08 17:21 
GeneralRe: it's not working :S PinmemberPetey14-May-08 6:15 
QuestionCan i receive data with event? Pinmemberamir1928-Oct-07 7:26 
AnswerRe: Can i receive data with event? PinmemberPablo Romano2-May-09 18:11 
QuestionStill have inpout3.dll? PinmemberAriston Darmayuda27-Jul-07 18:14 
AnswerRe: Still have inpout3.dll? Pinmembercitizen_runner23-Nov-07 6:26 
AnswerRe: Still have inpout3.dll? Pinmembergsuspradeep19-Dec-09 17:04 
Questionparallel port input Pinmemberdannydy29-May-07 21:53 
AnswerRe: parallel port input Pinmemberrigidigi3-Jul-07 1:40 
GeneralRe: parallel port input Pinmemberdannydy3-Jul-07 7:20 
GeneralRe: parallel port input [modified] Pinmemberrigidigi4-Jul-07 21:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 8 Aug 2006
Article Copyright 2006 by phebejtsov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid