unit Sample1u; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, ComCtrls, StdCtrls; type TSample1Form = class(TForm) CardName: TLabel; Memo1: TMemo; ExitButton: TButton; ISAPanel: TGroupBox; HexLabel: TLabel; BaseEdit: TEdit; TestButton: TButton; ChannelBox: TGroupBox; Label2: TLabel; Label3: TLabel; Label4: TLabel; Port0Text: TPanel; Port1Text: TPanel; Port2Text: TPanel; TestTimer: TTimer; deviceList: TComboBox; procedure ExitButtonClick(Sender: TObject); procedure TestButtonClick(Sender: TObject); procedure TestTimerTimer(Sender: TObject); procedure FormCreate(Sender: TObject); procedure GetDeviceInfo(); procedure deviceListChange(Sender: TObject); private { Private declarations } public { Public declarations } data : word; //what is being written out to each port end; var Sample1Form: TSample1Form; Address : Word; PortPanels : array[0..2] of ^TPanel; addresses : array[0..63] of DWORD; numCards : integer; implementation uses ACCES32, registry; {$R *.DFM} procedure TSample1Form.ExitButtonClick(Sender: TObject); begin Close(); end; procedure TSample1Form.TestButtonClick(Sender: TObject); begin if (TestTimer.Enabled) then begin TestTimer.Enabled := false; TestButton.Caption := 'Start Test'; BaseEdit.Enabled := true; end // end if else begin PortPanels[0] := @Port0Text; PortPanels[1] := @Port1Text; PortPanels[2] := @Port2Text; Address := StrToInt('$'+BaseEdit.Text); TestTimer.Enabled := true; TestButton.Caption := 'Abort Test'; BaseEdit.Enabled := false; end; // end else end; // end TestButtonClick procedure TSample1Form.TestTimerTimer(Sender: TObject); var port, i : integer; output, mask : Word; const ofs : array[0..5] of integer = ( 0,1,2,4,5,6 ); // Table of offsets to input registers begin PortPanels[0].Caption := ''; PortPanels[1].Caption := ''; PortPanels[2].Caption := ''; for port := 0 to 2 do begin // Read the first 8 input channels of current port // data := InPortB(Address + ofs[2*port])*256; // data := data + InPortB(Address + ofs[(2*port)+1]); OutPortB(Address + ofs[2*port], data); OutPortB(Address + ofs[2*port + 1], data); output := data or (data shl 8); // Check the status of each bit field and display result mask := 1; for i := 0 to 15 do begin if (mask and output) <> 0 then PortPanels[port].Caption := '1' + PortPanels[port].Caption else PortPanels[port].Caption := '0' + PortPanels[port].Caption; mask := mask SHL 1; end; // end for i end; // end for port data := data shl 1; if data > $80 then data := 1 ; end; procedure TSample1Form.FormCreate(Sender: TObject); begin 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; GetDeviceInfo; data := 1; end; procedure TSample1Form.GetDeviceInfo(); var Configs : array [0..63] of TPCI_COMMON_CONFIG; Registry : TRegistry; CardsListed : Integer; //the number of cards found in the registry I : Integer; const RegKey = 'System\CurrentControlSet\Services\NTioPCI\Parameters'; begin //check for PCI devices, and if there isn't one then set up for //ISA instead numCards := 0; Registry := TRegistry.Create; Registry.RootKey := HKEY_LOCAL_MACHINE; Registry.OpenKey(RegKey, True); CardsListed := Registry.ReadInteger('NumDevices'); if CardsListed > 0 then Registry.ReadBinaryData('PCICommonConfig', Configs, (sizeof(TPCI_COMMON_CONFIG)*CardsListed)) ; Registry.Free; for I := 0 to CardsListed - 1 do begin with Configs[I] do begin if (VendorID = $494F) and (DeviceID = $0520) then begin addresses[numCards] := BaseAddresses[2]and $FFF8; DeviceList.Items.Add(IntToStr(numCards) + ': PCI-IDO-48'); inc(numCards); end; end; end; if numCards > 0 then BaseEdit.ReadOnly := true ; DeviceList.Items.Add('ISA-IDO-48 (Enter Base Address below)'); addresses[numCards] := $300; inc (numCards); address := addresses[0]; BaseEdit.Text := IntToHex(address, 4); DeviceList.ItemIndex := 0; end; procedure TSample1Form.deviceListChange(Sender: TObject); begin if devicelist.ItemIndex = numCards - 1 then //isa option selected BaseEdit.ReadOnly := false else BaseEdit.ReadOnly := true ; address := addresses[deviceList.ItemIndex]; BaseEdit.Text := IntToHex(address, 4); end; end.