Solved

Using Parallel Port for Switch Input

Posted on 1998-08-02
2
402 Views
Last Modified: 2013-11-15
Hi,
I'm trying to read switch input from the parallel port and am having trouble getting the input.  I've opened the port using FILE streams on "PRN", and also tried to read from the port with _inp(), but I don't seem to be able to read any changes on the port when I activate the switch.  I also havn't been able to verify that I've actually read the port since the uninitialized data in the buffer was not overwritten by the call to the read functions.  This also might not be a programming problem, but a hardware problem.  Right now, I'm just making connection between pins 2-9 and pin 25 trying to see a change on the port, but I'm not seeing it.  Any suggestions on how to do this.  Thanks.
Mark
0
Comment
Question by:mustang070597
2 Comments
 

Author Comment

by:mustang070597
ID: 1169222
P.S. I forgot to mention that I'm working in Windows 95/98, and using Visual C++ 4.2.
0
 
LVL 2

Accepted Solution

by:
warmcat earned 150 total points
ID: 1169223
musty -

Parallel ports come in ''standard'', ''bidirectional'', and ''EPP/ECP'' flavours.  You can only count on any particular PC meeting the ''standard''.. uh.. standard.

This has the data lines on p2..p9 as *output only*, so that's why you're not getting any joy there.

Opening a FILE * to PRN is a loser too.... think about it... what consititutes a ''character'' if you are hoping to detect one bit changing at a time?

Instead, you should wire your switch to pin10, pin11, pin12, pin13 or pin15.  You can pick up the states of these lines on _inp(wBaseAds+1), where wBaseAds is 0x378 or 0x278 for LPT1 or 2 (see http://warmcat.com/parallel for a better way to get base addresses and more detail).

The readback information:

b7 is ~pin11  (~ indicates inverted logic)
b6 is pin10
b5 is pin12
b4 is pin13
b3 is pin15

-Andy
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question