Link to home
Start Free TrialLog in
Avatar of headley
headley

asked on

Parallel port and MFC

I would like to send data strings to a device connected to my parallel port using MFC 5.0.  I have seen a variety of responses as to how to do this... "Use CreateFile()"... "You cannot use CreateFile(), you have to go thru the VxD"... "You can use CreateFile() with Windows 95"... etc. etc.  I am only interested in getting this to work under Windows 95.  Do I need to go thru a driver, can I use CreateFile()?  Is there some way I could use a dedicated thread to read the status of the parallel port to read data from the parallel port when there is data available?  Do I need to set the parallel port data buffer to hold a specified number of characters before I get around to reading it?  

Basically, I just need a method to read and write data strings to a custom device that is not a printer.  Can anyone give me some advice AND OR sample code?

Thanks in advance
Garrett Headley
Avatar of trestan
trestan
Flag of Canada image

Avatar of warmcat
warmcat

Hi headly -

If it's just '95 you're after working with, use the following tips:  Use this to get the IO base ads of printer port n

// returns 0 for invalid port, or IO base ads

WORD GetPrinterPortBaseAddress(int nPort) // 0=LPT1, 1=LPT2 ..3
{
WORD * pwDosPrinterPortBaseAddresses= (WORD *) 0x0408;
if((nPort<4)&&(nPort>=0)) return pwDosPrinterPortBaseAddresses[nPort];
return(0);
}

Then write to the (base ads+0) to set D0..D7 on the printer port, eg outp(wBaseAds, 0x55);.  inp(wBaseAds+1) reads back the input lines, and outp(wBaseAds+2) writes to the status lines.

Contact me at andy@warmcat.com if you need more detail.


ALready answered, but you don't need a VxD for sure! If you need source, contact me.

You can still use the standard _inp and _outp as well.

Phillip

Avatar of headley

ASKER

Phillip, I would LOVE some source code.  The help from sites:
http://www.lvr.com/parport.htm 
http://dialspace.dial.pipex.com/town/close/ec63/portio95.htm
I've been over a couple of times, and cannot seem to figure out how to make it useful... I really need something that will allow me to send a string of characters to the parallel port... even if it can be done only 1 character at a time.  I'm checking into Andy's advice, but haven't gotten it to work correctly yet.  I apologize for delays in grading these responses... one fire after another seems to be springing up at the moment.

So yeah, source code would be GREAT!!

Garrett
ASKER CERTIFIED SOLUTION
Avatar of warmcat
warmcat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of headley

ASKER

Thanks to Andy for sample code... if Phillip comes across this question again, I'd definitely appriciate the sample code you offered.  You can always email it to me headley@cs.ucsb.edu

Garrett