Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Parallel port programming in Win32

Posted on 1998-04-07
6
Medium Priority
?
1,303 Views
Last Modified: 2013-12-03
I would like to use the parallel port with Win32 API routines. I know that I can open the port using 'CreateFile' and write the port using the 'WriteFile' routine. However, I assume that this lets you write 8 bits of data via the parallel port 'data' register. I need to be able to use the parallel port 'status' register and the 'control' register. Do I have to use a driver in order to do this or is there a way to access these ports within the Win32 API??

In case I am not clear on what is meant by the parallel port data, status, and control registers, I am talking about the registers that occupy I/O space. Normally, the first parallel port resides at I/O address 0x3BC. This is the 'data' register of the parallel port. The status and control registers follow at I/O address 0x3BD and 0x3BE, consecutively. These are the registers that I would like to access via the Win32 API.
0
Comment
Question by:cunningham
[X]
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
6 Comments
 

Expert Comment

by:maries032698
ID: 1412604
I was just going to post the same question to the exchange. The only difference is that on my machine, the addresses are 0x378 (data) 0x379 (status) and 0x37A and I am using the _inp() and _outp() functions. So, for example, _inp(0x378) should read the byte data register byte.
If you find out more, please let me know.


0
 

Author Comment

by:cunningham
ID: 1412605
As far as I can tell, parallel ports reside at either 0x3BC, 0x378, or 0x278. I think it is dependent on the type of motherboard you have in your system. I am not very clear on this and am not sure exactly how you find out what address is assigned to LPT1, LPT2, etc.
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 200 total points
ID: 1412606
This is code I use...

static int DataRegister = 0x278;
#define DATAREGISTER ((unsigned short) DataRegister)
#define STATUSREGISTER ((unsigned short) (DataRegister + 1))
#define CONTROLREGISTER ((unsigned short) (DataRegister + 2))

void OutData(BYTE b)      { _outp (DATAREGISTER, b); }
void OutControl(BYTE b)      { _outp (CONTROLREGISTER, b); }
void OutStatus(BYTE b)      { _outp (STATUSREGISTER, b); }

int GetStatus(void)            { return _inp(STATUSREGISTER); }
int GetControl(void)      { return _inp(CONTROLREGISTER); }

bool SetPrinterPort(int which) {
    /* Select print port at one of the allowable addresses */
    /* which = 0,1,2,... and when the selection is not ok, return false */
    switch (which) {
    case 0: DataRegister = 0x278; break;
    case 1: DataRegister = 0x3BC; break;
    case 2: DataRegister = 0x378; break;
    default: return false;
    }
    return true;
}

...

can either get port number info from user or write a loop like this...

for (int j = 0; !ok && SetPrinterPort(j); j++) {
      // try to access the port
}

Roger

0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:cunningham
ID: 1412607
RONSLOW - The answer that you gave is good. However, I am looking for a way to use the standard communication functions of the Win32 API (ie. CreateFile("LPT1"...), ReadFile, WriteFile, etc.) to be able to control all of the registers of the parallel port. I knew that I could use the _inp() and _outp() functions to directly access these registers although this was not stated in my question (sorry - my bad). Is there a way to use the Win32 API functions to control the data, status, and control registers of the parallel port or do I have to use the _inp and _outp functions??
0
 
LVL 1

Expert Comment

by:iron_fist
ID: 1412608
If your program will be run on Windows 95 only, you can use ClearCommError to read the status register. Otherwaise, I'm afraid you have to use a driver to access the parallel port registers.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1412609
The answer is "No" as far as Win32 API is concerned.  The best solution is to write a VxD (for win95) or NT Driver (for NT).  These would do the _inp and _outp calls on your behalf.

On Win95 this is not strictly necessary, but a VxD can make timing critical operations more reliable and, if properly written, will stop conflicts on the printer port.

On NT a driver is (almost) required, although it is possible to turn the protection off for the port access, but makes it open season on the parallel port and could cause system problems.

0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Screencast - Getting to Know the Pipeline

610 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