//--------------------------------------------------------------------------- #include #pragma hdrstop #include "detect.h" #include #include "Unit1.h" #include "aiousb.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBar1Change(TObject *Sender) { rateLBL -> Caption = IntToStr(TrackBar1 -> Position) + " KHz"; } //--------------------------------------------------------------------------- void __fastcall TForm1::fopenBTNClick(TObject *Sender) { if (OpenDialog1 -> Execute() == true) { fName = OpenDialog1 -> FileName; goBTN -> Enabled = true; } } //--------------------------------------------------------------------------- void __fastcall TForm1::goBTNClick(TObject *Sender) { int numDACs, oldDACs; //the number of DACS that are in the source file unsigned short FrameData[8192]; //1k samples for an 8 DAC setup unsigned long FramePoints, index; ifstream inStream (fName.c_str()); char line[128], formatString[32]; int count; double clockRate; bool loopFile; unsigned long status; done = false; index = FramePoints = 0; clockRate = TrackBar1 -> Position * 1000.0; oldDACs = 8; DACOutputOpen(DeviceIndex, &clockRate); DACOutputSetCount(DeviceIndex, oldDACs); do { inStream.getline(line, 128); numDACs = sscanf(line, "%d, %d, %d, %d, %d, %d, %d, %d", &(FrameData[index]), &(FrameData[index + 1]), &(FrameData[index + 2]), &(FrameData[index + 3]), &(FrameData[index + 4]), &(FrameData[index + 5]), &(FrameData[index + 6]), &(FrameData[index + 7])); if ((inStream.eof() == true) || (numDACs < 1)) { inStream.close(); inStream.open(fName.c_str()); //The following really seems like it should work, but it //didn't. I also found several forums of people complaining //that it didn't work. So I went the cheezy route //inStream.seekg(0, ios::beg); //inStream.clear(0); if (numDACs < 1) continue; } if (numDACs == oldDACs) { FramePoints++; index += numDACs; if (index + numDACs > 8191) { DACOutputSetCount(DeviceIndex, numDACs); do { status = DACOutputFrame(DeviceIndex, FramePoints, FrameData); }while (status == ERROR_NOT_READY); index = FramePoints = 0; } } else { DACOutputSetCount(DeviceIndex, oldDACs); do { status = DACOutputFrame(DeviceIndex, FramePoints, FrameData); }while (status == ERROR_NOT_READY); for (count = 0; count < numDACs; count++) { FrameData[count] = FrameData[count + index]; } index = numDACs; FramePoints = 1; oldDACs = numDACs; } Application -> ProcessMessages(); }while (done == false); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormActivate(TObject *Sender) { TForm2 *DetectForm; unsigned long Status; DeviceIndex = diOnly; Status = QueryDeviceInfo(DeviceIndex, NULL, NULL, NULL, NULL, NULL); if (Status == ERROR_SUCCESS) { DetectForm = new TForm2(NULL); DeviceIndex = DetectForm->ShowModal(); DeviceIndex = DetectForm->DeviceIndex; } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { done = true; Memo1 -> Lines -> Add ("Closing... This may take a few seconds."); } //---------------------------------------------------------------------------