Solved

Parallel port and MFC

Posted on 1998-07-27
6
585 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

759 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

20 Experts available now in Live!

Get 1:1 Help Now