diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.c b/slsDetectorSoftware/eigerDetectorServer/FebControl.c index 300a92bc9..dbb4ebad0 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.c +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.c @@ -18,6 +18,7 @@ #include "FebRegisterDefs.h" #include "FebControl.h" #include "Beb.h" +#include "slsDetectorServer_defs.h" @@ -906,7 +907,7 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ return 0; } - if(!Feb_Control_Reset()) cprintf(RED,"Warning could not reset DAQ.\n"); + if(Feb_Control_Reset() == STATUS_ERROR) cprintf(RED,"Warning could not reset DAQ.\n"); int l_r; //printf("222\n"); for(l_r=0;l_r<2;l_r++){ // l_r loop //printf("\nl_r:%d\t\t",l_r); @@ -914,7 +915,7 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ if(Feb_Control_activated){ if(!(Feb_Interface_WriteRegister(0xfff,DAQ_REG_STATIC_BITS,disable_chip_mask|DAQ_STATIC_BIT_PROGRAM|DAQ_STATIC_BIT_M8,0,0) &&Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) - &&Feb_Control_StartDAQOnlyNWaitForFinish(5000))){ + &&(Feb_Control_StartDAQOnlyNWaitForFinish(5000) == STATUS_IDLE))){ printf("Could not select chips\n"); return 0; } @@ -980,7 +981,7 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ !Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)|| //if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)|| // !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)|| - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){ printf(" some errror!\n"); return 0; } @@ -991,7 +992,7 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ !Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),0,0,1024,trimbits_to_load_r)|| //if(!Feb_Interface_WriteMemory(Module_GetTopLeftAddress(&modules[0]),0,0,1023,trimbits_to_load_r)|| // !Feb_Interface_WriteMemory(Module_GetTopRightAddress(&modules[0]),0,0,1023,trimbits_to_load_l)|| - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){ printf(" some errror!\n"); return 0; } @@ -1073,29 +1074,29 @@ int Feb_Control_AcquisitionInProgress(){ //deactivated should return end of acquisition if(!Feb_Control_activated) - return 0; + return STATUS_IDLE; int ind = Feb_Control_current_index; if(Module_BottomAddressIsValid(&modules[ind])){ if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomRightAddress(&modules[ind]),&status_reg_r))) - {cprintf(RED,"Error: Trouble reading Status register. bottom right address\n");return 0;} + {cprintf(RED,"Error: Trouble reading Status register. bottom right address\n");return STATUS_ERROR;} if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomLeftAddress(&modules[ind]),&status_reg_l))) - {cprintf(RED,"Error: Trouble reading Status register. bottom left address\n");return 0;} + {cprintf(RED,"Error: Trouble reading Status register. bottom left address\n");return STATUS_ERROR;} }else{ if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[ind]),&status_reg_r))) - {cprintf(RED,"Error: Trouble reading Status register. top right address\n");return 0;} + {cprintf(RED,"Error: Trouble reading Status register. top right address\n");return STATUS_ERROR;} if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[ind]),&status_reg_l))) - {cprintf(RED,"Error: Trouble reading Status register. top left address\n");return 0;} + {cprintf(RED,"Error: Trouble reading Status register. top left address\n");return STATUS_ERROR;} } //running if((status_reg_r|status_reg_l)&DAQ_STATUS_DAQ_RUNNING) {/*printf("**runningggg\n");*/ - return 1; + return STATUS_RUNNING; } //idle - return 0; + return STATUS_IDLE; } @@ -1132,16 +1133,25 @@ int Feb_Control_AcquisitionStartedBit(){ int Feb_Control_WaitForFinishedFlag(int sleep_time_us){ int is_running = Feb_Control_AcquisitionInProgress(); - while(is_running){ + + int check_error = 0; + + // it will break out if it is idle or if check_error is more than 5 times + while(is_running != STATUS_IDLE){ usleep(sleep_time_us); is_running = Feb_Control_AcquisitionInProgress(); - } - if(is_running!=0){ - printf("\n\nWarning WaitForFinishedFlag comunication problem..\n\n"); - return 0; //communication problem + + // check error only 5 times (ensuring it is not something that happens sometimes) + if (is_running == STATUS_ERROR) { + if (check_error == 5) + break; + check_error++; + }// reset check_error for next time + else check_error = 0; + } - return 1; + return is_running; } @@ -1151,6 +1161,10 @@ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){ if(!Feb_Control_activated) return 1; + //did not start + if(prev_flag == -1) + return 0; + int value = prev_flag; while(value == prev_flag){ usleep(sleep_time_us); @@ -1183,7 +1197,9 @@ int Feb_Control_Reset(){ int Feb_Control_SetStaticBits(){ if(Feb_Control_activated){ //program=1,m4=2,m8=4,test=8,rotest=16,cs_bar_left=32,cs_bar_right=64 - if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_STATIC_BITS,Feb_Control_staticBits,0,0) || + !Feb_Control_SetCommandRegister(DAQ_SET_STATIC_BIT) || + (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){ cprintf(RED,"Warning: Could not set static bits\n"); return 0; } @@ -1390,7 +1406,7 @@ unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec){ } int Feb_Control_ResetChipCompletely(){ - if(!Feb_Control_SetCommandRegister(DAQ_RESET_COMPLETELY) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + if(!Feb_Control_SetCommandRegister(DAQ_RESET_COMPLETELY) || (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){ cprintf(RED,"Warning: could not ResetChipCompletely() with 0x%x.\n",DAQ_RESET_COMPLETELY); return 0; } @@ -1401,13 +1417,13 @@ int Feb_Control_ResetChipCompletely(){ int Feb_Control_ResetChipPartially(){ - if(!Feb_Control_SetCommandRegister(DAQ_RESET_PERIPHERY) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + if(!Feb_Control_SetCommandRegister(DAQ_RESET_PERIPHERY) || (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){ cprintf(RED,"Warning: could not ResetChipPartially with periphery\n"); return 0; } printf("Chip reset periphery 0x%x\n",DAQ_RESET_PERIPHERY); - if(!Feb_Control_SetCommandRegister(DAQ_RESET_COLUMN_SELECT) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + if(!Feb_Control_SetCommandRegister(DAQ_RESET_COLUMN_SELECT) || (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){ cprintf(RED,"Warning: could not ResetChipPartially with column select\n"); return 0; } @@ -1456,7 +1472,7 @@ int Feb_Control_PrepareForAcquisition(){//return 1; Feb_Control_PrintAcquisitionSetup(); // if(!Reset()||!ResetDataStream()){ - if(!Feb_Control_Reset()){ + if(Feb_Control_Reset() == STATUS_ERROR){ printf("Trouble reseting daq or data stream...\n");; return 0; } @@ -1580,7 +1596,10 @@ int Feb_Control_Pulse_Pixel(int npulses, int x, int y){ Feb_Control_SetInTestModeVariable(1); //on Feb_Control_SetStaticBits(); Feb_Control_SetCommandRegister(DAQ_RESET_PERIPHERY|DAQ_RESET_COLUMN_SELECT); - Feb_Control_StartDAQOnlyNWaitForFinish(5000); + if (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE) { + cprintf(RED,"Warning: could not pulse pixel as status not idle\n"); + return 0; + } unsigned int serial_in = 8<<(4*(7-x%8)); if(!Feb_Control_Shift32InSerialIn(serial_in)){ @@ -1610,7 +1629,7 @@ int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos){ if(Feb_Control_activated){ if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SEND_N_TESTPULSES,npulses,0,0) || !Feb_Control_SetCommandRegister(c) || - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){ cprintf(RED,"Warning: could not PulsePixelNMove(...).\n"); return 0; } @@ -1624,7 +1643,7 @@ int Feb_Control_Shift32InSerialIn(unsigned int value_to_shift_in){ if(Feb_Control_activated){ if(!Feb_Control_SetCommandRegister(DAQ_SERIALIN_SHIFT_IN_32) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SHIFT_IN_32,value_to_shift_in,0,0) || - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){ cprintf(RED,"Warning: could not shift in 32.\n"); return 0; } @@ -1634,7 +1653,7 @@ int Feb_Control_Shift32InSerialIn(unsigned int value_to_shift_in){ int Feb_Control_SendTokenIn(){ if(!Feb_Control_SetCommandRegister(DAQ_SEND_A_TOKEN_IN) || - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){ cprintf(RED,"Warning: could not SendTokenIn().\n"); return 0; } @@ -1650,7 +1669,7 @@ int Feb_Control_ClockRowClock(unsigned int ntimes){ if(Feb_Control_activated){ if(!Feb_Control_SetCommandRegister(DAQ_CLK_ROW_CLK_NTIMES) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CLK_ROW_CLK_NTIMES,ntimes,0,0) || - !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ + (Feb_Control_StartDAQOnlyNWaitForFinish(5000) != STATUS_IDLE)){ cprintf(RED,"Warning: could not clock row clock.\n"); return 0; } @@ -1680,7 +1699,7 @@ int Feb_Control_PulseChip(int npulses){ for(i=0;inumberOfDetectors; ++i) { if (detectors[i]) { @@ -1901,8 +1901,9 @@ slsDetectorDefs::runStatus multiSlsDetector::getRunStatus() { s1=detectors[i]->getRunStatus(); if(detectors[i]->getErrorMask()) setErrorMask(getErrorMask()|(1<startAcquisition(); } +int slsDetectorUsers::stopAcquisition() { + return myDetector->stopAcquisition(); +} + + int slsDetectorUsers::setReceiverSilentMode(int i) { return myDetector->setReceiverSilentMode(i); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h index 0727bb49c..2823d7cb6 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h @@ -598,11 +598,19 @@ class slsDetectorUsers int stopReceiver(); /** - start detector acquisition in non blocking mode + start detector real time acquisition in non blocking mode + does not include scans, scripts, incrementing file index, s + tarting/stopping receiver, resetting frames caught in receiver \returns OK if all detectors are properly started, FAIL otherwise */ int startAcquisition(); + /** + stop detector real time acquisition + \returns OK if all detectors are properly started, FAIL otherwise + */ + int stopAcquisition(); + /** * set receiver in silent mode * @param i 1 sets, 0 unsets (-1 gets) diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp index c3771e7e0..a87747cf6 100644 --- a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp @@ -163,7 +163,7 @@ int receiverInterface::getLastClientIP(int fnum, char retval[]){ dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - dataSocket->ReceiveDataOnly(retval,sizeof(retval)); + dataSocket->ReceiveDataOnly(retval,INET_ADDRSTRLEN); return ret; }