read data from Parallel port

Posted on 2003-11-11
Last Modified: 2010-05-18

i want to read data and write  to Parallel  port  from   a Delphi proram.
Question by:mohammedasd
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

Accepted Solution

saienlyh earned 30 total points
ID: 9721776
unit Port95;
* Description: Port95 - very simple unit, that lets you access port *
* under Window 95,not under Windows NT. *
* Status: Freeware *
* You can freely use or distribute this unit *
* Target: Delphi 2/3 only under Windows 95 *
* Version: 1.0 (April 27, 1997) *
* Status: Freeware *
* Author: Anatoly Podgoretsky *
* Address: *
* Tips: font Courier, tabs = 2 *
* Problems: Word Read/Write utulities may problems on some computers *
* or interface cards, that can't access whole word. *
* To prevent it You can use slow equivalent of these *
* procedures with suffix LS (Low Speed) *
* Copyright: Copyright (C) 1997, NPS *

function PortReadByte(Addr:Word) : Byte;
function PortReadWord(Addr:Word) : Word;
function PortReadWordLS(Addr:Word) : Word;
procedure PortWriteByte(Addr:Word; Value:Byte);
procedure PortWriteWord(Addr:Word; Value:Word);
procedure PortWriteWordLS(Addr:Word; Value:Word);
* Port Read byte function *
* Parameter: port address *
* Return: byte value from given port *
function PortReadByte(Addr:Word) : Byte; assembler; register;

* HIGH SPEED Port Read Word function *
* Parameter: port address *
* Return: word value from given port *
* Comment: may problem with some cards and computers *
* that can't to access whole word, usually it work. *
function PortReadWord(Addr:Word) : Word; assembler; register;
* LOW SPEED Port Read Word function *
* Parameter: port address *
* Return: word value from given port *
* Comment: work in all cases, only to adjust DELAY if need *

function PortReadWordLS(Addr:Word) : Word; assembler; register;
Delay = 150; // depending of CPU speed and cards speed
IN AL,DX // read LSB port
MOV ECX,Delay
LOOP @1 // delay between two reads
INC DX // port+1
IN AL,DX // read MSB port
XCHG AH,AL // restore bytes order
* Port Write byte function *

* Parameter: port address *

procedure PortWriteByte(Addr:Word; Value:Byte); assembler; register;


* HIGH SPEED Port Write word procedure *
* Comment: may problem with some cards and computers *
* that can't to access whole word, usually it work. *
procedure PortWriteWord(Addr:word; Value:word); assembler; register;


* LOW SPEED Port Write Word procedure *
* Parameter: port address *
* Return: word value from given port *
* Comment: work in all cases, only to adjust DELAY if need *
procedure PortWriteWordLS(Addr:word; Value:word); assembler; register;

Delay = 150; // depending of CPU speed and cards speed
OUT DX,AL // port LSB
MOV ECX,Delay
LOOP @1 // delay between two writes

INC DX // port+1
OUT DX,AL // port MSB


Author Comment

ID: 9721859
hi  saienlyh
  sorry , i used windows XP and delphi 6  ,are you have code for that

Expert Comment

ID: 9721875
I have not Code

Expert Comment

ID: 9721899
Look at, about 3/5 of the way down is a section with a DLL (inpout32.dll). Use this on XP/NT/2K/95/ME/98.

Geoff M.

Expert Comment

ID: 9725326
Hi :-)

I wrote a cute little util in delphi (118kb) that lets you controll the ports.

It is customizable and can be used as a command line you can
very simply use it from your own code to control a port..

If it looks good to you you can use it as it is as a util or I can show you how to
recreate the functionality in your own app :-)

Please right click this link and choose 'save target as' because geocities does
not allow direct file linking.

here is the readme from this program (I hope it formats correctly)
Portie is a FREEWARE utility program written by me, Gwen Carpenter
 You may use this program freely for both personal and commercial purposes.

Portie is a controller util that can switch on/off the 8 output lines of any of the 3 common lpt ports  $378 $278 $3BC

This util has customizable button text that lets you label the buttons that toggle the output lines any way that you
like... by default they are named as RELAY1 thru RELAY8. Portie requires NO installation, does not write data
to the registry, works in ALL windows versions, is totally self-contained, alters it's own exe file to allow customization,
holds a tiny 3kb driver file within itself and ejects it if needed for use on NT/2000/XP.

If you double click the port address label in the upper left corner you will toggle from one lpt port to another but
THIS DOES NOT CHANGE THE DEFAULT PORT ADDRESS!  to change that use the Customize exe screen.

You can also add a custom info that will replace current info... just create your own info as a .txt file and add it to the
exe using the Customize Exe screen.

This util can also be called as a command line util, so you can use it to easily control the ports from about any
programming language...when called this way the exe will NOT display, just run and exit... here are the commands...
They are all case insensitive!

"Portie allon"                        -->Sets all lines ON for the default port
"Portie alloff"                        -->As above but turns the lines OFF
"Portie display"                   -->Pops up a messagebox showing the value held in
                                                       the default port
"Portie $???"                        -->Pops up a box as above but it displays the value held in
                                                      any port... enter values in HEX ONLY!  i.e.
                                                      Portie $378  or Portie $12A  any port can be used not
                                                       just the lpt port addresses.
"Portie ????????"              -->This command has a length of 8 characters and they
                                                      can be 0,1 or x    a '0' clears that bit of the default port
                                                      a '1' sets that bit, and ' x' leaves that bit alone. i.e
                                                     "Portie xxxxxxxx" would change NOTHING
                                                     "Portie 11111111" would set all bits ON
                                                     "Portie 00000000" would set all bits OFF
                                                     "Portie x10xx011" sets some bits. clears others and
                                                     leaves some as they are.

CUSTOMIZE EXE INSTRUCTIONS......................
In the customize exe screen you will find these buttons

[Store Changes]  This button saves the changes you have made.

[Lock Exe] This button saves changes and locks the exe to prevent any
future changes..

[ADD A CUSTOM INFO FILE] Lets you replace this info file.

[Abort] This gets you out of the customize screen without saving any changes.

In the select lpt Port frame you can select a new port address to become the default.  You can also set Portie
to clear all bits of the port on startup.

the custom changes are added to the exe itself.. no use of the registry and no ini files are written :-)

If I get some feedback on this util asking for some useful additions I will add them...

I may add some timer functions... the timer scripts will, of course, store right into the exe
and not into external files :-)

Here are the software rules I go by..

1- Programs should NOT need to be installed.
2- If  a program won't fit on a single 1.44 floppy I won't publish it!
3- Programs should NOT write files or data anywhere outside their own dir unless the user requests it!
4- If it isn't CUTE I won't publish it :-)
5- It must be unique.. not a simple clone of something dull like a text-editor :-(
6- Must work on all win32 versions!
7- If EVERY FILE  needed (except a readme file) won't go into the exe then I won't publish it!

I say If at all possible use DELPHI... since life is sooo short and you can code so quickly with it :-)

p.s. This program was compiled with Delphi2 standard... I payed 2$ for it on EBAY so I got
in on the CHEAP :-)

ZLPORTIO  - Zlportio  is used in this util... this is a wonderful piece of freeware code by
Zloba Alexander ... many thanx go out to Zloba for his great freeware code :-)
see more of Zloba's work at

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Performance of SQL statement 37 137
Firemonkey webbrowser scrollbars ? 1 57
enhance the following code 3 42
FMX TEdit KeyUp handler detecting  "enter" key 4 41
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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