• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 613
  • Last Modified:

Parallel port Interfacing

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
ryan_sabarre
Asked:
ryan_sabarre
1 Solution
 
ryan_sabarreAuthor Commented:
help me please
0
 
JaccoCommented:
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
Independent Software Vendors: 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!

 
CesarioCommented:
reading
0
 
VSFCommented:
Listenning!
VSF
0
 
GwenaCommented:
:-)
0
 
chunky1Commented:
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
 
iviCommented:
>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
 
GwenaCommented:
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
 
GwenaCommented:
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
 
ryan_sabarreAuthor Commented:
Thank you so much and
Gwena thanks for some info..
0
 
multyCommented:
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
 
cuimengCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now