//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { closedBmp = new Graphics::TBitmap; openBmp = new Graphics::TBitmap; ImageList1 ->GetBitmap(0, openBmp); ImageList1 ->GetBitmap(1, closedBmp); inImages[0] = inImage0; inImages[1] = inImage1; inImages[2] = inImage2; inImages[3] = inImage3; inImages[4] = inImage4; inImages[5] = inImage5; inImages[6] = inImage6; inImages[7] = inImage7; outImages[0] = outImage0; outImages[1] = outImage1; outImages[2] = outImage2; outImages[3] = outImage3; outImages[4] = outImage4; outImages[5] = outImage5; outImages[6] = outImage6; outImages[7] = outImage7; for (int count = 0; count < 8; count++) { inImages[count]->Picture->Bitmap = openBmp; outImages[count]->Picture->Bitmap = openBmp; } inByte = outByte = 0; getDeviceInfo(); } //--------------------------------------------------------------------------- void __fastcall TForm1::outImagesClick(TObject *Sender) { TImage *Image; Image = (TImage *)Sender; outByte ^= 1 << Image->Tag; if ((outByte >> Image->Tag) & 1) outImages[Image->Tag]->Picture->Bitmap = closedBmp; else outImages[Image->Tag]->Picture->Bitmap = openBmp; OutPortB(BaseAddress, outByte); } //--------------------------------------------------------------------------- void __fastcall TForm1::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 == 0x0f01) { cards[numCards].Name = IntToStr(numCards) + ": LPCI-IIRO-8"; DeviceList->Items->Add(cards[numCards].Name); cards[numCards].Address = buf[count].BaseAddresses[2] & 0xFFF8; numCards++; } } if (numCards != 0) addrEdit->ReadOnly = true; cards[numCards].Name = "104-IIRO-8 (Enter Base Address below)"; DeviceList->Items->Add(cards[numCards].Name); cards[numCards].Address = 0x300; BaseAddress = cards[numCards].Address; numCards++; DeviceList->ItemIndex = 0; DeviceList->OnChange(NULL); delete Reg; } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { inByte = InPortB(BaseAddress + 1); for (int count = 0; count < 8; count ++) { if (((inByte >> count) & 1) == 1) inImages[count]->Picture->Bitmap = closedBmp; else inImages[count]->Picture->Bitmap = openBmp; } } //--------------------------------------------------------------------------- void __fastcall TForm1::goBTNClick(TObject *Sender) { if (goBTN ->Caption == "GO") { if (DeviceList->Items->Count - 1 == DeviceList->ItemIndex) { BaseAddress = StrToInt("0x" + addrEdit->Text); cards[DeviceList->ItemIndex].Address = BaseAddress; } goBTN->Caption = "STOP"; DeviceList->Enabled = false; } else { goBTN->Caption = "GO"; DeviceList->Enabled = true; } Timer1->Enabled = !Timer1->Enabled; for (int count = 0; count < 8; count++) { outImages[count]->Enabled = Timer1->Enabled; } } //--------------------------------------------------------------------------- void __fastcall TForm1::DeviceListChange(TObject *Sender) { if (DeviceList->Items->Count - 1 == DeviceList->ItemIndex) //the ISA card option is selected addrEdit->ReadOnly = false; else addrEdit->ReadOnly = true; BaseAddress = cards[DeviceList->ItemIndex].Address; addrEdit->Text = IntToHex(int(BaseAddress), 4); } //---------------------------------------------------------------------------