Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Parallel port and MFC

Posted on 1998-07-27
6
589 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 67
method notes when mouse over in eclipse 5 87
wait notify demo infinite loop 3 121
"Black Box" Testing of Control System Software 2 69
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.

790 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