//--------------------------------------------------------------------------- #include #pragma hdrstop #include "DetectUnit.h" #include "AIOUSB.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" bool DeviceOK[7]; TDetectForm *DetectForm; //--------------------------------------------------------------------------- __fastcall TDetectForm::TDetectForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TDetectForm::FormCreate(TObject *Sender) { DetectButton->Click(); DeviceList->ItemIndex = 0; } //--------------------------------------------------------------------------- void __fastcall TDetectForm::DetectButtonClick(TObject *Sender) { unsigned long DeviceMask; unsigned long PID, NameSize; AnsiString Name; char buf[255]; int I; bool Found; DeviceList->Items->Clear(); Found = False; DeviceMask = GetDevices(); for (I = 0; I <= 7; I++) { DeviceOK[I] = False; if ((DeviceMask & (1 << I)) != 0) { NameSize = 256; QueryDeviceInfo(I, &PID, &NameSize, buf, NULL, NULL); Name = Format("%s", ARRAYOFCONST((buf))); Name.SetLength(NameSize); switch (PID) { case 0x8020: //USB-CTR-15 DeviceOK[I] = True; Found = True; break; default: Name = Format("%s ", ARRAYOFCONST((buf))); } // end switch PID } // end if DeviceMask else Name = ""; DeviceList->Items->Add(IntToStr(I) + ": " + Name); } // end for I if (Found) StatusMemo->Lines->Text = "Select the device you want to work with and click Go."; else StatusMemo->Lines->Text = "No compatible devices found; your device may not be installed, or may not be installed properly. Click Redetect to check again."; } //--------------------------------------------------------------------------- void __fastcall TDetectForm::GoButtonClick(TObject *Sender) { int I; I = DeviceList->ItemIndex; if ((I == -1) || (!DeviceOK[I])) { //No device index selected or Invalid device index selected Beep(); exit(0); } // end if I DeviceIndex = I; ModalResult = mrOk; } //---------------------------------------------------------------------------