Another way of controlling the LPT port under Windows 2000 and XP is using the Delphi language. In this case, library, inpout32.dll, is used, which allows controlling LPT port registers.
And now how to do this from the beginning. Start Borland Delphi 7.0 and make a simple form where you can enter Data to be sent to the port, Port Address, buttons for writing to and reading from a port.
If you are familiar with building forms this should be ease task.
Okay, now let’s start programming; first of all wee need to include inpout32.dll in the project. For this, Delphi has several ways, but let’s stay to the easiest one when the library is in the same directory, where the project is. The header in section uses we have to place function prototypes Out32 and Inp32 with special compiler directive external, saying where to find this function.
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 let’s go to the button methods. For this, double click on the button in the form, and you will be directed to the editor. First o all, let’s 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;
The same way we have to deal with reading. Port Address is taken from the 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 the program and start. Try to write to the DATA register of LPT port number 0. For this port, the address will be 888(or hexadecimal $378). Press the button, and if you have some tester connected to LPT, you will see the results. The same way you can work with reading.