Evo da ja malo pomognem ljudima, nasao sam neki primer za komandu LPT portom iz Delphija.
Nisam mnogo kopao na kojem OS-u radi (mislim da radi i na XP-u ali na 98-ci 100% radi)
Glavna komponenta je SmallPort driver (njega vec potrazite na netu) a ovde vam stavljam jedan kod da vam cisto da ideju sta gde i kako treba.
Naravno ovaj kod nece raditi bez SmallPort drivera.
HWUnit.pas
Code:
unit hwunit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, SmallPort, Spin;
type
TForm1 = class(TForm)
GroupBox3: TGroupBox;
Button5: TButton;
GroupBox4: TGroupBox;
Button6: TButton;
GroupBox5: TGroupBox;
Bit1: TCheckBox;
Bit0: TCheckBox;
Bit2: TCheckBox;
Bit3: TCheckBox;
Bit4: TCheckBox;
Bit5: TCheckBox;
Bit6: TCheckBox;
Bit7: TCheckBox;
GroupBox6: TGroupBox;
Error: TCheckBox;
Select: TCheckBox;
PE: TCheckBox;
Ask: TCheckBox;
Busy: TCheckBox;
RadioGroup1: TRadioGroup;
LPT1: TRadioButton;
LPT2: TRadioButton;
Button8: TButton;
GroupBox7: TGroupBox;
Edit1: TEdit;
GroupBox8: TGroupBox;
Button7: TButton;
Label2: TLabel;
SpinEdit2: TSpinEdit;
GroupBox9: TGroupBox;
Button1: TButton;
GroupBox1: TGroupBox;
Button9: TButton;
SmallPort1: TSmallPort;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
BASE: WORD;
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
if SmallPort1.Opened then
begin SmallPort1.Opened:=false; Button1.Caption:='Open Driver' end
else SmallPort1.Opened:=true;
if SmallPort1.Opened then Button1.Caption:='Close Driver';
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
SmallPort1.Sound(1100,300);
SmallPort1.Sound(1247,300);
SmallPort1.Sound(1393,300);
SmallPort1.Sound(1466,300);
SmallPort1.Sound(1613,300);
SmallPort1.Sound(1760,300);
SmallPort1.Sound(2052,300);
end;
procedure TForm1.Button6Click(Sender: TObject);
var b,b1: BYTE;
begin
if SmallPort1.Opened then
begin
if LPT1.Checked then BASE:=$378 else BASE:=278;
b:=SmallPort1.Port[BASE];
b1:=SmallPort1.Port[BASE+1];
if(b1 and $08)<>0 then Error.Checked:=true else Error.Checked:=false;
if(b1 and $10)<>0 then Select.Checked:=true else Select.Checked:=false;
if(b1 and $20)<>0 then PE.Checked:=true else PE.Checked:=false;
if(b1 and $40)<>0 then ASK.Checked:=true else ASK.Checked:=false;
if(b1 and $80)<>0 then BUSY.Checked:=true else BUSY.Checked:=false;
if(b and $01)<>0 then Bit0.Checked:=true else Bit0.Checked:=false;
if(b and $02)<>0 then Bit1.Checked:=true else Bit1.Checked:=false;
if(b and $04)<>0 then Bit2.Checked:=true else Bit2.Checked:=false;
if(b and $08)<>0 then Bit3.Checked:=true else Bit3.Checked:=false;
if(b and $10)<>0 then Bit4.Checked:=true else Bit4.Checked:=false;
if(b and $20)<>0 then Bit5.Checked:=true else Bit5.Checked:=false;
if(b and $40)<>0 then Bit6.Checked:=true else Bit6.Checked:=false;
if(b and $80)<>0 then Bit7.Checked:=true else Bit7.Checked:=false;
end;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
if SmallPort1.Opened then
begin
if LPT1.Checked then BASE:=$378 else BASE:=278;
SmallPort1.Port[$378]:=SpinEdit2.Value;
end;
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
SmallPort1.Sound(StrToIntDef(Edit1.Text,440),200);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SmallPort1.Opened:=false;
end;
end.