unit iiro8u; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, Registry, ExtCtrls ; type TMainFrm = class(TForm) Label5: TLabel; GroupBox1: TGroupBox; ExitButton: TBitBtn; Memo1: TMemo; CardName: TLabel; BeginSample: TButton; RunTimer: TTimer; RelayOut: TPanel; RelayRead: TPanel; OptoIn: TPanel; Label2: TLabel; Label3: TLabel; Label4: TLabel; IsaLabel: TLabel; IsaEdit: TEdit; AddressLabel: TLabel; AddressLabel1: TLabel; procedure ExitButtonClick(Sender: TObject); procedure FormCreate(Sender: TObject); // procedure AddressListChange(Sender: TObject); procedure RunTimerTimer(Sender: TObject); procedure BeginSampleClick(Sender: TObject); procedure FormActivate(Sender: TObject); private { Private declarations } DriverRegistry:TRegistry; public { Public declarations } end; const // myKey = 'System\CurrentControlSet\Services\NTioPCI\Parameters'; myKey = 'Software\PCIFind\NTioPCI\Parameters'; var MainFrm: TMainFrm; Address : WORD; RunFlag:Boolean; implementation uses ACCES32; type TPCI_COMMON_CONFIG = record VendorID : word; DeviceID : word; Command : word; Status : word; RevisionID : byte; ProgIf : byte; SubClass : byte; BaseClass : byte; CacheLineSize : byte; LatencyTimer : byte; HeaderType : byte; BIST : byte; BaseAddresses : Array[0..5] of longint; Reserved1 : Array[0..1] of longint; RomBaseAddress : longint; Reserved2 : Array[0..1] of longint; InterruptLine : byte; InterruptPin : byte; MinimumGrant : byte; MaximumLatency : byte; end; //global variables for internal use var buf: array [0..63] of TPCI_COMMON_CONFIG; Siz: Integer = 8; {$R *.DFM} procedure TMainFrm.FormCreate(Sender: TObject); var num, i: Integer; found: Boolean; begin found := false; DriverRegistry:=TRegistry.Create; DriverRegistry.RootKey:=HKEY_LOCAL_MACHINE; RunFlag:=True; if (InPortB($61) = $AA55) then begin Application.MessageBox('ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.', 'Warning', IDOK); end; try DriverRegistry.OpenKey(MyKey, False); num := DriverRegistry.ReadInteger('NumDevices'); except num := 0; end; if (num > 0) then DriverRegistry.ReadBinaryData('PCICommonConfig',buf,num*sizeof(TPCI_COMMON_CONFIG)); for i := 0 to num-1 do begin if found then Break; with Buf[i] do begin case (DeviceID) of $0F00:begin CardName.Caption:='PCI-IIRO-8 Digital Input/Relay Output Card'; AddressLabel.Caption:='$'+IntToHex(BaseAddresses[2] AND $FFFE,4); Label5.Caption:='Win95/NT Sample'; Siz := 8; found := true; end; $0F08:begin CardName.Caption:='PCI-IIRO-16 Digital Input/Relay Output Card'; AddressLabel.Caption:='$'+IntToHex(BaseAddresses[2] AND $FFFE,4); Label5.Caption:='Win95/NT Sample'; Siz := 16; found := true; end; $0DC8:begin CardName.Caption:='PCI-IDIO-16 Solid-State Input/Output Card'; AddressLabel.Caption:='$'+IntToHex(BaseAddresses[2] AND $FFFE,4); Label5.Caption:='Win95/NT Sample'; Siz := 16; found := true; end; end;{case} end;{with} end;{for} if found then begin RelayOut.Caption := StringOfChar('0', Siz); RelayRead.Caption := StringOfChar('0', Siz); OptoIn.Caption := StringOfChar('0', Siz); end else begin Label5.Caption:='Win95/NT IIRO-8/16 Sample'; CardName.Caption:='No Card Found In Registry'; Memo1.Lines.Clear; Memo1.Lines.Append('No Card Found In Registry.'); Memo1.Lines.Append('This may mean an ISA IIRO-8 is installed, no card is installed, or that NTioPCI.SYS is not installed.'); Memo1.Lines.Append('If you have an ISA IIRO-8 card installed, you may continue running the sample ' + 'by entering the card''s Base Address in the edit box above and continuing as normal.'); Memo1.Lines.Append('If you have a PCI card installed, please make sure you have run PCIFind.EXE.'); IsaEdit.Visible := true; IsaLabel.Visible := true; AddressLabel.visible := false; AddressLabel1.visible := false; RunFlag:=False; end; if RunFlag then Address:=StrToInt(AddressLabel.Caption); DriverRegistry.Free; end; procedure TMainFrm.ExitButtonClick(Sender: TObject); begin Close; end; procedure TMainFrm.RunTimerTimer(Sender: TObject); const value:array[0..2] of LongWord=(0,0,0); i:Integer=0; var j:integer; msg: String; begin value[0]:=1 shl i; OutPortB(Address,value[0]); value[1] := InPortB(Address); value[2] := InPortB(Address+1); if Siz > 8 then begin OutPortB(Address + 4, value[0] shr 8); value[1] := value[1] + InPortB(Address + 4) shl 8; value[2] := value[2] + InPortB(Address + 4 + 1) shl 8; end; inc(i); i := i mod Siz; msg:=StringOfChar('0', Siz); for j:=0 to Siz-1 do msg[Siz-j]:=chr(ord((value[0] and (1 shl j))>0)+$30); RelayOut.Caption := msg; for j:=0 to Siz-1 do msg[Siz-j]:=chr(ord((value[1] and (1 shl j))>0)+$30); RelayRead.Caption := msg; for j:=0 to Siz-1 do msg[Siz-j]:=chr(ord((value[2] and (1 shl j))>0)+$30); OptoIn.Caption := msg; end; procedure TMainFrm.BeginSampleClick(Sender: TObject); begin if not RunFlag then Address := StrToInt('$'+IsaEdit.Text); if RunTimer.Enabled=True then Begin RunTimer.Enabled:=False; BeginSample.Caption:='Perform I/O'; end else begin RunTimer.Enabled:=True; BeginSample.Caption:='Stop I/O'; end; end; procedure TMainFrm.FormActivate(Sender: TObject); begin if not RunFlag then FocusControl(IsaEdit); end; END.