//--------------------------------------------------------------------------- #include #pragma hdrstop #include #include "DIOu.h" #include "ACCES32.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TSampleForm *SampleForm; TPCI_COMMON_CONFIG buf[64]; //--------------------------------------------------------------------------- __fastcall TSampleForm::TSampleForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TSampleForm::FormCreate(TObject *Sender) { int num, i; bool found; found = false; DriverRegistry = new TRegistry; DriverRegistry->RootKey = HKEY_LOCAL_MACHINE; RunFlag = True; 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->OpenKey(MyKey, true); try { num = DriverRegistry->ReadInteger("NumDevices"); } catch ( ... ) { num = 0; } if (num > 0) DriverRegistry->ReadBinaryData("PCICommonConfig",buf,num*sizeof(TPCI_COMMON_CONFIG)); for (i=0; iCaption="P104-DIO-96 Parallel Digital I/O Card"; AddressList->Items->Add("Port 0: "+IntToHex(int(buf[i].BaseAddresses[2] & 0xFFF8),4)); AddressList->Items->Add("Port 1: "+IntToHex(int(buf[i].BaseAddresses[2] & 0xFFF8) + 4,4)); AddressList->Items->Add("Port 2: "+IntToHex(int(buf[i].BaseAddresses[2] & 0xFFF8) + 8,4)); AddressList->Items->Add("Port 3: "+IntToHex(int(buf[i].BaseAddresses[2] & 0xFFF8) + 12,4)); OutPortB((buf[i].BaseAddresses[2] & 0xFFF8) + 0x1F, 0); //reset CPLD found = true; break; } } if (!found) { CardName->Caption = "No Card Found In Registry"; StatusMemo->Lines->Clear(); StatusMemo->Lines->Append("No Card Found In Registry."); StatusMemo->Lines->Append("This may mean the card is not installed, or that NTioPCI.SYS is not installed, or the card you have installed is not 8255 equipped."); StatusMemo->Lines->Append("Please make sure you have run PCIFind.EXE."); StatusMemo->Lines->Append("If you have an ISA card installed, you may continue running the sample " "by entering the card's Base Address in the edit box above and continuing as normal."); IsaEdit->Visible = true; IsaLabel->Visible = true; AddressList->Enabled = false; RunFlag = false; } AddressList->ItemIndex = 0; if (RunFlag) Address = StrToInt("0x" + AddressList->Items->Strings[AddressList->ItemIndex].SubString(9,4)); DriverRegistry->Free(); } //--------------------------------------------------------------------------- void __fastcall TSampleForm::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 TSampleForm::ExitButtonClick(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TSampleForm::AddressListChange(TObject *Sender) { StatusMemo->Lines->Append("New Port Selected: " + AddressList->Items->Strings[AddressList->ItemIndex]); Address = StrToInt("0x" + AddressList->Items->Strings[AddressList->ItemIndex].SubString(9,4)); } //--------------------------------------------------------------------------- void __fastcall TSampleForm::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 TSampleForm::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 + 3, 0x82); 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); PortAOut->Caption = msg; for (j=0; j<8; j++) msg[7-j] = (((value[1] & (1 << j))>0) + 0x30); PortAIn->Caption = msg; for (j=0; j<8; j++) msg[7-j] = (((value[2] & (1 << j))>0) + 0x30); PortBIn->Caption = msg; } //--------------------------------------------------------------------------- void __fastcall TSampleForm::FormActivate(TObject *Sender) { if (!RunFlag) FocusControl(IsaEdit); } //---------------------------------------------------------------------------