Solved

win32 paralle port I/O

Posted on 1998-08-22
17
633 Views
Last Modified: 2013-12-03
From a win32 app, I need to control an external device connected to the PC thru the paralle port. I already have a DOS program which does this. It accesses the paralle port using IN and OUT instructions. How do I do this under win32 ?

Just a pointer to the info is enough.
0
Comment
Question by:byang
  • 7
  • 3
  • 2
  • +4
17 Comments
 
LVL 11

Expert Comment

by:alexo
Comment Utility
You cannot, unless you want to write a device driver.  IN and OUT instructions can only run in kernel mode under NT.

You could open the port using CreateFile("LPT1", ...) and read/write data using ReadFile() and WriteFile() functions.
0
 
LVL 4

Expert Comment

by:agreen
Comment Utility
>>You cannot, unless you want to write a device driver.
You're right - the best way to do that is to write a device driver. But under Win95 and Win98 the Win32 applications do have I/O access.

>>IN and OUT instructions can only run in kernel mode under NT.
The ntiosupp.dll will help you to access the I/O space from the user mode application under Windows NT: http://warmcat.com/ntiosupp.zip
0
 
LVL 3

Author Comment

by:byang
Comment Utility
I need this to work on win95, nt, and win98. Ideally on WinCE too.

So I cannot use IN and OUT instructions. What I am asking for is something like accessing the port thru some of standard paralle port driver, or win32 API.

I know I can open the port as a regular file, but then I need info on how data read by ReadFile() and data written by WriteFile() maps to pins on the port, or bits on the port registers.

For example, on a standard unidirecitonal port, external devices can change the voltages on 5 control pins (error, acknowledge etc). The CPU can then read them using IN instruction. If I use ReadFile(), how are these 5 bits returned ?


0
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
If you are going to do parallel port communication with Win95 and WinNT, you've gotta write yourself a VxD.  I've had little to no success at all with ReadFile and WriteFile using the parallel port.  You have no low level support using these features.

Check out the products available like VToolsD for your parallel port access.  You'll get a program up and running in days vs. months or not at all.  The price is relatively high but it's nothing compared to the troubles you'll see.

Phillip
0
 
LVL 4

Expert Comment

by:agreen
Comment Utility
>>So I cannot use IN and OUT instructions.
You CAN !!! See my comment above.
0
 
LVL 3

Author Comment

by:byang
Comment Utility
I would like to avoid requiring a Vxd or device driver for my app, as it complicates shipping and installation.

To Andy Green:
I downloaded your ZIP file and it looks very interesting. I haven't tested it on NT yet but if it works, there's obviously some way to disable i/o trapping. I'd like to know:

1. Is it part of regular win32 API, or part of the device driver API ?
2. Do you need administrator previlege to use it ?
3. If possible, I'd like to see the code for you DLL, and the code for the DLL you're embedding in your DLL.

0
 
LVL 4

Expert Comment

by:agreen
Comment Utility
1) The NTIOSUPP.DLL uses the CreateService and StartService Win32 API functions to install the GIVEIO.SYS device driver that uses two undocumented functions to give I/O access to the calling process.

2) Yes you need the administrator privs. to use the ntiosupp.dll.
3) The ntiosupp.dll was written by Andy Green (aka warmcat) ask him (andy@warmcat.com). The source code of the GIVEIO.SYS driver you can find in the DDJ's May 1996 sources. (www.ddj.com).

Btw see the INSTDRV NT DDK's sample that shows how to install the driver without forcing the user to reboot. I think that warmcat uses the same way to load the GIVEIO.SYS
0
 
LVL 11

Expert Comment

by:alexo
Comment Utility
Is ut just me or anybody else sees some similarity between "Andy Green" and "agreen"?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 4

Expert Comment

by:agreen
Comment Utility
alexo: :))
By a weird coincidence the warmcat's real name is Andy Green
and my name is Alex :)

0
 
LVL 1

Expert Comment

by:issamwd
Comment Utility
It is so easy to do that just follow my instructions:

First method :
      If you are familier with Assembly language you can add your code in assembly language to Delphi , Vbasic, VC++ ......
as following :
     ASM
          {
           ...
....    //write your code here
...
..
          }
the instructions you must use are
IN           addressOf port in hexadecimel
OUT       addressOf port in hexadecimel

the syntax depens on the kind of your processor
you can take the assistance of any book talking about Microprocessors or you can e-mail me.

second method:

Win32 programming langauges gives two instructions
for getting/giving information from/to port
they are
InPort ,
OutPort ,
they accepts the address of the port you are using
( Parallel port address =  3f8 Hexadecimal or 888 decimal )  
the syntax changes with programming language you are using.

These are the two ways, I used them when I was in my Fourth Year applying on an interfacing project.

0
 
LVL 4

Expert Comment

by:agreen
Comment Utility
issamwd:
Under Windows NT all the I/O ports are trapped.  
Under Windows 95 some ports are also trapped, for example the serial ports.
So in both cases you need a piece of kernel mode code.
0
 
LVL 2

Expert Comment

by:warmcat
Comment Utility
As Alex and I live in different countries, we have never been seen together at the same time and same place :)  But I really am quite sure we're different people.

I fear your hope of unifying 95, NT and CE are doomed when it comes to IO.  If you use NTIOSUPP.DLL, you will be able to write a single piece of Application code that ''just works'' on 95, 98 and NT.  CE does not even use 80x86 processors, so you really will have to look into the CE SDK to find out what you're meant to do.  Unless it's a high-volume consumer device well suited to portable/battery operation I would skip CE support.

Regards,

-Andy
0
 
LVL 2

Expert Comment

by:warmcat
Comment Utility
BTW, issamwd's comment:

>( Parallel port address =  3f8 Hexadecimal or 888 decimal )  

is busted: 0x378 is the normal address for LPT1.  See http://warmcat.com/parallel for a deeper discussion on how to get LPT base addresses, and some of the diseases that can attack the unwary LPT bit-twiddler.
0
 
LVL 3

Author Comment

by:byang
Comment Utility
Confusing names: I know warmcat is Andy Green from his web site, but agreen is not Andy Green ?

Agreen was the first one to point to the solution (on warmcat's web site, or are they the same person), so I'll give the points to agreen.
0
 
LVL 4

Accepted Solution

by:
agreen earned 50 total points
Comment Utility
Thank you, byang.

0
 
LVL 4

Expert Comment

by:agreen
Comment Utility
>>...or are they the same person
Once again - we are different people :))

warmcat:
May be it will be better for me to write my own implementation of the giveio.sys loader instead of directing people to your web site or it will be better to change my nick ?? (joke) :)))
0
 

Expert Comment

by:Splatterware
Comment Utility
You can accsses easily with the LPT und Win95 / 98 with
the Borland CBuilder:

For Example:
The Parallelport base address 378h

unsigned char x;
.
.
.
C-Code
.
.
.
// input
asm{
 mov dx,0x379
 in a,dx
 mov x,a
}
... now you can use x and its value in normal C code
.
.
.
// ouput
x=10; //just an example
asm{
 mov dx,0x379
 mov a,x
 out dx,a
}
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared 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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 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

8 Experts available now in Live!

Get 1:1 Help Now