I have a somewhat oldish piece of electronic equipment (circa 1995) that connects to the host using the printer/parallel port.

The 'drivers' included in the software package were written for DOS; I want to create versions for Windows 32.

As it happens the interfacing library included in the software package is in source code form, and the source of the driving software (which detects the equipment, runs tests, and loads applications into the equipment) happens to be included.

What I need to know is how to directly control the parallel port of a PC from Windows. Am I allowed to directly read and write the ports? Or do I need to ask permission from Windows in some manner? How do I detect what I/O addresses the ports are?
Posted on 2003-04-03 20:33:51 by AmkG
The Ststem Properties dialog (right click My Computer, pick Properties) will give you the addredd of the port. Sorry, I don't know how to get it on the fly.

For W9x, you can use the IN and OUT asm statements to bang ports directly. Otherwise, you'll need a driver. Search for WinIO.dll, its a freebie good for this stuff.
Posted on 2003-04-03 21:50:34 by Ernie
Hello Pare!

Well, you can't do it in windows. And yes, you need permission to access it. If you want to access ports in Windows then you need to switch to ring 0, then you can execute

in al, dx

or

out dx, al

you need to code either a dll or vxd(for win9x) or wdm (for nt/2k/xp). I have coded my own dll to access the parallel port. I kinda got the idea from an article found @ asm programming journal. I forgot the issue #. it's a cool way to switch from ring 3 to ring 0.

accdg to jan axelson (author of parallel port complete), if you want to get the address of the parallel port (in windows), you need to call GetPrivateProfileString to open an ini file (lptprogs.ini) and read the 'lptdata'. i haven't done that. i just hardcoded the address i found at the bios setting ;)

anyway, see attached file (it's for win9x only)

regards,
flotsam

btw, forgive me for the documentation. like i told you i suck at programming :grin:
Posted on 2003-04-03 22:02:12 by flotsam
This and simular things have been a forever topic it seems. Yes there is a good dll out there that is quick and dirty, but my problem is they dont address interupts at all... I dont like the idea of writing apps that poll for hardware responce. I would rather be properly messaged at ring 3 of new info loading into a port.

However, the problem that keeps this at its standstill (publically on this board) is the fact that WDMs (which is where future OS is heading) have a steep learning curve, with minimal to no good resources to work from.

I personally would like to openly "slay" this dragon, make the do's, dont's, and how-to's made public so that more unique assmenbly/hardward projects can be introduced and discussed.

I would drop everything im doing at the moment and help research/write documentation if others are interested in helping out as well... to me this knowledge would be one of the best assets to have (from an electronics first, asm second point of view).

:NaN:
Posted on 2003-04-03 22:49:12 by NaN

with minimal to no good resources to work from

last time I looked in NTDDK there were extensive amounts of documentation and example source?
Posted on 2003-04-03 23:44:03 by f0dder
flotsam,

Good job Pre!

I'll be taking your word that it works...

Say, what about the source code for your parport.dll file?

I take it I could use *any* address for this parport.dll file (so it's not just for parallel port, in theory I can also access serial port directly).

Incidentally, as of 80186 and later, you can push a constant directly - your sample source does mov eax,3 then push eax - it can be push 3 now.



Sincerely,
AmkG
Posted on 2003-04-04 02:05:44 by AmkG
to AmkG:

tnx for the reply. I'll post my source code here after i finish adding an interrupt procedure if i can (to eliminate polling, as NaN suggests).

yes, you can use any address (even for serial port). and tnx for the correction. that would save me a byte or so ;)

to Nan:
I agree that polling sucks, and it's a waste of resources by just reading the status ports (or any) all the time. anyway, i have this idea in my mind. kinda like an ISR. so for example, after setting bit 4 of the control port (interrupt enable), placing a "0" at bit 6 of status port (nAck) would generate an interrupt 5. in asm, we can just replace for the moment interrupt 5 with our own interrupt, execute our code, then put back the original int5 (much like TSRs). i know in theory it will work :)
any suggestions are welcomed!

I would drop everything im doing at the moment and help research/write documentation if others are interested in helping out as well

I'll help! i love pc interfacing :cool:
Posted on 2003-04-04 12:24:41 by flotsam

in asm, we can just replace for the moment interrupt 5 with our own interrupt, execute our code, then put back the original int5 (much like TSRs). i know in theory it will work

But it's rather dirty code :eek:, and if you have _any_ plans for NT support, you should look up the correct way to do it.
Posted on 2003-04-04 12:48:07 by f0dder
Hi,

look at this:
hxxp://www.entechtaiwan.com/tools.htm

KSA
Posted on 2003-04-04 15:29:51 by KSA
But it's rather dirty code.


Yes i know it's kinda dirty. But that's just the way it is. I've done research on parallel ports. And the only way to act on the slave's request is either thru polling (inefficient) or thru int 5 or 7. If there's another way, I'd like to know. :alright:
Posted on 2003-04-04 20:32:15 by flotsam
I dont like the idea of writing apps that poll for hardware responce. I would rather be properly messaged at ring 3 of new info loading into a port.


I quite agree with you, I have the same prejudges.

However, the parallel port is already quite overburdened with having to drive printers, scanners, and all sorts of stuff. Additionally, it's going obsolete.

So what did I use? The USB port. I have a little demo board complete that gives me 3 bytes of outgoing signals, with 5 lines of interrupts back, and each interupt is divided into KeyDown and KeyUp events. The hardware needed is just a Microchip PIC16C765, a 4MHz crystal, some caps and a resistor, and an USB socket.

I did get a little lazy with the controlling code. Properly, it should have a free thread looking for the USB callbacks. I faked it out by using a VB exe server (since every .exe necessarily runs on its own thread).

But it all works together nicely. If anyone is interested, I can flip the code over. If pestered often enough, I'll make a tut out of it.
Posted on 2003-04-04 20:54:51 by Ernie
You lost me on the VB part...

However, i would like to formally acknowledge my "Pester" with you ;) . A quick and dirty tutorial would be awesome to have with USB. I have the "USB Design by Example" text published by Intel. But its alot to get through to find what your looking for. Cross referencing with a second source would be nice!

:NaN:
Posted on 2003-04-05 09:53:06 by NaN
flotsam, by dirty I was referring to ring0 hacks instead of using a proper driver. Polling is also "bad", but not "dirty" (in my mind anyway) :)
Posted on 2003-04-05 09:54:35 by f0dder
hi fodder,

i understand what you mean. yanking interrupts thru ring0 (and other methods) is indeed a dirty hack ;) i just wish microsoft was kind enough to publish code for drivers using parallel ports and others (the right way)...or i missed it again :eek:

regards,
flotsam
Posted on 2003-04-05 12:38:34 by flotsam
If you search the board you will find some stuff I posted on this topic a while back .. it may or may not help :)
Posted on 2003-04-27 01:00:31 by Homer
Most likely not, since the heap was flushed out of back dated posts reciently.... If you have it on your CPU please repost it..

:NaN:
Posted on 2003-04-27 01:03:16 by NaN
Afternoon, All.

http://www.lvr.com/parport.htm

Cheers,
Scronty
Posted on 2003-04-27 04:09:20 by Scronty
Beginnings of a DRO software for multi axis controller thru parallel port.
Uses WinIO, is meant to work for 98 thru XP .. enjoy..
Posted on 2003-05-01 07:30:48 by Homer
hey guys their are apis for reading ports directly.
see getcommmask, setcommmask, waitcommevent.
their are a total of 20 api for port use
these are win32 apis

good luck
Posted on 2003-07-11 21:47:32 by dhicks586
Replacing interrupt vector in Dos. I suppose we would need the documentation on WinX all's IDT. At that point we use a device driver to access the table entry and redirect it to an ISR. I saw something on the board with handling exceptions in Windows. Lastly would be allocating some non-volatile memory (from system's point of veiw) for the ISR. I'm not ready to tackle that just yet. I'm still studying four-F's tutorials and next is Walter Oney's book "Programming the Windows Driver Model". Since "Mad Scientist" or whatever his name is seems to be teasing us about his WDM tutorial.
Posted on 2003-07-13 13:00:21 by mrgone