![]() |
Languages »
VB.NET »
General
Intermediate
Reading from Parallel Port using Inpout32.dllBy phebejtsovUsing the Signal Port to read in data instead of Data Port |
VB.NET 2.0, WinXP, Visual Studio, Dev, QA
|
||||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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 (
Go to �Control Panel / System / Hardware Tab / Device Manager / Ports (Com & LPT) /
It should indicate what type you have. You can also go to the �Resource� Tab to indicate the range of your port: mine is
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.
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:
The 2nd Tutorial: Reading from the 'status' port externally.

Option Strict Off
Option Explicit On
Module InpOut32_Declarations
'Inp and Out declarations for port I/O using inpout32.dll.
Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As Short) As Short
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Short, ByVal Value As Short)
End Module

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
Out(&H378S, &HFFS) 'Print '1' to D7-D0 or 255 in Decimal
Dim Value1 As String 'String named Value1
Value1 = Inp(&H378S) 'Now Value1 has the values in 'data port'
MessageBox.Show(Value1) 'A popup will indicate the current value written


Dim Value2 As String 'String named Value2
Value2 = Inp(&H379S) '
Now Value2 has the values in 'signal port'MessageBox.Show(Value2) 'A popup will indicate the current value written


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.
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.
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
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
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
The result should be: 88
S7
S6
S5
S4
S3
S2
S1
S0
0
1
0
1
1
0
0
0
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.
Email me at phebejtsov@yahoo.com for questions.
Regards
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 8 Aug 2006 Editor: |
Copyright 2006 by phebejtsov Everything else Copyright © CodeProject, 1999-2009 Web19 | Advertise on the Code Project |