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

read data from Parallel port

Posted on 2003-11-11
7
287 Views
Last Modified: 2010-05-18

i want to read data and write  to Parallel  port  from   a Delphi proram.
0
Comment
Question by:mohammedasd
7 Comments
 

Accepted Solution

by:
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: kvk@estpak.ee *
* 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 *
**************************************************************************}

interface
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);
implementation
{**************************************************************
* Port Read byte function *
* Parameter: port address *
* Return: byte value from given port *
**************************************************************}
function PortReadByte(Addr:Word) : Byte; assembler; register;
asm
MOV DX,AX
IN AL,DX
end;

{**************************************************************
* 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;
asm
MOV DX,AX
IN AX,DX
end;
{**************************************************************
* 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;
const
Delay = 150; // depending of CPU speed and cards speed
asm
MOV DX,AX
IN AL,DX // read LSB port
MOV ECX,Delay
@1:
LOOP @1 // delay between two reads
XCHG AH,AL
INC DX // port+1
IN AL,DX // read MSB port
XCHG AH,AL // restore bytes order
end;
{**************************************************************
* Port Write byte function *

* Parameter: port address *
**************************************************************}

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

asm
XCHG AX,DX
OUT DX,AL
end;


{**************************************************************
* 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;
asm
XCHG AX,DX

OUT DX,AX

end;
{**************************************************************
* 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;
const

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

INC DX // port+1
OUT DX,AL // port MSB
end;
end.

0
 

Author Comment

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

Expert Comment

by:saienlyh
ID: 9721875
I have not Code
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9721899
Look at http://www.lvr.com/parport.htm, 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.
0
 
LVL 5

Expert Comment

by:Gwena
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 util...so 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.

http://www.geocities.com/gacarpenter386/portie.zip

here is the readme from this program (I hope it formats correctly)
=======================================
Portie is a FREEWARE utility program written by me, Gwen Carpenter gacarpenter386@yahoo.com
 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 www.specosoft.com
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 101
Print Graphic and Text to Epson TM-T88v 12 367
find a node in VST 2 70
Dev express lookupcombo 3 34
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

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