Solved

Parallel port Interfacing

Posted on 2001-08-19
13
575 Views
Last Modified: 2010-04-06
how can i send data tru parallel port
or ACCEPT DATA Coming from outside.

all i know at port 378h you can assign a
value tru it example when you let
  378h:=1 then on the parallel Port PIN 2
  The (5 Volts) is On or HIGH when you
  put a 0 on port 378h then all PINS from 2 to
  9 will have no volts and it will remain as low.

how can i do that in Delphi
and also how can i accept data ?

ex.

 on PIN 10,11,12,13 ON the parallel port
 have a HIGH signal having 5Volts on each pin.
 when i SUPPPLY a LOW signal in each pin a data
 received on port 379H. exp.
 exp. on Turbo Pascal
  Repeat
   writeln(port[$379]);
  Until keypressed
 --when you send a LOW Signal on pin 10 THE VALUE
 of Port[$379] is 63.

How can i do this in DELPHI or is there another
way to received a data in Delphi?
0
Comment
Question by:ryan_sabarre
13 Comments
 

Author Comment

by:ryan_sabarre
ID: 6403135
help me please
0
 
LVL 2

Expert Comment

by:bugroger
ID: 6403145
0
 
LVL 10

Expert Comment

by:Jacco
ID: 6403203
A very good component set to do communications if AsyncPro of TurboPower I believe that support parallel port as well as com ports.

www.turbopower.com

Regards Jacco
0
 
LVL 8

Expert Comment

by:Cesario
ID: 6403337
reading
0
 
LVL 3

Expert Comment

by:VSF
ID: 6403436
Listenning!
VSF
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6403890
:-)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Accepted Solution

by:
chunky1 earned 300 total points
ID: 6406547
I have done this previously.
Instead of using a component, I used a small procedure which contained a small assembly language routine.

The routing is as follows:

procedure outport(port:longint;data:integer);
begin
     asm
        push ax
        push dx
        mov eax,data
        mov edx,port
        out dx,ax
        pop dx
        pop ax
     end;
end;


procedure inport(port:longint;var data:integer);
begin
     asm
        push ax
        push dx
        mov edx,port
        in dx,ax
        mov data,eax
        pop dx
        pop ax
     end;
end;


From your main program you can call either the inport or outport routine as follows:

outport(888,128); // port 888 is 378h in decimal.


Hope this helps.

Chunky.
0
 
LVL 2

Expert Comment

by:ivi
ID: 6408445
>how can i send data tru parallel port
or ACCEPT DATA Coming from outside.

chunky1 gave you an answer. But what is your operating system? This solution will work under Windows 98/98/ME only but not under NT/2000/XP.

0
 
LVL 5

Expert Comment

by:Gwena
ID: 6408471
Here is a file that will let you do lpt i/o under NT/2000/XP  Chunky's code is just perfect for 9x :-)

http://www.internals.com/utilities/winio.zip

and here is a delphi unit that makes winio easy to use
Arkamax wrote this for me a while back.... I hope it formats ok...if not I can email it to you :-)

unit winio;

interface
uses
   Windows;

function InitializeWinIo: boolean; stdcall;

{This function initializes the WinIo library.

For applications running under Windows NT/2000, this function
must be called before calling any other function in the library.

Windows 9x applications are not required to call this function.

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.}

procedure ShutdownWinIo; stdcall;

{This function performs cleanup of the WinIo library.

For applications running under Windows NT/2000, this function
must be called before terminating the application or when the
WinIo library is no longer required.

Windows 9x applications are not required to call this function.}

function GetPortVal(wPortAddr: WORD; pdwPortVal: PDWORD; bSize: BYTE): boolean; stdcall;

{Use this function to read a BYTE/WORD/DWORD value from an I/O port.

Parameters:

 wPortAddr - I/O port address

 pdwPortVal - Pointer to a DWORD variable that receives the value
              obtained from the port.

 bSize - Number of bytes to read.
         Can be 1 (BYTE), 2 (WORD) or 4 (DWORD).

 If the function succeeds, the return value is nonzero.

 If the function fails, the return value is zero.}

function SetPortVal(wPortAddr: WORD; dwPortVal: DWORD; bSize: BYTE): boolean; stdcall;

{Use this function to write a BYTE/WORD/DWORD value to an I/O port.

Parameters:

 wPortAddr - I/O port address

 dwPortVal - A DWORD value to be written to the port

 bSize - Number of bytes to write.
         Can be 1 (BYTE), 2 (WORD) or 4 (DWORD).

 If the function succeeds, the return value is nonzero.

 If the function fails, the return value is zero.}

function MapPhysToLin(pbPhysAddr: PBYTE; dwPhysSize: DWORD; pPhysicalMemoryHandle: PHANDLE): PBYTE;
stdcall;

{Use this function to map a region of physical memory into the linear address
space of a 32-bit Windows application.

Here is an example:

PBYTE pbLinAddr;
HANDLE PhysicalMemoryHandle;

pbLinAddr = MapPhysToLin(0xA0000, 65536, &PhysicalMemoryHandle);

The function will map physical addresses 0xA0000 - 0xAFFFF into the linear
address space of the application. The value returned is a linear address
corresponding to physical address 0xA0000. In case of an error, the return
value is NULL.

Parameters:

 pbPhysAddr - Pointer to the physical address
 
 dwPhysSize - Number of bytes to map

 pPhysicalMemoryHandle - Points to a variable that will receive the physical memory section
                         handle if this call is successful. This handle is later used as
                         the first parameter when calling the UnmapPhysicalMemory function.}

function UnmapPhysicalMemory(PhysicalMemoryHandle: THANDLE; pbLinAddr: PBYTE): boolean; stdcall;

{Use this function to unmap a region of physical memory which was previously mapped
to the linear address space of the application using the MapPhysToLin function.

Windows 9x applications are not required to call this function.

Parameters:

 PhysicalMemoryHandle - Handle to the physical memory section which was returned
                        from the call to the MapPhysToLin function.

 pbLinAddr - Linear address which was returned from the call to the MapPhysToLin
             function.}

function GetPhysLong(pbPhysAddr: PBYTE; pdwPhysVal: PDWORD): boolean; stdcall;

{This function reads one DWORD from the specified physical address.

Parametes:

 pbPhysAddr - Pointer to the physical address

 pdwPhysVal - Pointer to a DWORD variable that receives the value
              obtained from the physical memory location.

 If the function succeeds, the return value is nonzero.

 If the function fails, the return value is zero.}

function SetPhysLong(pbPhysAddr: PBYTE; dwPhysVal: DWORD): boolean; stdcall;

{This function writes one DWORD to the specified physical address.

Parametes:

 pbPhysAddr - Pointer to the physical address

 pdwPhysVal - Specifies a DWORD value to be written to the physical
              memory location.

 If the function succeeds, the return value is nonzero.

 If the function fails, the return value is zero.}

implementation
function InitializeWinIo; external 'winio.dll';
procedure ShutdownWinIo; external 'winio.dll';
function GetPortVal; external 'winio.dll';
function SetPortVal; external 'winio.dll';
function MapPhysToLin; external 'winio.dll';
function UnmapPhysicalMemory; external 'winio.dll';
function GetPhysLong; external 'winio.dll';
function SetPhysLong; external 'winio.dll';

end.

// -------------------

And this small test will show you the current time by peeking CMOS area through direct port access:

procedure TForm1.Button1Click(Sender: TObject);

function ReadCMOSByte(Offset: byte): byte;
var
  Inp: byte;

begin
    SetPortVal($70, Offset, sizeof(Offset));
    GetPortVal($71, @Inp, sizeof(Inp));
    Result:=Inp;
end;

begin
    Edit1.Text:=Format('%.2x:%.2x:%.2x', [ReadCMOSByte($4), ReadCMOSByte($2), ReadCMOSByte($0)]);
end;



0
 
LVL 5

Expert Comment

by:Gwena
ID: 6408504
Oh-- it also might be possible to tack the winio dll onto the end of your delphi exe and use it without extracting to disk...see this site for details.. it's a utility called PEBundle.. if this does the trick then you would be able to have a single exe with lpt and memory i/o under 9x and NT without any external dll file...    

http://www.collakesoftware.com/

0
 

Author Comment

by:ryan_sabarre
ID: 6424131
Thank you so much and
Gwena thanks for some info..
0
 

Expert Comment

by:multy
ID: 8875763
try http://www.logix4u.net/inpout32_source_and_bins.zip from http://www.logix4u.net. Vb sample programs are include in the zip file. It will work with delphi also.
0
 

Expert Comment

by:cuimeng
ID: 8965653
i have some problem using the code that Gwena posted.
when i use InitializeWinIo to initialize the library, the function always returns FALSE.
what's wrong?
can anybody help me?

thanks in advance!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi with SQL Natvie Client 15 75
Sending Gmail through Delphi 3 69
Intraweb download file link ? 1 88
Create a path if not exists 7 47
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

14 Experts available now in Live!

Get 1:1 Help Now