Monday, August 30, 2010

LPT Port Interface with Delphi 7

The following code is for data retrieval through the LPT port using Delphi 7 and components of the program interface inpout32.dll LPT. Download inpout32.dll and saved in the same folder with the exe application

unit Unit1;


interface


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

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
Port: word;
Data: Byte;
begin
Data:= StrToInt(Edit1.Text);
Port:= StrToInt(Edit2.Text);
Out32(Port, Data);
end;

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;
end.

download complete Delphi 7 code

No comments:

Post a Comment