Solved

Parallel port Interfacing

Posted on 2001-08-19
13
589 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

10 Experts available now in Live!

Get 1:1 Help Now