Previous in Forum: FEA (Finite Element Analysis)   Next in Forum: Survey Sheds Light on PCB Design
Close
Close
Close
15 comments
Rate Comments: Nested
Anonymous Poster

Reading from parallel port on windows xp

11/05/2006 2:11 PM

Hello everyone,

I've written a program that should read and write to the parallel port of my pc. I need to read input from several sensors / devices, as well as actuate certain processes through that interface as well. I've done this fairly easily on a Linux machine, but for some reason it's not so easy to do it in Windows. Apparently I need to code / download some driver, and then have it configured. This sounds like too much work that I hadn't anticipated, my project is already in the red, I cannot afford to spend any more time on this. If anyone can help, I'd be eternally greatful.

The program has to poll the parallel port and execute appropriate routines if it detects an interrupt.

This is all I get:

byte = 127

byte = 127

.........

byte = 127

where byte is defined as:

......

#define status 0x379

.....

byte = inportb(status); /*

printf("byte = %d\n", byte);

.......

The value of byte in the above example does NOT ever change, even if I change the values of the status inputs (ie. aknowledge, error, etc). I even thought my printer port was stuffed, but I reconnected my printer and was able to print just fine.

Any help would be welcome. Thanks.

Limpho Mothae

Reply
Pathfinder Tags: byte drivers sensors Windows XP
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#1

Re: Reading from parallel port on windows xp

11/05/2006 6:48 PM

Sadly, I don't know that you're going to get any kind of useful answer to this one.

I wrote device drivers for 'COM' and 'PRINTER' type ports (in assembler!) back in the days when Windows loaded on top of DOS. They worked fine with 3.1, and seemed to work as 'legacy' devices in other systems.

It was also possible to use interrupt type statements in many languages to get to the bits & bobs of the IO system, and more-or-less write some sort of driver at a higher level - maybe this still works - I haven't tried it recently.

Perhaps this sort of thing is still possible with XP, but I don't have any books on it, and I haven't seen anything this deep on the MS site (Microsoft Knowledge Base isn't any use). Have a scour through your nearest decent bookshop - there may be something around.

BTW what kind of C are you using? Where did you get "0x379" from?

Sorry to be the bringer of bad tidings. Anyone out there who can help?

__________________
"Love justice, you who rule the world" - Dante Alighieri
Reply
Anonymous Poster
#2
In reply to #1

Re: Reading from parallel port on windows xp

11/06/2006 12:15 AM

Hi, thanks for the response anyhow. I'm using Turbo C v3.1 I think it is, am really not used to usoft at all, but I had to use this project on a windows xp machine because that's what my client insisted on.

The 0x379 (= 888 in decimal, I think) is the address of the status port.

I've tried to download a driver that'll enable my program to access the parallel port but there's absolutely no change, hence my decision to look for help on these forums. This is actually an engineering project but I thought this forum would be the best place to come to for help. The driver is portnet95 and is supposed to be used by people who use NT based OSs (like XP). I don't know if the driver needs any special configuration, maybe that's why nothing is happening?

Thanks, Limpho Mothae, Johannesburg, South Africa

Reply
Active Contributor

Join Date: Sep 2006
Location: Bangalore, India
Posts: 20
#3
In reply to #2

Re: Reading from parallel port on windows xp

11/06/2006 12:23 AM

Hi !

It is not possible to access any hardware DIRECTLY (by reading/writing from/to the ports of the device) on Windows Systems. You must use an appropriate driver (which is running at a higher privilege level and will be able to access the device).

You need to open a device (by calling "CreateDevice()" routine in WinSDK) and then Read() from it.

No applications will ever be able to handle the device interrupts DIRECTLY (other than through 'notification' mechanisms from the underlying device driver).

Govinda Padaki

Reply
Participant

Join Date: Feb 2007
Location: mumbai
Posts: 1
#14
In reply to #3

Re: Reading from parallel port on windows xp

02/03/2007 12:26 AM

hi ,

i have tried -----inpout32.dll-------DriverLINX---

i am able to write to parallel port continuously but not able to read single byte

according to some sites tristating the parallel port bits will do.

doing this we can read from port.

but i dont know how to tristate the port................

please help me out as my project is in danger

__________________
JDT
Reply
Anonymous Poster
#4

Re: Reading from parallel port on windows xp

11/06/2006 12:35 AM

What you need is a driver that will translate your inportb call into an XP call. There is a dll that handles this, along with some example code. Look for inpout32.dll on google.

The downside for you is that you need a compiler that will support dll calls, and i´m guessing that borlandc does not. I tried it with devcpp and it worked fine. Try it with care and expect to hang up your pc in the process.

If you need more help mail me at alejandro@xve.com

Regards.

Alex.

Reply
Anonymous Poster
#5

Re: Reading from parallel port on windows xp

11/06/2006 3:36 AM

It's not reccommended by most but it can be done. I can't remember exactly how but it is something to do with windows permissions registers or something like that. There are various websites with example code for free download and several professional drivers for sale which will do it. I looked at doing it not long ago for a work project and found out a fair bit but the project was cancelled so I never got to complete it. Have a search on the web.

Reply
Participant

Join Date: Nov 2006
Location: Sunnyvale, California
Posts: 1
#6

Re: Reading from parallel port on windows xp

11/06/2006 5:58 AM

I have been using inpout32.dll and it works fine when compiled with Borland 5.

I haven't been able to make it work with Microsoft C++ version 6.

inpout32.dll allows you to access the parallel port registers but it does not work

for the serial port registers.

I have some simple routines that I will be glad to provide if you send me your email address.

regards,

Franco Iacobelli

fd_iacobelli@hotmail.com

Reply
Participant

Join Date: Oct 2006
Posts: 3
#7

Re: Reading from parallel port on windows xp

11/06/2006 6:12 AM

As other contributors already mentioned, you will need a specialized library to do it (there are many of them, try Google for "xp parallel port library") or open it as a device. Opening it as a device is pretty simple. You need just a few things:

- CreateFile( "LPT1", ... GENERIC_READ | GENERIC_WRITE, ...) to open the port for R/W access

- ReadFile and WriteFile for reading and writing

- CloseHandle to close it

BUT!!!! There's one thing you must know! These API calls expect some device, like printer, to be on the port and perform handshaking correctly. So for output you will need two things:

1. have a 74123 circuit generate the acknowledge signal. It's pretty simply, the computer raises (or lowers?) a signal to tell you that it sent data. This triggers the 74123 which generates acknowledge a moment later. That's all. The computer will not send any new data until it gets the acknowledge signal, so you really must do it.

2. have a latch there. The data will be on the port only until you send the acknowledge signal. So you need a latch triggered by the "new data" signal to hold them.

The same API (perhaps) will handle input and all the interrupts etc. The data should be stored in a buffer. So I think you can simply call ReadFile at given intervals and try to read the data. If some data arrived, you can get them byte-by-byte from the buffer. If no data arrived, the buffer will be empty and you will get corresponding error code. There's a function called SetCommTimeout to set timeouts, but I'm not sure if it works for parallel ports; I used it just for serial ones. Anyway, I never tried reading the parallel port, so it's just my guess. But I think it should work. If it does not, try the parallel port libraries, some of them handle the interrupts and call your own callback functions if it comes.

Reply
Guru

Join Date: Aug 2006
Posts: 4484
Good Answers: 246
#8

Re: Reading from parallel port on windows xp

11/06/2006 12:36 PM

I wish I could help. I used to do this kind of thing frequently with DOS machines, but have not done it with Windows machines other than through someone else's DLL. I'm sure there is a DLL available that will do exaclty what you want, but I don't know where.

__________________
There is more to life than just eating mice.
Reply
Active Contributor

Join Date: Jul 2006
Location: Texas! South of I-10
Posts: 16
#9

Re: Reading from parallel port on windows xp

11/06/2006 5:59 PM
Reply
Commentator
Peru - Member - New Member

Join Date: Oct 2006
Location: Lima Peru
Posts: 57
#10

Re: Reading from parallel port on windows xp

11/06/2006 11:10 PM

I had the same problem with a PIC programmer, You can try to run:

Start --> Run ---> C:\epicwin\NTINST.EXE /install

You can find it in the net looking "epicwin"

This works fine to me, you need to run it only ones

Regards

Ciro

__________________
There is allways another way
Reply
Anonymous Poster
#11
In reply to #10

Re: Reading from parallel port on windows xp

11/07/2006 2:48 AM

Thanks for all the help and suggestions guys. I'll keep you in the loop :-)

Cheers,

Limpho

Reply
Anonymous Poster
#12
In reply to #11

Re: Reading from parallel port on windows xp

11/08/2006 3:28 AM

Phew! That was too close to call! I was getting REALLY desperate, but I managed to get the bloody thing working, after having downloaded and tried every conceivable driver (well, almost). The driver that I'm using is a tad stupid in that it only grants IO permissions on the fly, meaning that everytime I run my program I should request temporary kernel-mode priviledges. It's stupid but it works. Part of my design entails decoding dtmf tones (transmitted either over a standard telephone line or over the air interface). Once the dtmf tones are decoded, they are then polled by the parallel port and mapped to specific digits in my code. The parallel port interface allows me to automate certain processes, e.g. delete access rights for a particular user over a phone line, remotely activate / deactivate the alarm, etc. I'm really happy, my project would've had to be cancelled if I didn't fix the bloody thing on time. I've "wasted" a lot of time but I've also learnt a lot, thanks to you guys, but I still hate usoft. Thanks again everyone, you're a great lot!

BR,

Limpho Mothae

Reply
Participant

Join Date: Nov 2006
Posts: 1
#13
In reply to #12

Re: Reading from parallel port on windows xp

11/16/2006 4:12 AM

Hello,

I have been for a while trying to Read\Write to parallel port printer. I began trying with CreateFile\ReadFile\WriteFile API. But I was unsuccessful in that attempt. I was able to open a handle and write to the printer. But somehow readfile fails. when readfile is called nothing happens and just the control waits there infinitely.

Then I tried using INPout32.dll. But I think in (Inp32(byte) call takes only a byte )that only a byte of data can be sent at once. How can a large chunk of data can be sent or read from the printer using the dll. I actually want to send a PJL to the printer and able to read the response from the printer. How can i do this using the Inpout32.dll. Thank you for any help provided for this.

Reply
Anonymous Poster
#15

Re: Reading from parallel port on windows xp

02/23/2007 2:35 AM

use FreeBASIC program the compiller is free to download

Reply
Reply to Forum Thread 15 comments
Copy to Clipboard

Users who posted comments:

47CDPG (1); Anonymous Poster (6); Blink (1); Bovlk (1); ciro (1); fiacobelli (1); GovindaPadaki (1); jignesh (1); JohnDG (1); virajitha (1)

Previous in Forum: FEA (Finite Element Analysis)   Next in Forum: Survey Sheds Light on PCB Design

Advertisement