Another way of controlling LPT port under Windows 2000 and XP using Delphi language. In this case library inpout32.dll is used which allows controlling LPT port registers.
Ready project for Borland Delphi 7.0 you can download here: Project Files<187.5kB>
And now how to do this from beginning. Start Borland Delphi 7.0 and make simple form where you can enter Data to be sent to port, Port Address, buttons for writing to and reading from port.
If you are familiar with building forms this should be ease task.
OK now lets start programming. First of all wee need somehow to include inpout32.dll in to the project. For this Delphi has several ways, but lets stay to the easiest one when library is in same directory, where project is. Then in header in section uses we have to place function prototypes Out32 and Inp32 with special compiler directive external, saying where to find this finction.
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; function Inp32(PortAdr: word): byte; stdcall; external 'inpout32.dll'; function Out32(PortAdr: word; Data: byte): byte; stdcall; external 'inpout32.dll';
Then lets go to the button methods. For this double click on button in form and you will be directed to editor. Firs o all lets work with wiring to port function. Place data to the variables Port and Data from text fields convert them from text to numerical data and then call function Out32() with these parameters.
procedure TForm1.Button1Click(Sender: TObject); var Port: word; Data: Byte; begin Data:= StrToInt(Edit1.Text); Port:= StrToInt(Edit2.Text); Out32(Port, Data); end;
Same way we have to deal with reading. Port Address is taken from Port Address text field. This is where data will be read from. Then call function Inp32() with port number and output received data to the window.
procedure TForm1.Button2Click(Sender: TObject); var Port: word; Data: Byte; begin Port:= StrToInt(Edit3.Text); Data:= Inp32(Port); MessageDlg('Value: '+ IntToStr(Data), mtInformation, [mbOK], 0); end;
Compile program and start. Try to write to DATA register of LPT port number 0. For this port address will be 888(or hexadecimal $378). Press button and if you have some tester connected to LPT you will se the results. Same way you can work with reading.