//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Sample1u.h" #include "Acces32.h" #include //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TSample1Form *Sample1Form; Word Address; TPanel *PortPanels[3]; //--------------------------------------------------------------------------- __fastcall TSample1Form::TSample1Form(TComponent* Owner) : TForm(Owner) { getDeviceInfo(); } //--------------------------------------------------------------------------- void __fastcall TSample1Form::ExitButtonClick(TObject *Sender) { exit(0); } //--------------------------------------------------------------------------- void __fastcall TSample1Form::TestButtonClick(TObject *Sender) { if (TestTimer->Enabled) { TestTimer->Enabled = false; TestButton->Caption = "Start Test"; BaseEdit->Enabled = true; } else { PortPanels[0]=Port0Text; PortPanels[1]=Port1Text; PortPanels[2]=Port2Text; Address = StrToInt("0x"+BaseEdit->Text); TestTimer->Enabled = true; TestButton->Caption = "Abort Test"; BaseEdit->Enabled = false; } } //--------------------------------------------------------------------------- void __fastcall TSample1Form::TestTimerTimer(TObject *Sender) { int port, i; unsigned output,mask; unsigned char ofs[] = { 0,1,2,4,5,6 }; // Table of offsets to input registers static unsigned data = 1; PortPanels[0]->Caption = ""; PortPanels[1]->Caption = ""; PortPanels[2]->Caption = ""; for (port = 0; port <= 2; port++) { // Read the first 8 input channels of current port // data = InPortB(Address + ofs[2*port])*256; // data += InPortB(Address + ofs[(2*port)+1]); OutPortB(Address + ofs[2*port], data); OutPortB(Address + ofs[2 * port + 1], data); output = data | (data << 8); // Check the status of each bit field and display result mask = 1; for (i = 0; i < 16; i++) { if (mask & output) PortPanels[port]->Caption = "1" + PortPanels[port]->Caption; else PortPanels[port]->Caption = "0" + PortPanels[port]->Caption; mask <<= 1; } // end for i } // end for port data <<= 1; if (data > 0x80) data = 1; } // end TestTimerTimer //--------------------------------------------------------------------------- void __fastcall TSample1Form::FormCreate(TObject *Sender) { if (InPortB(0x61) == 0xAA55) { Application->MessageBox("ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.", "Warning", IDOK); } } //--------------------------------------------------------------------------- void __fastcall TSample1Form::getDeviceInfo() { TRegistry *Reg; TPCI_COMMON_CONFIG buf[64]; int cardsListed; numCards = 0; Reg = new TRegistry; Reg->RootKey = HKEY_LOCAL_MACHINE; Reg->OpenKey(RegKey, true); cardsListed = Reg->ReadInteger("NumDevices"); if (cardsListed) Reg->ReadBinaryData("PCICommonConfig", buf, sizeof(TPCI_COMMON_CONFIG) * cardsListed); for (int count = 0; count < cardsListed; count++) { if (buf[count].VendorID == 0x494F && buf[count].DeviceID == 0x0520) { deviceList->Items->Add(IntToStr(numCards) + ": PCI-IDO-48"); addresses[numCards] = buf[count].BaseAddresses[2] & 0xFFF8; numCards++; } } if (numCards == 0) BaseEdit->ReadOnly = true; deviceList->Items->Add("ISA-IDO-48 (Enter Base Address below)"); addresses[numCards] = 0x300; numCards++; Address = addresses[0]; deviceList->ItemIndex = 0; BaseEdit->Text = IntToHex(addresses[0], 4); delete Reg; } //--------------------------------------------------------------------------- void __fastcall TSample1Form::deviceListChange(TObject *Sender) { if (deviceList->ItemIndex == numCards - 1) //isa selected BaseEdit->ReadOnly = false; else BaseEdit->ReadOnly = true; BaseEdit->Text = IntToHex(addresses[deviceList->ItemIndex], 4); } //---------------------------------------------------------------------------