Solved

win32 paralle port I/O

Posted on 1998-08-22
17
638 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
ID: 1413798
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
ID: 1413799
>>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
ID: 1413800
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 7

Expert Comment

by:psdavis
ID: 1413801
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
ID: 1413802
>>So I cannot use IN and OUT instructions.
You CAN !!! See my comment above.
0
 
LVL 3

Author Comment

by:byang
ID: 1413803
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
ID: 1413804
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
ID: 1413805
Is ut just me or anybody else sees some similarity between "Andy Green" and "agreen"?
0
 
LVL 4

Expert Comment

by:agreen
ID: 1413806
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
ID: 1413807
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
ID: 1413808
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
ID: 1413809
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
ID: 1413810
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
ID: 1413811
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
ID: 1413812
Thank you, byang.

0
 
LVL 4

Expert Comment

by:agreen
ID: 1413813
>>...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
ID: 7364642
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…

740 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