// // Isaac Labrie-Boulay // // Program that enables the modification of gate and delay values // in the logic unit // // Last Edit: 2021-030-29 // #include #include #include #include #include #include #include using namespace std; #include "CAEN_PLULib.h" #include "midas.h" #include "assert.h" #include "mfe.h" #include "mvmestd.h" #include "odbxx.h" //#include "CAEN_PLULib_TEST.h" #ifdef WIN32 // Windows #include #include #else // Linux #define _popen popen #include #include #include char _getch() { char buf = 0; struct termios old = { 0 }; fflush(stdout); if (tcgetattr(0, &old)<0) perror("tcsetattr()"); old.c_lflag &= ~ICANON; old.c_lflag &= ~ECHO; old.c_cc[VMIN] = 1; old.c_cc[VTIME] = 0; if (tcsetattr(0, TCSANOW, &old)<0) perror("tcsetattr ICANON"); if (read(0, &buf, 1)<0) perror("read()"); old.c_lflag |= ICANON; old.c_lflag |= ECHO; if (tcsetattr(0, TCSADRAIN, &old)<0) perror("tcsetattr ~ICANON"); printf("%c\n", buf); return buf; } #endif char *base_address = "32100000"; void err_check(CAEN_PLU_ERROR_CODE err); int main() { cm_connect_experiment("", "", "logic_controller", NULL); midas::odb::set_debug(true); //Establish a connection with the unit through the V1718 int handle; CAEN_PLU_ERROR_CODE err_code; err_code = CAEN_PLU_OpenDevice(CAEN_PLU_CONNECT_VME_V1718, base_address, 0, 0, &handle); err_check(err_code); //Create an ODB key to hold the V2495 handle midas::odb hKey = {{"V2495 Handle", handle}}; hKey.connect("/Modules/Logic"); uint32_t firmware; err_code = CAEN_PLU_ReadReg(handle, 0x1000, &firmware); err_check(err_code); printf("Firmware version: %d\n", firmware); //Initialize Gate and Delay Generators err_code = CAEN_PLU_InitGateAndDelayGenerators(handle); err_check(err_code); //Take the Default gate values from the ODB midas::odb def("/Modules/Logic/Default"); uint32_t commonGate = (uint32_t)def["width"]; uint32_t commonDelay = (uint32_t)def["delay"]; uint32_t commonScale = (uint32_t)def["scale"]; //Set all gates to the same default settings err_code = CAEN_PLU_SetGateAndDelayGenerators(handle, commonGate, commonDelay, commonScale); err_check(err_code); //Watch the ODB subtree midas::odb to_watch("/Modules/Logic"); //Lambda function // // if any of these keys are changed through the web server, // write the new value to the logic unit // to_watch.watch([](midas::odb &logic){ //std::cout << "Value of key \"" + logic.get_full_path() + "\" changed to " << logic << std::endl; CAEN_PLU_ERROR_CODE err_code; //Retrieve the V2495 handle midas::odb temp("/Modules/Logic"); int h = temp["V2495 Handle"]; //Get the QDC parameters midas::odb qdc("/Modules/Logic/QDCGateA"); uint32_t qdcGate = qdc["width"]; uint32_t qdcDelay = qdc["delay"]; uint32_t qdcScale = qdc["scale"]; //Set the new values err_code = CAEN_PLU_SetGateAndDelayGenerator(h, 0, 1, qdcGate, qdcDelay, qdcScale); err_check(err_code); //Get the TDC parameters midas::odb tdc("/Modules/Logic/TDCGate"); uint32_t tdcGate = tdc["width"]; uint32_t tdcDelay = tdc["delay"]; uint32_t tdcScale = tdc["scale"]; //Set the new values err_code = CAEN_PLU_SetGateAndDelayGenerator(h, 1, 1, tdcGate, tdcDelay, tdcScale); err_check(err_code); }); do { int status = cm_yield(100); if (status == SS_ABORT || status == RPC_SHUTDOWN) break; } while (!ss_kbhit()); cm_disconnect_experiment(); return 0; } void err_check(CAEN_PLU_ERROR_CODE err) { if (err != CAEN_PLU_OK) { printf("Error %d\n", err); exit(0); } }