//--------------------------------------------------------------------------- #include #pragma hdrstop #include #include "iirou.h" #include "ACCES32.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; TPCI_COMMON_CONFIG buf[64]; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { int num, i; bool found; found = false; 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); } DriverRegistry = new TRegistry; DriverRegistry->RootKey = HKEY_LOCAL_MACHINE; RunFlag = True; try { DriverRegistry->OpenKey(MyKey, false); num = DriverRegistry->ReadInteger("NumDevices"); } catch ( ... ) { num = 0; } if (num > 0) DriverRegistry->ReadBinaryData("PCICommonConfig",buf,num*sizeof(TPCI_COMMON_CONFIG)); for (i=0; iCaption="PCI-IIRO-8 Digital Input/Relay Output Card"; Label5->Caption = "Win95/NT Sample"; AddressLabel->Caption = IntToHex((int)(buf[i].BaseAddresses[2]) & 0xFFFE,4); found = true; break; case 0x0F08: CardName->Caption="PCI-IIRO-16 Digital Input/Relay Output Card"; Label5->Caption = "Win95/NT Sample"; AddressLabel->Caption = IntToHex((int)(buf[i].BaseAddresses[2]) & 0xFFFE,4); found = true; break; case 0x0DC8: CardName->Caption="PCI-IDIO-16 Solid-State Input/Output Card"; Label5->Caption = "Win95/NT Sample"; AddressLabel->Caption = IntToHex((int)(buf[i].BaseAddresses[2]) & 0xFFFE,4); found = true; break; case 0x0F01: CardName->Caption="PCIe-IIRO-8 Digital Input/Relay Output Card"; Label5->Caption = "Win95/NT Sample"; AddressLabel->Caption = IntToHex((int)(buf[i].BaseAddresses[2]) & 0xFFFE,4); found = true; break; case 0x0F09: CardName->Caption="PCIe-IIRO-16 Digital Input/Relay Output Card"; Label5->Caption = "Win95/NT Sample"; AddressLabel->Caption = IntToHex((int)(buf[i].BaseAddresses[2]) & 0xFFFE,4); found = true; break; } } if (!found) { Label5->Caption="Win95/NT IIRO-8/16 Sample"; CardName->Caption = "No Card Found In Registry"; Memo1->Lines->Clear(); Memo1->Lines->Append("No PCI Cards Found."); 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; Label5->Caption = "Win9x/NT IIRO-8/16 Sample"; } if (RunFlag) Address = StrToInt("0x"+AddressLabel->Caption); DriverRegistry->Free(); } //--------------------------------------------------------------------------- void __fastcall TForm1::UpdateDriverRegistry(void) { unsigned long TypeValue, StartValue, ErrorControlValue; DriverRegistry = new TRegistry; DriverRegistry->RootKey = HKEY_LOCAL_MACHINE; DriverRegistry->OpenKey(MyKey, true); TypeValue = 1; DriverRegistry->WriteInteger("Type", TypeValue); StartValue = 2; DriverRegistry->WriteInteger("Start", StartValue); ErrorControlValue = 1; DriverRegistry->WriteInteger("ErrorControl", ErrorControlValue); DriverRegistry->WriteString("Group", "Extended Base"); DriverRegistry->Free(); } //--------------------------------------------------------------------------- void __fastcall TForm1::ExitButtonClick(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TForm1::BeginSampleClick(TObject *Sender) { if (!RunFlag) sscanf(IsaEdit->Text.c_str(), "%x", &Address); if (RunTimer->Enabled) { RunTimer->Enabled = false; BeginSample->Caption = "Perform I/O"; } else { RunTimer->Enabled = true; BeginSample->Caption = "Stop I/O"; } } //--------------------------------------------------------------------------- void __fastcall TForm1::RunTimerTimer(TObject *Sender) { static int value[3] = {0,0,0}, i = 0; int j; char msg[9] = "00000000\0"; value[0] = 1 << i++; OutPortB(Address, value[0]); value[1] = InPortB(Address); value[2] = InPortB(Address+1); i %= 8; for (j=0; j<8; j++) msg[7-j] = (((value[0] & (1 << j))>0) + 0x30); RelayOut->Caption = msg; for (j=0; j<8; j++) msg[7-j] = (((value[1] & (1 << j))>0) + 0x30); RelayRead->Caption = msg; for (j=0; j<8; j++) msg[7-j] = (((value[2] & (1 << j))>0) + 0x30); OptoIn->Caption = msg; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormActivate(TObject *Sender) { if (!RunFlag) FocusControl(IsaEdit); } //--------------------------------------------------------------------------- //---------------------------------------------------------------------------