diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 9223daa91..bde785043 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -52,6 +52,7 @@ using namespace std; #define COULD_NOT_SET_SPEED_PARAMETERS 0x0000000000004000ULL #define COULD_NOT_SET_READOUT_FLAGS 0x0000000000008000ULL #define COULD_NOT_SET_FIFO_DEPTH 0x0000000000010000ULL +#define COULD_NOT_SET_COUNTER_BIT 0x0000000000020000ULL // 0x00000000FFFFFFFFULL /** @short class returning all error messages for error mask */ @@ -161,6 +162,9 @@ public: if(slsErrorMask&COULD_NOT_SET_FIFO_DEPTH) retval.append("Could not set receiver fifo depth\n"); + if(slsErrorMask&COULD_NOT_SET_COUNTER_BIT) + retval.append("Could not set/reset counter bit\n"); + return retval; } diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index c2e41bc56..37c78668d 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -93,7 +93,9 @@ enum { F_SET_ALL_TRIMBITS, /** < set all trimbits to this value */ F_SET_CTB_PATTERN, /** < loads a pattern in the CTB */ - F_WRITE_ADC_REG /** < writes an ADC register */ + F_WRITE_ADC_REG, /** < writes an ADC register */ + + F_SET_COUNTER_BIT /** < set/reset counter bit in detector for eiger */ /* Always append functions hereafter!!! */ diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.c b/slsDetectorSoftware/eigerDetectorServer/FebControl.c index b24cc374a..376c032b5 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.c +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.c @@ -55,6 +55,8 @@ unsigned int* Feb_Control_last_downloaded_trimbits; int Feb_Control_module_number; int Feb_Control_current_index; +int counter_bit = 1; + void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){ unsigned int i; @@ -1408,7 +1410,18 @@ int Feb_Control_ResetChipCompletely(){ printf("Warning: could not ResetChipCompletely().\n");; return 0; } + printf("Chip reset completely\n"); + return 1; +} + + +int Feb_Control_ResetChipPartially(){ + if(!Feb_Control_SetCommandRegister(DAQ_RESET_PERIPHERY & DAQ_RESET_COLUMN_SELECT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + printf("Warning: could not ResetChipPartially().\n");; + return 0; + } + printf("Chip reset partially\n"); return 1; } @@ -1524,7 +1537,12 @@ int Feb_Control_PrepareForAcquisition(){//return 1; return 0; } - if(!Feb_Control_ResetChipCompletely()){ + int ret=0; + if(counter_bit) + ret = Feb_Control_ResetChipCompletely(); + else + ret = Feb_Control_ResetChipPartially(); + if(!ret){ printf("Trouble resetting chips ...\n");; return 0; } @@ -1589,3 +1607,12 @@ int Feb_Control_SaveAllTrimbitsTo(int value){ chanregs[i] = value; return Feb_Control_SetTrimbits(0,chanregs); } + + +void Feb_Control_Set_Counter_Bit(int value){ + counter_bit = value; +} + +int Feb_Control_Get_Counter_Bit(){ + return counter_bit; +} diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.h b/slsDetectorSoftware/eigerDetectorServer/FebControl.h index 3c0e62760..edc28dc6b 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.h +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.h @@ -101,6 +101,7 @@ int Feb_Control_GetModuleNumber(); int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us); int Feb_Control_ResetChipCompletely(); + int Feb_Control_ResetChipPartially(); //struct sockaddr_in Feb_Control_serv_addr; /* @@ -174,6 +175,8 @@ int Feb_Control_GetModuleNumber(); int Feb_Control_SetTestModeVariable(int on); int Feb_Control_GetTestModeVariable(); + void Feb_Control_Set_Counter_Bit(int value); + int Feb_Control_Get_Counter_Bit(); diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer index a309b56c7..9c25f7521 100755 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer and b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServer differ diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c index 3c66d1dcf..5b9047517 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c @@ -441,6 +441,18 @@ int enableTenGigabitEthernet(int val){ } +int setCounterBit(int val){ + if(val!=-1){ + Feb_Control_Set_Counter_Bit(val); +#ifdef VERBOSE + printf("Counter Bit:%d\n",val); +#endif + } + + return Feb_Control_Get_Counter_Bit(); +} + + int setModule(sls_detector_module myMod, int* gain, int* offset){ int retval[2]; int i; @@ -582,12 +594,9 @@ enum detectorSettings setSettings(enum detectorSettings sett, int imod){ int startReceiver(int d){ - - //reset frame number + printf("Going to prepare for acquisition with counter_bit:%d\n",Feb_Control_Get_Counter_Bit()); + Feb_Control_PrepareForAcquisition(); printf("Going to reset Frame Number\n"); - - //if(master) - Feb_Control_PrepareForAcquisition(); Beb_ResetFrameNumber(); return OK; diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index ee3cc4c48..f00b9c926 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -3446,6 +3446,22 @@ int multiSlsDetector::resetCounterBlock(int startACQ){ +int multiSlsDetector::setCounterBit(int i){ + int ret=-100,ret1; + for (int idet=0; idetnumberOfDetectors; idet++) + if (detectors[idet]){ + ret1=detectors[idet]->setCounterBit(i); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<onlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + if(i ==-1) + std::cout<< "Getting counter bit from detector" << endl; + else if(i==0) + std::cout<< "Resetting counter bit in detector " << endl; + else + std::cout<< "Setting counter bit in detector " << endl; +#endif + if (connectControl() == OK){ + + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&i,sizeof(i)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_SET_COUNTER_BIT)); + } + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateDetector(); + + } + } + return retval; +} + diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 5d505a748..2b0064ca6 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1435,6 +1435,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int resetCounterBlock(int startACQ=0); + /** set/get counter bit in detector + * @param i is -1 to get, 0 to reset and any other value to set the counter bit + /returns the counter bit in detector + */ + int setCounterBit(int i = -1); + int getMoveFlag(int imod){if (moveFlag) return *moveFlag; else return 1;}; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 2c539829f..a276b323d 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -163,6 +163,9 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdCounter; i++; + descrToFuncMap[i].m_pFuncName="setctrbit"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdCounter; + i++; /* trim/cal directories */ descrToFuncMap[i].m_pFuncName="trimdir"; //OK @@ -2203,6 +2206,7 @@ string slsDetectorCommand::helpImage(int narg, char *args[], int action){ string slsDetectorCommand::cmdCounter(int narg, char *args[], int action){ int ival; + char answer[100]; string sval; int retval; if (action==HELP_ACTION) @@ -2229,6 +2233,16 @@ string slsDetectorCommand::cmdCounter(int narg, char *args[], int action){ retval=myDet->resetCounterBlock(ival); } + else if (string(args[0])==string("setctrbit")){ + if (action==PUT_ACTION){ + if (!sscanf(args[1],"%d",&ival)) + return string("Could not scan resetctrbit input ")+string(args[1]); + if(ival>=0) + sprintf(answer,"%d",myDet->setCounterBit(ival)); + }else + sprintf(answer,"%d",myDet->setCounterBit()); + return string(answer); + } if(retval==OK) return string("Counter read/reset succesfully"); @@ -2243,10 +2257,13 @@ string slsDetectorCommand::helpCounter(int narg, char *args[], int action){ if (action==PUT_ACTION || action==HELP_ACTION){ os << "readctr \t Cannot put"<< std::endl; os << "resetctr i \t resets counter in detector, restarts acquisition if i=1"<< std::endl; + os << "setctrbit i \t sets/resets counter bit in detector"<< std::endl; + } + if (action==GET_ACTION || action==HELP_ACTION){ + os << "readctr i fname\t reads counter in detector to file fname, restarts acquisition if i=1"<< std::endl; + os << "resetctr \t Cannot get"<< std::endl; + os << "setctrbit i \t gets the counter bit in detector"<< std::endl; } - if (action==GET_ACTION || action==HELP_ACTION) - os << "readctr i fname\t reads counter in detector to file fname, restarts acquisition if i=1"<< std::endl; - os << "resetctr \t Cannot get"<< std::endl; return os.str(); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 3e69f88d3..1d954b733 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -382,8 +382,11 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { */ virtual int resetCounterBlock(int startACQ=0)=0; - - + /** set/get counter bit in detector + * @param i is -1 to get, 0 to reset and any other value to set the counter bit + /returns the counter bit in detector + */ + virtual int setCounterBit(int i = -1)=0; /** diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h index ca9095d83..fa0432bf5 100644 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h @@ -47,6 +47,7 @@ int setHighVolage(int val, int imod); #ifdef EIGERD int setIODelay(int val, int imod); int enableTenGigabitEthernet(int val); +int setCounterBit(int val); #endif #if defined(MYTHEND) || defined(GOTTHARDD) diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index dfe66d020..ed8c7d9f0 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -175,6 +175,7 @@ int function_table() { flist[F_CALIBRATE_PEDESTAL]=&calibrate_pedestal; flist[F_ENABLE_TEN_GIGA]=&enable_ten_giga; flist[F_SET_ALL_TRIMBITS]=&set_all_trimbits; + flist[F_SET_COUNTER_BIT]=&set_counter_bit; #ifdef VERBOSE @@ -3513,7 +3514,7 @@ int calibrate_pedestal(int file_des){ int enable_ten_giga(int file_des) { int n; - int retval; + int retval=-1; int ret=OK,ret1=OK; int arg = -1; @@ -3607,3 +3608,47 @@ int set_all_trimbits(int file_des){ return ret; } + + + + + +int set_counter_bit(int file_des) { + int n; + int retval = -1; + int ret=OK,ret1=OK; + int arg = -1; + + sprintf(mess,"Can't set/rest counter bit \n"); + /* receive arguments */ + n = receiveData(file_des,&arg,sizeof(arg),INT32); + if (n < 0) { + sprintf(mess,"Error reading from socket\n"); + ret=FAIL; + } + /* execute action */ + if(ret != FAIL){ +#ifdef VERBOSE + printf("Getting/Setting/Resetting counter bit :%d \n",arg); +#endif +#ifdef SLS_DETECTOR_FUNCTION_LIST + retval=setCounterBit(arg); + if((arg != -1) && (retval != arg)) + ret=FAIL; + else if (differentClients==1) { + ret=FORCE_UPDATE; + } +#endif + } + /* send answer */ + /* send OK/failed */ + //ret could be swapped during sendData + ret1 = ret; + n = sendData(file_des,&ret1,sizeof(ret),INT32); + if (ret==FAIL) + n += sendData(file_des,mess,sizeof(mess),OTHER); + /* send return argument */ + n += sendData(file_des,&retval,sizeof(retval),INT32); + /*return ok/fail*/ + return ret; +} diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h index 3de728aa8..a7f197432 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h @@ -83,5 +83,6 @@ int stop_receiver(int); int calibrate_pedestal(int); int enable_ten_giga(int); int set_all_trimbits(int); +int set_counter_bit(int); #endif