Solved

Parallel port and MFC

Posted on 1998-07-27
6
586 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:headley
6 Comments
 
LVL 8

Expert Comment

by:trestan
ID: 1319793
0
 
LVL 2

Expert Comment

by:warmcat
ID: 1319794
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.


0
 
LVL 7

Expert Comment

by:psdavis
ID: 1319795
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

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:headley
ID: 1319796
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
0
 
LVL 2

Accepted Solution

by:
warmcat earned 200 total points
ID: 1319797
Headly -

The sample I gave you works in a DOS app - now I see you are in the 32-bit world.  Use the following code instead...

WORD GetPrinterPortBaseAddress(int nPort) // 0=LPT1, 1=LPT2 ..3
{
   WORD wa[4];
   DWORD dwRead;

   if( (nPort<0)||(nPort>3) ) return(0);
   if(ReadProcessMemory(GetCurrentProcess() ,(void *)0x00000408, wa, sizeof(wa), &dwRead)) {
      return (wa[nPort]);
   } else {
      return(0);
   }
}

. some sample code to go with it ....

int main()
{
   WORD wBase=GetPrinterPortBaseAddress(0);
   int n;

   if(wBase==0) { printf("Unable to get LPT1 base ads\n"); return(1); }

   for(n=0;n<1000;n++) {
     outp(wBase, 0x55);
     outp(wBase, 0xaa);
   }
   return(0);
}

. mail me if you need more advice.

-Andy
0
 

Author Comment

by:headley
ID: 1319798
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

25 Experts available now in Live!

Get 1:1 Help Now