unit Main;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,IniFiles,
  Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Menus, Spin, Grids,
  ComCtrls, Tabnotbk, PORT_32;

type
  TMainForm = class(TForm)
    BitBtn3: TBitBtn;
    B_Open: TButton;
    Timer1: TTimer;
    Panel1: TPanel;
    Label4: TLabel;
    Label3: TLabel;
    Label18: TLabel;
    B_CloseDriver: TButton;
    HwCtrl: TVicPort;
    GroupBox3: TGroupBox;
    Label19: TLabel;
    L_LPTs: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    L_Base: TLabel;
    SpinLPT: TSpinEdit;
    G_Read: TGroupBox;
    RPin1: TCheckBox;
    RPin2: TCheckBox;
    RPin3: TCheckBox;
    RPin5: TCheckBox;
    RPin11: TCheckBox;
    RPin12: TCheckBox;
    RPin13: TCheckBox;
    RPin15: TCheckBox;
    GroupBox1: TGroupBox;
    WPin2: TCheckBox;
    WPin3: TCheckBox;
    WPin4: TCheckBox;
    WPin5: TCheckBox;
    WPin6: TCheckBox;
    WPin7: TCheckBox;
    WPin8: TCheckBox;
    WPin9: TCheckBox;
    Memo1: TMemo;
    procedure B_OpenClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure WPin1Click(Sender: TObject);
    procedure C_InitClick(Sender: TObject);
    procedure B_CloseDriverClick(Sender: TObject);
    procedure SpinLPTChange(Sender: TObject);
    procedure C_MasterClick(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
  end;

const MaxPorts = 8;

var
  MainForm: TMainForm;

var CPinRead,CPinWrite : array[1..25] of TCheckBox;



implementation




{$R *.DFM}


procedure ShowButtons;
var nPin : Byte;
    s    : String;
begin
  with MainForm,HwCtrl do
  begin
   SpinLPT.Enabled:=ActiveHW;
   SpinLPT.MaxValue:=LPTNumPorts;
   L_LPTs.caption:=IntToStr(LPTNumPorts);
   L_BASE.caption:=IntToHex(LPTBasePort,3)+'h';
   B_Open.Enabled:=not ActiveHW;
   B_CloseDriver.Enabled := ActiveHW;

   if not ActiveHW then
     begin
          for nPin:=1 to 5 do
          begin
               CPinRead[nPin].Checked:=FALSE;
               CPinRead[nPin].enabled:=FALSE;
          end;

          for nPin:=11 to 15 do
          begin
               CPinRead[nPin].Checked:=FALSE;
               CPinRead[nPin].enabled:=FALSE;
          end;
          For nPin:=2 to 9 do
          begin
               CPinWrite[nPin].Checked:=FALSE;
               CPinWrite[nPin].enabled:=false;
          end;
     
   end
   else
   begin
          for nPin:=1 to 5 do
          begin
               CPinRead[nPin].enabled:=TRUE;
          end;

          for nPin:=11 to 15 do
          begin
               CPinRead[nPin].enabled:=TRUE;
          end;

          For nPin:=2 to 9 do
          begin
               CPinWrite[nPin].enabled:=TRUE;
          end;



  end;
end;
end;

procedure TMainForm.B_OpenClick(Sender: TObject);
begin
  HwCtrl.OpenDriver;
  if not HwCtrl.ActiveHW then
  begin
    MessageBeep(0);
    Application.MessageBox('The driver not found',
                           ' Warning! ',mb_OK or mb_ICONHAND);
  end
  else begin
         Timer1.Enabled:=TRUE;

       end;
  ShowButtons;
end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  HwCtrl.CloseDriver;
  ShowButtons;
end;

procedure TMainForm.FormActivate(Sender: TObject);
var i         : Word;
begin

 with HWCtrl do
 begin
   CPinRead[1]:=rPin1;
   CPinRead[ 2]:=RPin2;    CPinWrite[ 2]:=WPin2;
   CPinRead[ 3]:=RPin3;    CPinWrite[ 3]:=WPin3;
   CPinRead[ 4]:=RPin3;  CPinWrite[ 4]:=WPin4;
   CPinRead[ 5]:=RPin5;    CPinWrite[ 5]:=WPin5;
   CPinWrite[ 6]:=WPin6;
   CPinWrite[ 7]:=WPin7;
   CPinWrite[ 8]:=WPin8;
   CPinWrite[ 9]:=WPin9;
   CPinRead[11]:=RPin11;
   CPinRead[12]:=RPin12;
   CPinRead[13]:=RPin13;
   CPinRead[14]:=RPin13;
   CPinRead[15]:=RPin15;   


  if (GetVersion() and $80000000)<>0 then
     Label3.caption:='Windows 95/98'
  else
     Label3.caption:='Windows NT';


 end;
 ShowButtons;
end;


procedure TMainForm.Timer1Timer(Sender: TObject);
var nPin : Byte;
begin
  with HWCtrl do
  begin

    if ActiveHW  then
    begin
      {select line for digital inputs}
      Pin[16]:=false;
      for nPin:=11 to 15 do
        CPinRead[nPin].Checked:=Pin[nPin];
      {other four inputs}
      Pin[16]:=true;
      for nPin:=11 to 15 do
        CPinRead[nPin-10].Checked:=Pin[nPin];

    end;
  end;
end;


procedure TMainForm.WPin1Click(Sender: TObject);
var nPin : Byte;
begin
  HwCtrl.Pin[1]:=false;
  {write to LPT's data pins}
  for nPin:=2 to 9 do
     HwCtrl.Pin[nPin]:=BOOL(CPinWrite[nPin].Checked);
  {toggle strobe to latch data lines}
  HwCtrl.Pin[1]:=true;
  HwCtrl.Pin[1]:=false;

end;

procedure TMainForm.C_InitClick(Sender: TObject);
begin
  HwCtrl.LPTInit;
end;

procedure TMainForm.B_CloseDriverClick(Sender: TObject);
begin
  Timer1.Enabled:=FALSE;
  HwCtrl.CloseDriver;
  ShowButtons;
end;

procedure TMainForm.SpinLPTChange(Sender: TObject);
begin
  with HwCtrl do
  begin
    LPTNumber:=SpinLPT.Value;
  end;
  ShowButtons;
end;


procedure TMainForm.C_MasterClick(Sender: TObject);
begin
  ShowButtons;
end;

procedure TMainForm.BitBtn3Click(Sender: TObject);
begin
close;
end;

initialization

end.
