Solved

Using Parallel Port for Switch Input

Posted on 1998-08-02
2
399 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Let’s list some of the technologies that enable smooth teleworking. 
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now