//------------------------------------------------------------------------------ // MAIN SCRIPT FUNCTIONS //------------------------------------------------------------------------------ // slots allocation const byte _BOARD_ID_MCB = 100; const byte _BOARD_ID_START = 0; const byte _BOARD_ID_STOP = 2; const byte _NB_SLOTS = _BOARD_ID_STOP-_BOARD_ID_START+1; //----------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------- // --- Common cfg file for all slots : //string[] _cfgfilenames = {"G:/TEMP/AIDA/HW_TEST/CFG/PDdiscri-A0-CH0-extclk"}; // --- Different slot cfg files : the number of files must be the number of slots to be configured string[] _cfgfilenames = { "G:/TEMP/AIDA/HW_TEST/CFG/PDdiscri-A0-CH0-5-25-31-MCBNano", "G:/TEMP/AIDA/HW_TEST/CFG/PDdiscri-A0-CH0-5-25-31-MCBNano", "G:/TEMP/AIDA/HW_TEST/CFG/PDdiscri-A0-CH0-5-25-31-MCBNano"}; // --- MCR array of different config files, each MCR config file may have a different size corresponding to its slots nb //string[][] _MCRfiles = new string[_MCR_NB]; //string[] _cfgfilenamesMCR0 = {"cfgFileCommonMCR0AllSlot"}; // common file for all MCR0 slots //string[] _cfgfilenamesMCR1 = {"cfgFileMCR1Slot0, cfgFileMCR1Slot1, cfgFileMCR1Slot2"}; //3 slots in MCR1 //string[] _cfgfilenamesMCR2 = {"cfgFileMCR2Slot0, cfgFileMCR2Slot1"}; //2 slots in MCR2 //_MCRfiles[MCR0] = _cfgfilenamesMCR0; //_MCRfiles[MCR1] = _cfgfilenamesMCR1; //_MCRfiles[MCR2] = _cfgfilenamesMCR2; void ScriptMain() { Console.WriteLine("Script begins..."); // DAQ const int _DAQ_TIME = 30000; // in ms const int _FILE_LIMIT = 40000; //in Ko string l_daqFile = "D:/data/B-MIND/MCBtest/gbit-tdm"; var l_port = App.MCBOpenPort("COM10"); // parameters bool l_enableReadoutOnSpillGate = true; bool l_enableGtrigOnlyOnSpill = true; bool l_syncResetEn = true; // enable Spill & GTRIG time/tag counters reset bool l_enableGtrig = true; // DAQ will see the GTRIG beacons, set it to false if you want only amplitude for histograms bool l_globalToCsv = false; // want the global DAQ to CSV UInt64 l_globalToCsvWords = 0; // limit the nb of words to convert for global daq, set to 0 for all bool l_TDMchop = true; // want the TDM to Individual DAQ chopping bool l_individualToCsv = false; // want the indiv. slot# to csv conversion (NEED l_TDMchop = true) bool l_gtrigSpillCheck = true; // want the GTRIG & SPILL check (NEED l_TDMchop = true) //------------------------------------------------------------------------------ Console.WriteLine("---------------------------------------------------"); Console.WriteLine("This will launch the TDM DAQ for SLAVES ONLY on " + _NB_SLOTS + " slots trough GTX"); Console.WriteLine("---------------------------------------------------"); Console.WriteLine(); Dialog.ShowDialog("Are you sure the MCB has been configured ?"); //----------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------ Console.WriteLine("----------------------------------"); Console.WriteLine("Prepare SYNC ..."); App.ChainSetCheckSyncAndGtx(_BOARD_ID_START, _BOARD_ID_STOP); //------------------------------------------------------------------------------ Console.WriteLine("----------------------------------"); Console.WriteLine("prepare DAQ of all MCR"); App.TDMPrepareDaq(_BOARD_ID_START, _BOARD_ID_STOP, _cfgfilenames, _BOARD_ID_MCB, l_enableGtrig, l_enableGtrigOnlyOnSpill, l_enableReadoutOnSpillGate, l_syncResetEn, x_beforeConfigure:beforeConfigure); //------------------------------------------------------------------------------ Console.WriteLine("----------------------------------"); Console.WriteLine("DAQ on all slot with USB on SLOT0"); App.ChainSetHV(_BOARD_ID_START, _BOARD_ID_STOP, true); Sync.Sleep(500); // allow HV on to be established BoardLib.SetVariable("Board.UsbParam.FileLimit", _FILE_LIMIT); App.TDMStartDaq(_BOARD_ID_START, _BOARD_ID_STOP, l_daqFile, _BOARD_ID_MCB); Sync.Sleep(500); Console.WriteLine("----------------------------------"); Console.WriteLine("MCB start readout"); if(!App.MCBReadout(l_port, true, true)) { //------------------------------------------------------------------------------ // DAQ is now started Console.WriteLine("----------------------------------"); Console.WriteLine("DAQ started for " + _DAQ_TIME/1000 + "s and limited to " + _FILE_LIMIT/1000 + "Mo"); const int _SLEEP_TIME = 50; //ms int l_timeEnd = _DAQ_TIME/_SLEEP_TIME; int l_sleepCnt = 0; while ((l_sleepCnt < l_timeEnd) && (BoardLib.IsTransferingData)) { Sync.Sleep(_SLEEP_TIME); l_sleepCnt++; } //------------------------------------------------------------------------------ //----- STOP DAQ --------- Console.WriteLine("----------------------------------"); Console.WriteLine("Stop DAQ"); App.TDMStopDaq(); Sync.SleepUntil(()=>!BoardLib.IsTransferingData); Console.WriteLine(""); Console.WriteLine("DAQ Total Time (hh:mm:ss): " + BoardLib.ElapsedTime); Console.WriteLine("DAQ Total KBytes: " + BoardLib.XferKBytes); Console.WriteLine("DAQ Xfer rate (KB/s): Avg=" + BoardLib.AvgXferRate + " / Max=" + BoardLib.MaxXferRate); Console.WriteLine(""); Sync.Sleep(500); // allow DAQ stop thread to be finished } Console.WriteLine("----------------------------------"); Console.WriteLine("MCB stop readout"); App.MCBReadout(l_port, false, false); l_port.Close(); //------------------------------------------------------------------------------ //----- HV OFF --------- Console.WriteLine("----------------------------------"); Console.WriteLine("Stop HV"); App.ChainSetHV(_BOARD_ID_START, _BOARD_ID_STOP, false); Sync.Sleep(50); //------------------------------------------------------------------------------ Console.WriteLine("----------------------------------"); Console.WriteLine("DAQ to CSV & TDM/GTRIG check"); if(l_globalToCsv) { App.DaqToCsv(l_daqFile, l_globalToCsvWords); Console.WriteLine(""); } if(l_TDMchop) { Console.WriteLine("TDM chopping & check on " + l_daqFile); App.TDMtoIndividualDaq(l_daqFile); // you can remove TDM beacons in the output files with // App.TDMtoIndividualDaq("G:/TEMP/AIDA/HW_TEST/TEMP/TDM/gbit-tdm-slot2", false); Console.WriteLine(""); } if(l_gtrigSpillCheck && l_TDMchop) { for (int l_i=_BOARD_ID_START ; l_i<=_BOARD_ID_STOP; l_i++) { string l_file = l_daqFile + "--slot" + (l_i-_BOARD_ID_START).ToString(); Console.WriteLine("Gtrig/Spill check on " + l_file); App.GtrigAndSpillCheck(l_file); Console.WriteLine(""); } } if(l_individualToCsv && l_TDMchop) { for (int l_i=_BOARD_ID_START ; l_i<=_BOARD_ID_STOP; l_i++) { string l_file = l_daqFile + "--slot" + (l_i-_BOARD_ID_START).ToString(); Console.WriteLine("Daq to CSV on " + l_file); App.DaqToCsv(l_file); Console.WriteLine(""); } } // We're done! Console.WriteLine("Script ended"); } // function called between BoardLib.OpenConfigFile() and BoardLib.BoardConfigure() in App.TDMPrepareDaq() void beforeConfigure(byte x_boardId, byte x_cfgFileIndex) { Console.WriteLine("Additionnal configure called with BoardId = " + x_boardId); // Printing the config file Console.WriteLine("Config File = " + _cfgfilenames[x_cfgFileIndex]); // OR USING MCR array of different config files //int l_mcr = x_boardId>>3; //Console.WriteLine("Config File = " + _MCRfiles[l_mcr][l_slot]); } // this function (if declared) will be called upon abort request from the user void ScriptAbort() { Console.WriteLine("Script Aborted : stop HV..."); App.ChainSetHV(_BOARD_ID_START, _BOARD_ID_STOP, false); }