Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

read data from Parallel port

Posted on 2003-11-11
7
Medium Priority
?
296 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 120 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

927 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