unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ImgList; type TForm1 = class(TForm) ImageList1: TImageList; outImage0: TImage; outImage1: TImage; outImage2: TImage; outImage3: TImage; outImage4: TImage; outImage5: TImage; outImage6: TImage; outImage7: TImage; inImage0: TImage; DeviceList: TComboBox; Label1: TLabel; Label2: TLabel; addrEdit: TEdit; inImage1: TImage; inImage2: TImage; inImage3: TImage; inImage4: TImage; inImage5: TImage; inImage6: TImage; inImage7: TImage; Timer1: TTimer; goBTN: TButton; Memo1: TMemo; GroupBox1: TGroupBox; Image1: TImage; Label3: TLabel; Label4: TLabel; Image2: TImage; Label5: TLabel; Label6: TLabel; procedure FormCreate(Sender: TObject); procedure outImagesClick(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure goBTNClick(Sender: TObject); procedure DeviceListChange(Sender: TObject); private { Private declarations } procedure GetDeviceInfo (); public { Public declarations } end; type CardInfo = record Name : AnsiString; BaseAddress : DWORD; end; var Form1: TForm1; closedBmp, openBmp : TBitmap; inputImages, outputImages : array[0..7] of TImage; inByte, outByte : Byte; numCards : Integer; Cards : array [0..63] of CardInfo; BaseAddr : DWORD; //the currently active base address implementation {$R *.DFM} uses ACCES32, registry; procedure TForm1.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 = $0f01) then begin Cards[numCards].BaseAddress := BaseAddresses[2] and $FFF8; Cards[numCards].Name := IntToStr(numCards) + ': LPCI-IIRO-8'; DeviceList.Items.Add(Cards[numCards].name); inc(numCards); end; end; end; if numCards > 0 then addrEdit.ReadOnly := true ; DeviceList.Items.Add('104-IIRO-8 (Enter Base Address below)'); Cards[numCards].BaseAddress := $300; inc (numCards); BaseAddr := Cards[0].BaseAddress; addrEdit.Text := IntToHex(BaseAddr, 4); DeviceList.ItemIndex := 0; end; procedure TForm1.FormCreate(Sender: TObject); var I : Integer; begin openBmp := TBitmap.Create; closedBmp := TBitmap.Create; ImageList1.GetBitmap(0, openBmp); ImageList1.GetBitmap(1, closedBmp); inputImages[0] := inImage0; inputImages[1] := inImage1; inputImages[2] := inImage2; inputImages[3] := inImage3; inputImages[4] := inImage4; inputImages[5] := inImage5; inputImages[6] := inImage6; inputImages[7] := inImage7; outputImages[0] := outImage0; outputImages[1] := outImage1; outputImages[2] := outImage2; outputImages[3] := outImage3; outputImages[4] := outImage4; outputImages[5] := outImage5; outputImages[6] := outImage6; outputImages[7] := outImage7; for I := 0 to 7 do begin inputImages[I].Picture.Bitmap := openBmp; outputImages[I].Picture.Bitmap := openBmp; end; inByte := 0; outByte := 0; GetDeviceInfo; end; procedure TForm1.outImagesClick(Sender: TObject); var Image : TImage; begin Image := Sender as TImage; outByte := outByte xor (1 shl Image.Tag); //the tag is set to the //bit associated with the //image if ((outByte shr image.Tag) and 1) = 1 then outputImages[Image.Tag].Picture.Bitmap := closedBmp else outputImages[Image.Tag].Picture.Bitmap := openBmp ; OutPortB(BaseAddr, outByte); end; procedure TForm1.Timer1Timer(Sender: TObject); var I : Integer; begin inByte := InPortB(BaseAddr + $1); for I := 0 to 7 do begin if ((inByte shr I) and 1) = 1 then inputImages[I].Picture.Bitmap := closedBmp else inputImages[I].Picture.Bitmap := openBmp ; end; end; procedure TForm1.goBTNClick(Sender: TObject); begin if goBTN.Caption = 'GO' then begin if DeviceList.Items.Count - 1 = DeviceList.ItemIndex then begin BaseAddr := StrToInt('$' + addrEdit.Text); cards[DeviceList.ItemIndex].BaseAddress := BaseAddr; end; goBTN.Caption := 'STOP'; DeviceList.Enabled := False; end else begin goBTN.Caption := 'GO'; DeviceList.Enabled := True; end; Timer1.Enabled := not Timer1.Enabled end; procedure TForm1.DeviceListChange(Sender: TObject); begin if DeviceList.Items.Count - 1 = DeviceList.ItemIndex then //the ISA card option is selected addrEdit.ReadOnly := false else addrEdit.ReadOnly := true ; BaseAddr := Cards[DeviceList.ItemIndex].BaseAddress; addrEdit.Text := IntToHex(BaseAddr, 4); end; end.