/********************************************************************\ Name: drs_simple.cpp Modified : Hide Katagiri Originally created by: Stefan Ritt Contents: Simple example application to read out a DRS4 evaluation board $Id: drs_exam.cpp 13344 2009-04-28 07:34:45Z ritt@PSI.CH $ \********************************************************************/ #include #ifdef _MSC_VER #include #elif defined(OS_LINUX) #define O_BINARY 0 #include #include #include #include #define DIR_SEPARATOR '/' #endif #include #include #include #include "strlcpy.h" #include "DRS.h" #include #include //20130814 add tanaka /*------------------------------------------------------------------*/ //std::cerr << "debug output 1" << std::endl; int main(int argc, char *argv[]) { int i, j, nBoards; DRS *drs; DRSBoard *b; float time_array[1024]; float wave_array[1][1024];// old ver. [8][1024] std::cerr << "debug output 2" << std::endl; //// arguments, inirialization // float threshold=0.1; if (argc > 1) { threshold=atof(argv[1]); // in volt }; // std::cerr << "debug output 3" << std::endl; int nevent=10; if (argc > 2) { nevent=atoi(argv[2]); }; // std::cerr << "debug output 4" << std::endl; char *fname="tmp.dat"; if (argc > 3) { fname=argv[3]; }; // std::cerr << "debug output 5" << std::endl; bool negative_edge=false; // true is negative if (argc > 3) { if (argv[4]=="true") { negative_edge=true; }; }; // std::cerr << "debug output 6" << std::endl; float freq=2.; // sampling frequency (GHz) if (argc > 4) { freq=atof(argv[5]); }; std::cerr << "debug output 7" << std::endl; std::ofstream fout; fout.open(fname); // attention! file is truncated if the file fname already exists. if (!fout.is_open()) { exit(1); } std::cerr << "debug output 8" << std::endl; /* do initial scan */ drs = new DRS(); std::cerr << "debug output 9" << std::endl; /* show any found board(s) */ for (i=0 ; iGetNumberOfBoards() ; i++) { b = drs->GetBoard(i); printf("Found DRS4 evaluation board, serial #%d, firmware revision %d\n", b->GetBoardSerialNumber(), b->GetFirmwareVersion()); } std::cerr << "debug output 10" << std::endl; /* exit if no board found */ nBoards = drs->GetNumberOfBoards(); if (nBoards == 0) { printf("No DRS4 evaluation board found\n"); return 0; } std::cerr << "debug output 11" << std::endl; /* continue working with first board only */ b = drs->GetBoard(0); std::cerr << "debug output 12" << std::endl; /* initialize board */ b->Init(); std::cerr << "debug output 13" << std::endl; /* set sampling frequency */ b->SetFrequency(freq, true); std::cerr << "debug output 14" << std::endl; /* enable transparent mode needed for analog trigger */ b->SetTranspMode(1); std::cerr << "debug output 15" << std::endl; /* use following line to disable hardware trigger */ //b->EnableTrigger(0, 0); /* use following line to enable external hardware trigger (Lemo) */ b->EnableTrigger(1, 0); std::cerr << "debug output 16" << std::endl; /* set input range to -0.5V ... +0.5V */ // b->SetInputRange(0); b->SetInputRange(0.45); //does not work? std::cerr << "debug output 17" << std::endl; /* use following lines to enable hardware trigger on CH1 at 250 mV positive edge */ // b->EnableTrigger(0, 1); // lemo off, analog trigger on // b->SetTriggerSource(0); // use CH1 as source // b->SetTriggerLevel(0.25, false, 0); // 0.25 V, positive edge, zero delay // b->SetTriggerLevel(threshold, negative_edge); // -0.05 V, negative edge b->SetTriggerDelay(120); // zero trigger delay, this places pulse in std::cerr << "debug output 18" << std::endl; /* repeat nevent times */ for (j=0 ; jStartDomino(); //std::cerr << "debug output 19" << std::endl; /* wait for trigger */ //fout << "% Start to read Event #" << j << std::endl; while (b->IsBusy()); //std::cerr << "debug output 20" << std::endl; /* read all waveforms */ b->TransferWaves(0, 8); //std::cerr << "debug output 21" << std::endl; /* read time (X) array in ns */ b->GetTime(0, time_array); //std::cerr << "debug output 22" << std::endl; /* decode waveform (Y) array first channel in mV */ b->GetWave(0, 0, wave_array[0]); /* decode waveform (Y) array second channel in mV*/ // b->GetWave(0, 1, wave_array[1]); /* process waveform: add here some code to display or save waveform X=time[i], Y=wave_array[n][i] */ //std::cerr << "debug output 23" << std::endl; for (i=0;i<1024;i++) { fout << time_array[i] << " " << wave_array[0][i] << std::endl; } //std::cerr << "debug output 24" << std::endl; /* print some progress indication */ //fout << "% Event #" << j << " read successfully" << std::endl; //std::cerr << "debug output 25" << std::endl; } //std::cerr << "debug output 26" << std::endl; fout.close(); //std::cerr << "debug output 27" << std::endl; /* delete DRS object -> close USB connection */ delete drs; //std::cerr << "debug output 28" << std::endl; }