diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 8d1b04d3f..c3509a44a 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -55,7 +55,7 @@ using namespace std; #define COULD_NOT_SET_COUNTER_BIT 0x0000000000020000ULL #define COULD_NOT_PULSE_PIXEL 0x0000000000040000ULL #define COULD_NOT_PULSE_PIXEL_NMOVE 0x0000000000080000ULL - +#define COULD_NOT_PULSE_CHIP 0x0000000000100000ULL // 0x00000000FFFFFFFFULL /** @short class returning all error messages for error mask */ @@ -174,6 +174,8 @@ public: if(slsErrorMask&COULD_NOT_PULSE_PIXEL_NMOVE) retval.append("Could not pulse pixel and move\n"); + if(slsErrorMask&COULD_NOT_PULSE_CHIP) + retval.append("Could not pulse chip\n"); return retval; diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index 6950b80dd..e61b5cf9c 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -97,7 +97,8 @@ enum { F_SET_COUNTER_BIT, /** < set/reset counter bit in detector for eiger */ F_PULSE_PIXEL, /** < pulse pixel n number of times in eiger at (x,y) */ - F_PULSE_PIXEL_AND_MOVE /** < pulse pixel n number of times and move relatively by x and y */ + F_PULSE_PIXEL_AND_MOVE, /** < pulse pixel n number of times and move relatively by x and y */ + F_PULSE_CHIP /** < pulse chip n number of times */ /* Always append functions hereafter!!! */ diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.c b/slsDetectorSoftware/eigerDetectorServer/FebControl.c index 90ed811ba..27e00df46 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.c +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.c @@ -296,25 +296,25 @@ int Feb_Control_ReadSetUpFileToAddModules(char* file_name){ if(!strcmp(str,"add_module")){ if( sscanf (line,"%s %d %d %d", str,&i0,&i1,&i2) < 4){ - printf("Error adding module from %s.\n",file_name); + cprintf(RED,"Error adding module from %s.\n",file_name); exit(0); } printf ("str:%s len:%d i0:%d i1:%d i2:%d\n", str, strlen(str),i0,i1,i2); if(!Feb_Control_AddModule1(i0,1,i1,i2,0)){ - printf("Error adding module, parameter was assigned twice in setup file: %s.\n",file_name); + cprintf(RED,"Error adding module, parameter was assigned twice in setup file: %s.\n",file_name); exit(0); } } else if(!strcmp(str,"add_half_module")){ if( sscanf (line,"%s %d %d %d", str,&i0,&i1,&i2) < 4){ - printf("Error adding half module from %s.\n",file_name); + cprintf(RED,"Error adding half module from %s.\n",file_name); exit(0); } printf ("str:%s len:%d i0:%d i1:%d i2:%d\n", str, strlen(str),i0,i1,i2); if(!Feb_Control_AddModule1(i0,i1,i2,i2,1)){ - printf("Error adding module, parameter was assigned twice in setup file: %s.\n",file_name); + cprintf(RED,"Error adding module, parameter was assigned twice in setup file: %s.\n",file_name); exit(0); } @@ -322,7 +322,7 @@ int Feb_Control_ReadSetUpFileToAddModules(char* file_name){ Feb_Control_PrintModuleList(); /* if(!Feb_Control_AddModule1(i0,i1)){ - printf("Error adding module, parameter was assigned twice in setup file: %s.\n",file_name); + cprintf(RED,"Error adding module, parameter was assigned twice in setup file: %s.\n",file_name); exit(0); }*/ } @@ -391,12 +391,12 @@ int Feb_Control_CheckModuleAddresses(struct Module* m){ (Module_BottomAddressIsValid(m) && Module_GetBottomBaseAddress(&modules[i]) && Module_GetBottomBaseAddress(m)==Module_GetBottomBaseAddress(&modules[i]))) found_b=1; } - if(found_t) printf("\tWarning: top address %d already used.\n",Module_GetTopBaseAddress(m)); - if(found_b) printf("\tWarning: bottom address %d already used.\n",Module_GetBottomBaseAddress(m)); + if(found_t) cprintf(RED,"\tWarning: top address %d already used.\n",Module_GetTopBaseAddress(m)); + if(found_b) cprintf(RED,"\tWarning: bottom address %d already used.\n",Module_GetBottomBaseAddress(m)); int top_bottom_same = Module_TopAddressIsValid(m)&&Module_BottomAddressIsValid(m)&&Module_GetTopBaseAddress(m)==Module_GetBottomBaseAddress(m); - if(top_bottom_same) printf("\tWarning: top and bottom address are the same %d.\n",Module_GetTopBaseAddress(m)); + if(top_bottom_same) cprintf(RED,"\tWarning: top and bottom address are the same %d.\n",Module_GetTopBaseAddress(m)); return !(top_bottom_same||found_t||found_b); } @@ -473,7 +473,7 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ if(!strcmp("iodelay",str)){ if(sscanf (line,"%s %d", str,&i0) < 2){ - printf("Error reading io_delay\n"); + cprintf(RED,"Error reading io_delay\n"); exit(0); } Feb_Control_SetIDelays(module_num,i0); @@ -481,7 +481,7 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ else if(!strcmp("high_voltage",str)){ if(sscanf (line,"%s %f", str,&f0) < 2){ - printf("Error reading high_voltage\n"); + cprintf(RED,"Error reading high_voltage\n"); exit(0); } Feb_Control_SetHighVoltage(f0); @@ -489,7 +489,7 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ /* else if(!strcmp("photon_energy",str)){ if(sscanf (line,"%s %f", str,&f0) < 2){ - printf("Error reading photon_energy\n"); + cprintf(RED,"Error reading photon_energy\n"); exit(0); } Feb_Control_SetPhotonEnergy(f0); @@ -497,7 +497,7 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ else if(!strcmp("dynamic_range",str)){ if(sscanf (line,"%s %d", str,&i0) < 2){ - printf("Error reading dynamic_range\n"); + cprintf(RED,"Error reading dynamic_range\n"); exit(0); } Feb_Control_SetDynamicRange(i0); @@ -505,7 +505,7 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ else if(!strcmp("readout_speed",str)){ if(sscanf (line,"%s %d", str,&i0) < 2){ - printf("Error reading readout_speed\n"); + cprintf(RED,"Error reading readout_speed\n"); exit(0); } Feb_Control_SetReadoutSpeed(i0); @@ -513,7 +513,7 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ else if(!strcmp("readout_mode",str)){ if(sscanf (line,"%s %d", str,&i0) < 2){ - printf("Error reading readout_mode\n"); + cprintf(RED,"Error reading readout_mode\n"); exit(0); } Feb_Control_SetReadoutMode(i0); @@ -521,14 +521,14 @@ int Feb_Control_ReadSetUpFile(unsigned int module_num, char* file_name){ else { if( sscanf (line,"%s %f", str,&f0) < 2){ - printf("Error reading dac\n"); + cprintf(RED,"Error reading dac\n"); exit(0); } if(module_num>0) sprintf(str,"%s",str); /*sprintf(str,"mod%d::%s",module_num,str);*/ if(!Feb_Control_SetDAC(str,f0,1)) - printf("error in string: %s",str); + cprintf(RED,"Error in string: %s",str); } } @@ -548,25 +548,25 @@ int Feb_Control_CheckSetup(){ for(j=0;j<4;j++){ if(Module_GetTopIDelay(&modules[i],j)<0){ - printf("Warning: module %d's idelay top number %d not set.\n",Module_GetModuleNumber(&modules[i]),j); + cprintf(RED,"Warning: module %d's idelay top number %d not set.\n",Module_GetModuleNumber(&modules[i]),j); ok=0; } if(Module_GetBottomIDelay(&modules[i],j)<0){ - printf("Warning: module %d's idelay bottom number %d not set.\n",Module_GetModuleNumber(&modules[i]),j); + cprintf(RED,"Warning: module %d's idelay bottom number %d not set.\n",Module_GetModuleNumber(&modules[i]),j); ok=0; } } if(Module_GetHighVoltage(&modules[i])<0){ - printf("Warning: module %d's high voltage not set.\n",Module_GetModuleNumber(&modules[i])); + cprintf(RED,"Warning: module %d's high voltage not set.\n",Module_GetModuleNumber(&modules[i])); ok=0; } for(j=0;j3){ - printf("Error SetIDelay chip_pos %d doesn't exist.\n",chip_pos);; + cprintf(RED,"Error SetIDelay chip_pos %d doesn't exist.\n",chip_pos);; return 0; } unsigned int module_index=0; if(!Feb_Control_GetModuleIndex(module_num,&module_index)){ - printf("Error could not set i delay module number %d invalid.\n",module_num); + cprintf(RED,"Error could not set i delay module number %d invalid.\n",module_num); return 0; } @@ -620,7 +620,7 @@ int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsi for(i=0;i4095){ - printf("Warning: SetDac bad value, %d. The range is 0 to 4095.\n",v); + cprintf(RED,"Warning: SetDac bad value, %d. The range is 0 to 4095.\n",v); return 0; } @@ -882,7 +882,7 @@ int Feb_Control_GetDAC(char* s, int* ret_value, int voltage_mv){ int Feb_Control_GetDACName(unsigned int dac_num, char* s){ if(dac_num>=Module_ndacs){ - printf("Warning: GetDACName index out of range, %d invalid.\n",dac_num); + cprintf(RED,"Warning: GetDACName index out of range, %d invalid.\n",dac_num); return 0; } strcpy(s,Module_dac_names[dac_num]); @@ -909,7 +909,7 @@ int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int //static float vmax = 2; if(ch<0||ch>15){ - printf("Warning invalid ch for SetDAC.\n"); + cprintf(RED,"Warning invalid ch for SetDAC.\n"); return 0; } @@ -922,7 +922,7 @@ int Feb_Control_SendDACValue(unsigned int dst_num, unsigned int ch, unsigned int if(!Feb_Interface_WriteRegister(dst_num,0,r,1,0)){ - printf("Warning: trouble setting dac %d voltage.\n",ch); + cprintf(RED,"Warning: trouble setting dac %d voltage.\n",ch); return 0; } @@ -953,11 +953,11 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ unsigned int module_index=0; if(!Feb_Control_GetModuleIndex(module_num,&module_index)){ - printf("Warning could not set trimbits, bad module number.\n"); + cprintf(RED,"Warning could not set trimbits, bad module number.\n"); return 0; } - if(!Feb_Control_Reset()) printf("Warning could not reset DAQ.\n"); + if(!Feb_Control_Reset()) 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); @@ -971,12 +971,12 @@ int Feb_Control_SetTrimbits(unsigned int module_num, unsigned int *trimbits){ //printf("row_set:%d\t\t",row_set); if(row_set==0){ if(!Feb_Control_SetCommandRegister(DAQ_RESET_COMPLETELY|DAQ_SEND_A_TOKEN_IN|DAQ_LOAD_16ROWS_OF_TRIMBITS)){ - printf("Warning: Could not Feb_Control_SetCommandRegister for loading trim bits.\n"); + cprintf(RED,"Warning: Could not Feb_Control_SetCommandRegister for loading trim bits.\n"); return 0; } }else{ if(!Feb_Control_SetCommandRegister(DAQ_LOAD_16ROWS_OF_TRIMBITS)){ - printf("Warning: Could not Feb_Control_SetCommandRegister for loading trim bits.\n"); + cprintf(RED,"Warning: Could not Feb_Control_SetCommandRegister for loading trim bits.\n"); return 0; } } @@ -1084,7 +1084,7 @@ int Feb_Control_SetCommandRegister(unsigned int cmd){ int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret_status){ if(!Feb_Interface_ReadRegister(dst_address,DAQ_REG_STATUS,ret_status)){ - printf("Error: reading status register.\n"); + cprintf(RED,"Error: reading status register.\n"); return 0; } @@ -1095,7 +1095,7 @@ int Feb_Control_GetDAQStatusRegister(unsigned int dst_address, unsigned int* ret int Feb_Control_StartDAQOnlyNWaitForFinish(int sleep_time_us){ if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)||!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_START,0,0)){ - printf("Warning: could not start.\n"); + cprintf(RED,"Warning: could not start.\n"); return 0; } @@ -1110,15 +1110,15 @@ int Feb_Control_AcquisitionInProgress(){ if(Module_BottomAddressIsValid(&modules[ind])){ if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomRightAddress(&modules[ind]),&status_reg_r))) - {printf("ERROR: Trouble reading Status register. bottom right address\n");return 0;} + {cprintf(RED,"Error: Trouble reading Status register. bottom right address\n");return 0;} if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomLeftAddress(&modules[ind]),&status_reg_l))) - {printf("ERROR: Trouble reading Status register. bottom left address\n");return 0;} + {cprintf(RED,"Error: Trouble reading Status register. bottom left address\n");return 0;} }else{ if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[ind]),&status_reg_r))) - {printf("ERROR: Trouble reading Status register. top right address\n");return 0;} + {cprintf(RED,"Error: Trouble reading Status register. top right address\n");return 0;} if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[ind]),&status_reg_l))) - {printf("ERROR: Trouble reading Status register. top left address\n");return 0;} + {cprintf(RED,"Error: Trouble reading Status register. top left address\n");return 0;} } //running @@ -1137,15 +1137,15 @@ int Feb_Control_AcquisitionStartedBit(){ if(Module_BottomAddressIsValid(&modules[ind])){ if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomRightAddress(&modules[ind]),&status_reg_r))) - {printf("ERROR: Trouble reading Status register. bottom right address\n");return -1;} + {cprintf(RED,"Error: Trouble reading Status register. bottom right address\n");return -1;} if(!(Feb_Control_GetDAQStatusRegister(Module_GetBottomLeftAddress(&modules[ind]),&status_reg_l))) - {printf("ERROR: Trouble reading Status register. bottom left address\n");return -1;} + {cprintf(RED,"Error: Trouble reading Status register. bottom left address\n");return -1;} }else{ if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopRightAddress(&modules[ind]),&status_reg_r))) - {printf("ERROR: Trouble reading Status register. top right address\n"); return -1;} + {cprintf(RED,"Error: Trouble reading Status register. top right address\n"); return -1;} if(!(Feb_Control_GetDAQStatusRegister(Module_GetTopLeftAddress(&modules[ind]),&status_reg_l))) - {printf("ERROR: Trouble reading Status register. top left address\n");return -1;} + {cprintf(RED,"Error: Trouble reading Status register. top left address\n");return -1;} } //doesnt mean it started, just the bit @@ -1189,7 +1189,7 @@ int Feb_Control_WaitForStartedFlag(int sleep_time_us, int prev_flag){ int Feb_Control_Reset(){ if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,DAQ_CTRL_RESET,0,0) || !Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_CTRL,0,0,0)){ - printf("Warning: Could not reset daq, no response.\n"); + cprintf(RED,"Warning: Could not reset daq, no response.\n"); return 0; } @@ -1202,7 +1202,7 @@ int Feb_Control_Reset(){ int Feb_Control_SetStaticBits(){ //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)){ - printf("Warning: Could not set static bits\n"); + cprintf(RED,"Warning: Could not set static bits\n"); return 0; } @@ -1213,7 +1213,7 @@ int Feb_Control_SetStaticBits1(unsigned int the_static_bits){ return Feb_Control_SetStaticBits(); } -int Feb_Control_SetTestModeVariable(int on){ +int Feb_Control_SetInTestModeVariable(int on){ if(on) Feb_Control_staticBits |= DAQ_STATIC_BIT_CHIP_TEST; //setting test bit to high else Feb_Control_staticBits &= (~DAQ_STATIC_BIT_CHIP_TEST); //setting test bit to low return 1; @@ -1238,7 +1238,7 @@ int Feb_Control_SetDynamicRange(unsigned int four_eight_sixteen_or_thirtytwo){ Feb_Control_staticBits = DAQ_STATIC_BIT_M12 | (Feb_Control_staticBits&everything_but_bit_mode); Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_AUTO_SUBIMAGING; }else{ - printf("Warning: dynamic range (%d) not valid, not setting bit mode.\n",four_eight_sixteen_or_thirtytwo); + cprintf(RED,"Warning: dynamic range (%d) not valid, not setting bit mode.\n",four_eight_sixteen_or_thirtytwo); printf("Set dynamic range int must equal 4,8 16, or 32.\n"); return 0; } @@ -1268,7 +1268,7 @@ int Feb_Control_SetReadoutSpeed(unsigned int readout_speed){ //0->full,1->half,2 printf("Everything at super slow speed, ie. reading with ~0.200 MHz main clk (super slow speed) ....\n"); }else{ if(readout_speed){ - printf("Warning readout speed %d unknown, defaulting to full speed.\n",readout_speed); + cprintf(RED,"Warning readout speed %d unknown, defaulting to full speed.\n",readout_speed); printf("Everything at full speed, ie. reading with 100 MHz main clk (full speed) ....\n"); return 0; } @@ -1289,7 +1289,7 @@ int Feb_Control_SetReadoutMode(unsigned int readout_mode){ //0->parallel,1->non- }else{ Feb_Control_acquireNReadoutMode |= DAQ_NEXPOSURERS_PARALLEL_MODE; if(readout_mode){ - printf("Warning readout mode %d) unknown, defaulting to full speed.\n",readout_mode); + cprintf(RED,"Warning readout mode %d) unknown, defaulting to full speed.\n",readout_mode); printf("Readout mode set to parrallel acquire/read mode .... \n");; return 0; } @@ -1317,7 +1317,7 @@ int Feb_Control_SetTriggerMode(unsigned int trigger_mode,int polarity){ printf("Trigger mode: externally controlled, external image window (start and stop).\n");; }else{ Feb_Control_triggerMode = DAQ_NEXPOSURERS_INTERNAL_ACQUISITION; - if(trigger_mode) printf("Warning trigger %d) unknown, defaulting to internal triggering.\n",trigger_mode);; + if(trigger_mode) cprintf(RED,"Warning trigger %d) unknown, defaulting to internal triggering.\n",trigger_mode);; printf("Trigger mode: acquisition internally controlled exposure length and period.\n");; return trigger_mode==0; @@ -1347,7 +1347,7 @@ int Feb_Control_SetExternalEnableMode(int use_external_enable, int polarity){ printf(", polarity set to negative.\n");; } }else{ - Feb_Control_externalEnableMode &= (~DAQ_NEXPOSURERS_EXTERNAL_ENABLING); + Feb_Control_externalEnableMode = 0; /* changed by Dhanya according to old code &= (~DAQ_NEXPOSURERS_EXTERNAL_ENABLING);*/ printf("External enabling disabled.\n");; } @@ -1356,7 +1356,7 @@ int Feb_Control_SetExternalEnableMode(int use_external_enable, int polarity){ int Feb_Control_SetNExposures(unsigned int n_images){ if(!n_images){ - printf("Warning nimages must be greater than zero.%d\n",n_images); + cprintf(RED,"Warning nimages must be greater than zero.%d\n",n_images); return 0; } @@ -1393,7 +1393,7 @@ unsigned int Feb_Control_ConvertTimeToRegister(float time_in_sec){ unsigned int decoded_time; if(n_clk_cycles>(pow(2,29)-1)*pow(10,7)){ float max_time = 10e-9*(pow(2,28)-1)*pow(10,7); - printf("Warning: time exceeds (%f) maximum exposure time of %f sec.\n",time_in_sec,max_time); + cprintf(RED,"Warning: time exceeds (%f) maximum exposure time of %f sec.\n",time_in_sec,max_time); printf("\t Setting to maximum %f us.\n",max_time); decoded_time = 0xffffffff; }else{ @@ -1407,7 +1407,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)){ - printf("Warning: could not ResetChipCompletely() with 0x%x.\n",DAQ_RESET_COMPLETELY); + cprintf(RED,"Warning: could not ResetChipCompletely() with 0x%x.\n",DAQ_RESET_COMPLETELY); return 0; } printf("Chip reset completely\n"); @@ -1418,13 +1418,13 @@ int Feb_Control_ResetChipCompletely(){ int Feb_Control_ResetChipPartially(){ if(!Feb_Control_SetCommandRegister(DAQ_RESET_PERIPHERY) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - printf("Warning: could not ResetChipPartially with periphery\n"); + 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)){ - printf("Warning: could not ResetChipPartially with column select\n"); + cprintf(RED,"Warning: could not ResetChipPartially with column select\n"); return 0; } printf("Chip reset column select 0x%x\n",DAQ_RESET_COLUMN_SELECT); @@ -1463,7 +1463,7 @@ int Feb_Control_SendBitModeToBebServer(){ if(!Beb_SetUpTransferParameters(bit_mode)){ - printf("Error: sending bit mode ...\n"); + cprintf(RED,"Error: sending bit mode ...\n"); return 0; } @@ -1472,7 +1472,7 @@ int Feb_Control_SendBitModeToBebServer(){ sprintf(buffer,"setbitmode %d",bit_mode); if(Feb_Control_WriteNRead(buffer,strlen(buffer),1024)<1||strncmp(buffer,"0",1)){ - printf("Error: sending bit mode ...\n"); + cprintf(RED,"Error: sending bit mode ...\n"); return 0; } */ @@ -1511,10 +1511,10 @@ int Feb_Control_WriteNRead(char* message, int length, int max_length){ } int n = write(sockfd,message,length); - if(n<0) printf("ERROR writing to socket"); + if(n<0) cprintf(RED,"Error writing to socket"); length = read(sockfd,message,max_length); - if(length<0) printf("ERROR reading to socket"); + if(length<0) cprintf(RED,"Error reading to socket"); close(sockfd); @@ -1613,7 +1613,7 @@ int Feb_Control_StartAcquisition(){ reg_vals[14]=ACQ_CTRL_START; if(!Feb_Interface_WriteRegisters(Feb_Control_AddressToAll(),15,reg_nums,reg_vals,0,0)){ - printf("Trouble starting acquisition....\n");; + cprintf(RED,"Trouble starting acquisition....\n");; return 0; } @@ -1667,7 +1667,7 @@ int Feb_Control_Pulse_Pixel(int npulses, int x, int y){ printf("Pulsing pixel %d in all super columns below number %d.\n",x%8,x/8); } if(x<0||x>255||y<0||y>255){ - printf("Warning: Pixel out of range.\n"); + cprintf(RED,"Warning: Pixel out of range.\n"); return 0; } @@ -1676,14 +1676,14 @@ int Feb_Control_Pulse_Pixel(int npulses, int x, int y){ nrowclocks += (Feb_Control_staticBits&DAQ_STATIC_BIT_M4) ? 0 : 2*y; nrowclocks += (Feb_Control_staticBits&DAQ_STATIC_BIT_M8) ? 0 : y; - Feb_Control_SetTestModeVariable(1); //on + Feb_Control_SetInTestModeVariable(1); //on Feb_Control_SetStaticBits(); Feb_Control_SetCommandRegister(DAQ_RESET_PERIPHERY|DAQ_RESET_COLUMN_SELECT); Feb_Control_StartDAQOnlyNWaitForFinish(5000); unsigned int serial_in = 8<<(4*(7-x%8)); if(!Feb_Control_Shift32InSerialIn(serial_in)){ - printf("Warning ChipController::PulsePixel: could shift in the initail 32.\n"); + cprintf(RED,"Warning ChipController::PulsePixel: could shift in the initail 32.\n"); return 0; } @@ -1696,6 +1696,7 @@ int Feb_Control_Pulse_Pixel(int npulses, int x, int y){ Feb_Control_ClockRowClock(nrowclocks); Feb_Control_PulsePixelNMove(npulses,0,0); + return 1; } @@ -1708,7 +1709,7 @@ int Feb_Control_PulsePixelNMove(int npulses, int inc_x_pos, int inc_y_pos){ if(!Feb_Interface_WriteRegister(Feb_Control_AddressToAll(),DAQ_REG_SEND_N_TESTPULSES,npulses,0,0) || !Feb_Control_SetCommandRegister(c) || !Feb_Control_StartDAQOnlyNWaitForFinish(5000)){ - printf("Warning: could not PulsePixelNMove(...).\n"); + cprintf(RED,"Warning: could not PulsePixelNMove(...).\n"); return 0; } @@ -1720,7 +1721,7 @@ int Feb_Control_Shift32InSerialIn(unsigned int value_to_shift_in){ 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)){ - printf("Warning: could not shift in 32.\n"); + cprintf(RED,"Warning: could not shift in 32.\n"); return 0; } return 1; @@ -1729,7 +1730,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)){ - printf("Warning: could not SendTokenIn().\n"); + cprintf(RED,"Warning: could not SendTokenIn().\n"); return 0; } return 1; @@ -1737,15 +1738,14 @@ int Feb_Control_SendTokenIn(){ int Feb_Control_ClockRowClock(unsigned int ntimes){ if(ntimes>1023){ - printf("Warning: Clock row clock ntimes (%d) exceeds the maximum value of 1023.\n",ntimes); - printf("\t Setting ntimes to 1023.\n"); + cprintf(RED,"Warning: Clock row clock ntimes (%d) exceeds the maximum value of 1023.\n\t Setting ntimes to 1023.\n",ntimes); ntimes=1023; } 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)){ - printf("Warning: could not clock row clock.\n"); + cprintf(RED,"Warning: could not clock row clock.\n"); return 0; } @@ -1753,6 +1753,41 @@ int Feb_Control_ClockRowClock(unsigned int ntimes){ } +int Feb_Control_PulseChip(int npulses){ + int i; + int on = 1; + + if(npulses == -1){ + on = 0; + printf("\nResetting to normal mode\n"); + }else{ + printf("\n\nPulsing Chip.\n");//really just toggles the enable + printf("Vcmp should be set to 2.0 and Vtrim should be 2.\n"); + } + + + Feb_Control_SetInTestModeVariable(on); + Feb_Control_SetStaticBits(); //toggle the enable 2x times + Feb_Control_ResetChipCompletely(); + + for(i=0;ireceiver_read_freq = 0; - + thisMultiDetector->acquiringFlag = false; thisMultiDetector->alreadyExisting=1; } @@ -5145,4 +5145,27 @@ int multiSlsDetector::pulsePixelNMove(int n,int x,int y) { return ret; } - + +int multiSlsDetector::pulseChip(int n) { + int ret=-100,ret1; + for (int idet=0; idetnumberOfDetectors; idet++) + if (detectors[idet]){ + ret1=detectors[idet]->pulsePixelNMove(n); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<acquiringFlag = b; +} + +bool multiSlsDetector::getAcquiringFlag(){ + return thisMultiDetector->acquiringFlag; +} diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 85eb894bb..311810396 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -194,6 +194,9 @@ class multiSlsDetector : public slsDetectorUtils { /* Receiver read frequency */ int receiver_read_freq; + /** flag for acquiring */ + bool acquiringFlag; + }; @@ -1321,9 +1324,24 @@ class multiSlsDetector : public slsDetectorUtils { */ int pulsePixelNMove(int n=0,int x=0,int y=0); + /** + Pulse Chip + \param n is number of times to pulse + \returns OK or FAIL + */ + int pulseChip(int n=0); + + /** + Set acquiring flag in shared memory + \param b acquiring flag + */ + void setAcquiringFlag(bool b=false); - - + /** + Get acquiring flag from shared memory + \returns acquiring flag + */ + bool getAcquiringFlag(); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 6f94fbaa8..8b0581c8b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -347,6 +347,7 @@ slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int #endif if (connectData() == OK) retval=thisReceiver->sendInt(fnum2,k,(int)t); + disconnectData(); if(retval==FAIL){ cout << "ERROR: Could not send detector type to receiver" << endl; setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTTYPE_NOT_SET)); @@ -732,6 +733,7 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->actionMask=0; thisDetector->tenGigaEnable=0; + thisDetector->acquiringFlag = false; for (int ia=0; iaactionScript[ia],"none"); @@ -1190,7 +1192,7 @@ string slsDetector::checkOnline() { } //still cannot connect to socket, controlSocket=0 if(controlSocket){ - if (controlSocket->Connect()<0) { + if (connectControl() == FAIL) { controlSocket->SetTimeOut(5); thisDetector->onlineFlag=OFFLINE_FLAG; delete controlSocket; @@ -1202,7 +1204,7 @@ string slsDetector::checkOnline() { } else { thisDetector->onlineFlag=ONLINE_FLAG; controlSocket->SetTimeOut(100); - controlSocket->Disconnect(); + disconnectControl(); #ifdef VERBOSE std::cout<< "online!" << std::endl; #endif @@ -1344,8 +1346,7 @@ int slsDetector::connectData() { else{ std::cout << "cannot connect to receiver" << endl; setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER)); - return FAIL; - } + return FAIL;} } return UNDEFINED; }; @@ -1359,9 +1360,15 @@ int slsDetector::disconnectData(){ /** connect to the stop port */ int slsDetector::connectStop() { - if (stopSocket) - return stopSocket->Connect(); - return FAIL; + if (stopSocket){ + if (stopSocket->Connect() >= 0) + return OK; + else{ + std::cout << "cannot connect to stop server" << endl; + return FAIL; + } + } + return UNDEFINED; }; /** disconnect from the stop port */ int slsDetector::disconnectStop(){ @@ -1418,7 +1425,7 @@ int slsDetector::execCommand(string cmd, string answer){ } } } - controlSocket->Disconnect(); + disconnectControl(); } #ifdef VERBOSE std::cout<< "Detector answer is " << answer << std::endl; @@ -1468,7 +1475,7 @@ int slsDetector::setDetectorType(detectorType const type){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (retval==FORCE_UPDATE) updateDetector(); } @@ -1501,6 +1508,7 @@ int slsDetector::setDetectorType(detectorType const type){ #endif if (connectData() == OK) retval=thisReceiver->sendInt(fnum2,arg,(int)thisDetector->myDetectorType); + disconnectData(); if(retval==FAIL){ cout << "ERROR: Could not send detector type to receiver" << endl; setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTTYPE_NOT_SET)); @@ -1563,7 +1571,7 @@ int slsDetector::setNumberOfModules(int n, dimension d){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -1661,7 +1669,7 @@ int slsDetector::getMaxNumberOfModules(dimension d){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -1731,7 +1739,7 @@ slsDetectorDefs::externalSignalFlag slsDetector::setExternalSignalFlags(external controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -1800,7 +1808,7 @@ slsDetectorDefs::externalCommunicationMode slsDetector::setExternalCommunication controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -1860,6 +1868,7 @@ int64_t slsDetector::getId( idMode mode, int imod){ if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { if (connectData() == OK) ret=thisReceiver->getInt(fnum2,retval); + disconnectData(); if(ret==FORCE_UPDATE) ret=updateReceiver(); } @@ -1879,7 +1888,7 @@ int64_t slsDetector::getId( idMode mode, int imod){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -1941,7 +1950,7 @@ int slsDetector::digitalTest( digitalTestMode mode, int imod){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2032,7 +2041,7 @@ int slsDetector::writeRegister(int addr, int val){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2077,7 +2086,7 @@ int slsDetector::writeAdcRegister(int addr, int val){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2115,7 +2124,7 @@ int slsDetector::readRegister(int addr){ if (thisDetector->onlineFlag==ONLINE_FLAG) { // if (connectControl() == OK){ if (stopSocket) { - if (stopSocket->Connect()>=0) { + if (connectStop() == OK) { stopSocket->SendDataOnly(&fnum,sizeof(fnum)); stopSocket->SendDataOnly(&arg,sizeof(arg)); stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); @@ -2125,7 +2134,7 @@ int slsDetector::readRegister(int addr){ stopSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - stopSocket->Disconnect(); + disconnectStop(); // if (ret==FORCE_UPDATE) // updateDetector(); } @@ -2200,7 +2209,7 @@ dacs_t slsDetector::setDAC(dacs_t val, dacIndex index, int mV, int imod){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); @@ -2250,7 +2259,7 @@ dacs_t slsDetector::getADC(dacIndex index, int imod){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2340,7 +2349,7 @@ int slsDetector::setChannel(sls_detector_channel chan){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2431,7 +2440,7 @@ slsDetectorDefs::sls_detector_channel slsDetector::getChannel(int ichan, int ic controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2522,7 +2531,7 @@ int slsDetector::setChip(sls_detector_chip chip){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2575,7 +2584,7 @@ slsDetectorDefs::sls_detector_chip slsDetector::getChip(int ichip, int imod){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2716,7 +2725,7 @@ int slsDetector::setModule(sls_detector_module module, int* gainval, int* offset controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2841,7 +2850,7 @@ slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2957,7 +2966,7 @@ int slsDetector::getThresholdEnergy(int imod){ controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); thisDetector->currentThresholdEV=retval; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -2992,7 +3001,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); thisDetector->currentThresholdEV=retval; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -3033,7 +3042,7 @@ slsDetectorDefs::detectorSettings slsDetector::getSettings(int imod){ std::cout<< "Settings are "<< retval << std::endl; #endif } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -3392,7 +3401,7 @@ int slsDetector::updateDetector() { std::cout<< "Detector returned error: " << mess << std::endl; } else updateDetectorNoWait(); - controlSocket->Disconnect(); + disconnectControl(); } } return ret; @@ -3422,7 +3431,7 @@ int slsDetector::startAcquisition(){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -3444,14 +3453,14 @@ int slsDetector::stopAcquisition(){ #endif if (thisDetector->onlineFlag==ONLINE_FLAG) { if (stopSocket) { - if (stopSocket->Connect()>=0) { + if (connectStop() == OK) { stopSocket->SendDataOnly(&fnum,sizeof(fnum)); stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); if (ret==FAIL) { stopSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - stopSocket->Disconnect(); + disconnectStop(); } } } @@ -3478,7 +3487,7 @@ int slsDetector::startReadOut(){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -3498,7 +3507,7 @@ slsDetectorDefs::runStatus slsDetector::getRunStatus(){ //#endif if (thisDetector->onlineFlag==ONLINE_FLAG) { if (stopSocket) { - if (stopSocket->Connect()>=0) { + if (connectStop() == OK) { stopSocket->SendDataOnly(&fnum,sizeof(fnum)); stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); @@ -3511,7 +3520,7 @@ slsDetectorDefs::runStatus slsDetector::getRunStatus(){ stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); //cout << "____________________" << retval << endl; } - stopSocket->Disconnect(); + disconnectStop(); } } } @@ -3535,7 +3544,7 @@ int* slsDetector::readFrame(){ retval=getDataFromDetector(); if (retval) { dataQueue.push(retval); - controlSocket->Disconnect(); + disconnectControl(); } } } @@ -3633,7 +3642,7 @@ int* slsDetector::readAll(){ dataQueue.push(retval); std::cout<< "pushed" << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); } } #ifdef VERBOSE @@ -3693,7 +3702,7 @@ int* slsDetector::startAndReadAll(){ #endif dataQueue.push(retval); } - controlSocket->Disconnect(); + disconnectControl(); #ifdef VERBOSE std::cout<< "received "<< i<< " frames" << std::endl; @@ -3736,7 +3745,7 @@ int slsDetector::startAndReadAllNoWait(){ // if (thisDetector->onlineFlag==ONLINE_FLAG) { // if (controlSocket) { // if (retval==NULL){ -// controlSocket->Disconnect(); +// disconnectControl(); // #ifdef VERBOSE // std::cout<< "Run finished "<< std::endl; @@ -3797,7 +3806,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); thisDetector->timerValue[index]=retval; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) { updateDetector(); #ifdef VERBOSE @@ -3865,6 +3874,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ if (connectData() == OK) ret=thisReceiver->sendIntArray(fnum2,ut,args); + disconnectData(); if((ut != retval)|| (ret==FAIL)){ ret = FAIL; if(index==FRAME_PERIOD){ @@ -3905,7 +3915,7 @@ int slsDetector::lockServer(int lock) { } else { controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -3934,7 +3944,7 @@ string slsDetector::getLastClientIP() { } else { controlSocket->ReceiveDataOnly(clientName,sizeof(clientName)); } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -4261,7 +4271,7 @@ int slsDetector::setSpeed(speedVariable sp, int value) { } else { controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -4289,7 +4299,7 @@ int64_t slsDetector::getTimeLeft(timerIndex index){ #endif if (thisDetector->onlineFlag==ONLINE_FLAG) { if (stopSocket) { - if (stopSocket->Connect()>=0) { + if (connectStop() == OK) { stopSocket->SendDataOnly(&fnum,sizeof(fnum)); stopSocket->SendDataOnly(&index,sizeof(index)); stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); @@ -4299,7 +4309,7 @@ int64_t slsDetector::getTimeLeft(timerIndex index){ } else { stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); } - stopSocket->Disconnect(); + disconnectStop(); } } } @@ -4339,7 +4349,7 @@ int slsDetector::setDynamicRange(int n){ } else { controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -4388,6 +4398,7 @@ int slsDetector::setDynamicRange(int n){ #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum2,retval1,n); + disconnectData(); if ((ret==FAIL) || (retval1 != retval)){ ret = FAIL; cout << "ERROR:Dynamic range in receiver set incorrectly to " << retval1 << " instead of " << retval << endl; @@ -4471,7 +4482,7 @@ int slsDetector::sendROI(int n,ROI roiLimits[]){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -4531,7 +4542,7 @@ int slsDetector::setReadOutFlags(readOutFlags flag){ controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); thisDetector->roFlags=retval; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -4595,7 +4606,7 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){ */ retval=ret; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -5086,7 +5097,7 @@ int slsDetector::exitServer(){ controlSocket->Connect(); controlSocket->SendDataOnly(&fnum,sizeof(fnum)); controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - controlSocket->Disconnect(); + disconnectControl(); } } if (retval!=OK) { @@ -5355,6 +5366,7 @@ int slsDetector::setUDPConnection(){ #endif if (connectData() == OK) ret=thisReceiver->sendUDPDetails(fnum,retval,args); + disconnectData(); if(ret!=FAIL){ strcpy(thisDetector->receiverUDPMAC,retval); @@ -5492,7 +5504,7 @@ int slsDetector::configureMAC(){ } else controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -5517,6 +5529,7 @@ int slsDetector::configureMAC(){ #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum2,retval,retval); + disconnectData(); if(ret==FAIL) setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); } @@ -5633,7 +5646,7 @@ int slsDetector::sendImageToDetector(imageType index,short int imageVals[]){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -5658,7 +5671,7 @@ int slsDetector::getCounterBlock(short int arg[],int startACQ){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -5710,7 +5723,7 @@ int slsDetector::resetCounterBlock(int startACQ){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -5747,7 +5760,7 @@ int slsDetector::setCounterBit(int i){ setErrorMask((getErrorMask())|(COULD_NOT_SET_COUNTER_BIT)); } controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); @@ -6114,7 +6127,7 @@ int slsDetector::setAllTrimbits(int val, int imod){ } else { controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -6250,7 +6263,7 @@ slsDetectorDefs::masterFlags slsDetector::setMaster(masterFlags flag) { } else { controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -6294,7 +6307,7 @@ slsDetectorDefs::synchronizationMode slsDetector::setSynchronization(synchroniza } else { controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -6349,7 +6362,7 @@ string slsDetector::checkReceiverOnline() { } //still cannot connect to socket, dataSocket=0 if(dataSocket){ - if (dataSocket->Connect()<0) { + if (connectData() == FAIL) { dataSocket->SetTimeOut(5); thisDetector->receiverOnlineFlag=OFFLINE_FLAG; delete dataSocket; @@ -6361,7 +6374,7 @@ string slsDetector::checkReceiverOnline() { } else { thisDetector->receiverOnlineFlag=ONLINE_FLAG; dataSocket->SetTimeOut(100); - dataSocket->Disconnect(); + disconnectData(); #ifdef VERBOSE std::cout<< "receiver online!" << std::endl; #endif @@ -6467,6 +6480,7 @@ string slsDetector::setFilePath(string s) { #endif if (connectData() == OK) ret=thisReceiver->sendString(fnum,retval,arg); + disconnectData(); if(ret!=FAIL) fileIO::setFilePath(string(retval)); else if(!s.empty()){ @@ -6502,6 +6516,7 @@ string slsDetector::setFileName(string s) { #endif if (connectData() == OK) ret=thisReceiver->sendString(fnum,retval,arg); + disconnectData(); if(ret!=FAIL){ #ifdef VERBOSE std::cout << "Complete file prefix from receiver: " << retval << std::endl; @@ -6538,6 +6553,7 @@ int slsDetector::setFileIndex(int i) { #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); if(ret!=FAIL) fileIO::setFileIndex(retval); if(ret==FORCE_UPDATE) @@ -6561,6 +6577,7 @@ int slsDetector::startReceiver(){ #endif if (connectData() == OK) ret=thisReceiver->executeFunction(fnum,mess); + disconnectData(); if(ret==FORCE_UPDATE) ret=updateReceiver(); else if (ret == FAIL){ @@ -6595,6 +6612,7 @@ int slsDetector::stopReceiver(){ #endif if (connectData() == OK) ret=thisReceiver->executeFunction(fnum,mess); + disconnectData(); if(ret==FORCE_UPDATE) ret=updateReceiver(); else if (ret == FAIL) @@ -6619,6 +6637,7 @@ slsDetectorDefs::runStatus slsDetector::startReceiverReadout(){ #endif if (connectData() == OK) ret=thisReceiver->getInt(fnum,retval); + disconnectData(); if(retval!=-1) s=(runStatus)retval; if(ret==FORCE_UPDATE) @@ -6647,7 +6666,7 @@ int slsDetector::detectorSendToReceiver(bool set){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -6675,6 +6694,7 @@ slsDetectorDefs::runStatus slsDetector::getReceiverStatus(){ #endif if (connectData() == OK) ret=thisReceiver->getInt(fnum,retval); + disconnectData(); if(retval!=-1) s=(runStatus)retval; if(ret==FORCE_UPDATE) @@ -6698,6 +6718,7 @@ int slsDetector::getFramesCaughtByReceiver(){ #endif if (connectData() == OK) ret=thisReceiver->getInt(fnum,retval); + disconnectData(); if(ret==FORCE_UPDATE) ret=updateReceiver(); } @@ -6718,6 +6739,7 @@ int slsDetector::getReceiverCurrentFrameIndex(){ #endif if (connectData() == OK) ret=thisReceiver->getInt(fnum,retval); + disconnectData(); if(ret==FORCE_UPDATE) ret=updateReceiver(); } @@ -6739,6 +6761,7 @@ int slsDetector::resetFramesCaught(){ #endif if (connectData() == OK) ret=thisReceiver->executeFunction(fnum,mess); + disconnectData(); if(ret==FORCE_UPDATE) ret=updateReceiver(); } @@ -6771,7 +6794,7 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int n= dataSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned: " << mess << " " << n << std::endl; delete [] retval; - dataSocket->Disconnect(); + disconnectData(); return NULL; } else { n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH); @@ -6788,11 +6811,11 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int std::cout<dataBytes << std::endl; ret=FAIL; delete [] retval; - dataSocket->Disconnect(); + disconnectData(); return NULL; } } - dataSocket->Disconnect(); + disconnectData(); } } return retval; @@ -6816,6 +6839,7 @@ int slsDetector::lockReceiver(int lock){ #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); if(ret==FORCE_UPDATE) updateReceiver(); } @@ -6839,6 +6863,7 @@ string slsDetector::getReceiverLastClientIP(){ #endif if (connectData() == OK) ret=thisReceiver->getLastClientIP(fnum,retval); + disconnectData(); if(ret==FORCE_UPDATE) updateReceiver(); } @@ -6889,7 +6914,7 @@ int slsDetector::updateReceiver() { dataSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Receiver returned error: " << mess << std::endl; } - dataSocket->Disconnect(); + disconnectData(); } } @@ -6911,7 +6936,7 @@ int slsDetector::exitReceiver(){ dataSocket->Connect(); dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - dataSocket->Disconnect(); + disconnectData(); } } if (retval!=OK) { @@ -6945,6 +6970,7 @@ int slsDetector::enableWriteToFile(int enable){ #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); if(ret!=FAIL) parentDet->enableWriteToFileMask(retval); if(ret==FORCE_UPDATE) @@ -6975,6 +7001,7 @@ int slsDetector::overwriteFile(int enable){ #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); if(ret!=FAIL) parentDet->enableOverwriteMask(retval); if(ret==FORCE_UPDATE) @@ -7003,6 +7030,7 @@ int slsDetector::setFrameIndex(int index){ #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); if(ret!=FAIL) fileIO::setFrameIndex(retval); if(ret==FORCE_UPDATE) @@ -7034,7 +7062,7 @@ int slsDetector::calibratePedestal(int frames){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -7071,6 +7099,7 @@ int slsDetector::setReadReceiverFrequency(int getFromReceiver,int i){ #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); if(ret==FAIL) retval = -1; if(ret==FORCE_UPDATE) @@ -7097,6 +7126,7 @@ int slsDetector::enableReceiverCompression(int i){ #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum,retval,i); + disconnectData(); if(ret==FAIL) setErrorMask((getErrorMask())|(COULDNOT_ENABLE_COMPRESSION)); } @@ -7117,6 +7147,7 @@ void slsDetector::setDetectorHostname(){ #endif if (connectData() == OK) ret=thisReceiver->sendString(fnum,retval,thisDetector->hostname); + disconnectData(); if((ret==FAIL) || (strcmp(retval,thisDetector->hostname))) setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTNAME_NOT_SET)); } @@ -7145,7 +7176,7 @@ int slsDetector::enableTenGigabitEthernet(int i){ setErrorMask((getErrorMask())|(DETECTOR_TEN_GIGA)); } controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -7164,6 +7195,7 @@ int slsDetector::enableTenGigabitEthernet(int i){ #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum2,retval,i); + disconnectData(); if(ret==FAIL) setErrorMask((getErrorMask())|(RECEIVER_TEN_GIGA)); } @@ -7193,6 +7225,7 @@ int slsDetector::setReceiverFifoDepth(int i){ #endif if (connectData() == OK) ret=thisReceiver->sendInt(fnum,retval,i); + disconnectData(); if(ret==FAIL) setErrorMask((getErrorMask())|(COULD_NOT_SET_FIFO_DEPTH)); } @@ -7288,7 +7321,7 @@ uint64_t slsDetector::setCTBWord(int addr,uint64_t word) { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -7342,7 +7375,7 @@ int slsDetector::setCTBPatLoops(int level,int &start, int &stop, int &n) { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -7390,7 +7423,7 @@ int slsDetector::setCTBPatWaitAddr(int level, int addr) { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -7440,7 +7473,7 @@ int slsDetector::setCTBPatWaitTime(int level, uint64_t t) { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -7472,7 +7505,7 @@ int slsDetector::pulsePixel(int n,int x,int y) { std::cout<< "Detector returned error: " << mess << std::endl; setErrorMask((getErrorMask())|(COULD_NOT_PULSE_PIXEL)); } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -7503,7 +7536,7 @@ int slsDetector::pulsePixelNMove(int n,int x,int y) { std::cout<< "Detector returned error: " << mess << std::endl; setErrorMask((getErrorMask())|(COULD_NOT_PULSE_PIXEL_NMOVE)); } - controlSocket->Disconnect(); + disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } @@ -7512,4 +7545,43 @@ int slsDetector::pulsePixelNMove(int n,int x,int y) { return ret; } - + + +int slsDetector::pulseChip(int n) { + int ret=FAIL; + int fnum=F_PULSE_CHIP; + char mess[100]; + + +#ifdef VERBOSE + std::cout<< std::endl<< "Pulsing Pixel " << n << " number of times" << endl << endl; +#endif + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&n,sizeof(n)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_PULSE_CHIP)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + return ret; +} + + + +void slsDetector::setAcquiringFlag(bool b){ + thisDetector->acquiringFlag = b; +} + +bool slsDetector::getAcquiringFlag(){ + return thisDetector->acquiringFlag; +} diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index f80c3e80f..66c08783e 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -265,6 +265,9 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** 10 Gbe enable*/ int tenGigaEnable; + /** flag for acquiring */ + bool acquiringFlag; + } sharedSlsDetector; @@ -1752,6 +1755,25 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int pulsePixelNMove(int n=0,int x=0,int y=0); + /** + Pulse Chip + \param n is number of times to pulse + \returns OK or FAIL + */ + int pulseChip(int n=0); + + /** + Set acquiring flag in shared memory + \param b acquiring flag + */ + void setAcquiringFlag(bool b=false); + + /** + Get acquiring flag from shared memory + \returns acquiring flag + */ + bool getAcquiringFlag(); + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 22d1ee691..7377036db 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -321,9 +321,9 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef reads the encoder (iof required for angualr conversion)
processes the data (flat field, rate, angular conversion and merging ::processData()) \param delflag 0 leaves the data in the final data queue (default is 1) - \returns nothing + \returns OK or FAIL depending on if it already started */ - virtual void acquire(int delflag=1)=0; + virtual int acquire(int delflag=1)=0; int startMeasurement(){acquire(0); return OK;}; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 326511759..411d87de9 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -1019,7 +1019,7 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { i++; - /* pulse pixel */ + /* pulse */ descrToFuncMap[i].m_pFuncName="pulse"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPulse; @@ -1029,7 +1029,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPulse; i++; - + descrToFuncMap[i].m_pFuncName="pulsechip"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPulse; + i++; + numberOfCommands=i; @@ -1132,7 +1135,9 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); - myDet->acquire(); + + if(myDet->acquire() == FAIL) + return string("acquire unsuccessful"); if(myDet->setReceiverOnline()==ONLINE_FLAG){ char answer[100]; sprintf(answer,"\n%d",myDet->getFramesCaughtByReceiver()); @@ -4934,10 +4939,12 @@ string slsDetectorCommand::helpPulse(int narg, char *args[], int action) { if (action==PUT_ACTION || action==HELP_ACTION) { os << "pulse [n] [x] [y] \t pulses pixel at coordinates (x,y) n number of times" << std::endl; os << "pulsenmove [n] [x] [y]\t pulses pixel n number of times and moves relatively by x value (x axis) and y value(y axis)" << std::endl; + os << "pulsechip [n] \t pulses chip n number of times, while n=-1 will reset it to normal mode" << std::endl; } if (action==GET_ACTION || action==HELP_ACTION){ os << "pulse \t cannot get" << std::endl; os << "pulsenmove \t cannot get" << std::endl; + os << "pulsechip \t cannot get" << std::endl; } return os.str(); @@ -4945,6 +4952,7 @@ string slsDetectorCommand::helpPulse(int narg, char *args[], int action) { string slsDetectorCommand::cmdPulse(int narg, char *args[], int action) { + int retval = FAIL; if (action==HELP_ACTION) return helpPulse(narg, args, action); @@ -4953,32 +4961,43 @@ string slsDetectorCommand::cmdPulse(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); - if(narg<4) - return string("insufficient arguments:\n" + helpPulse(narg, args, action)); - int ival1=1,ival2=-2,ival3=-1; + int ival1=-1; if (!sscanf(args[1],"%d",&ival1)) return string("Could not scan 1st argument ")+string(args[1]); - if (!sscanf(args[2],"%d",&ival2)) - return string("Could not scan 2nd argument ")+string(args[2]); - if (!sscanf(args[3],"%d",&ival3)) - return string("Could not scan 3rd argument ")+string(args[3]); - if (string(args[0])==string("pulse")){ - if(myDet->pulsePixel(ival1,ival2,ival3) == OK) - return string("Pulse pixel successful"); - else - return string("Pulse pixel failed"); + if (string(args[0])==string("pulsechip")) + retval = myDet->pulseChip(ival1); + + + else{ + //next commands requires 3 addnl. arguments + int ival2=-1,ival3=-1; + if(narg<4) + return string("insufficient arguments:\n" + helpPulse(narg, args, action)); + if (!sscanf(args[2],"%d",&ival2)) + return string("Could not scan 2nd argument ")+string(args[2]); + if (!sscanf(args[3],"%d",&ival3)) + return string("Could not scan 3rd argument ")+string(args[3]); + + + if (string(args[0])==string("pulse")) + retval = myDet->pulsePixel(ival1,ival2,ival3); + + else if (string(args[0])==string("pulsenmove")) + retval = myDet->pulsePixelNMove(ival1,ival2,ival3); + + else return string("could not decode command")+cmd; + } - else if (string(args[0])==string("pulsenmove")){ - if(myDet->pulsePixelNMove(ival1,ival2,ival3) == OK) - return string("Pulse pixel and move successful"); - else - return string("Pulse pixel and move failed"); - } - - return string("could not decode command")+cmd; + return string(""); +/* + if(retval == OK) + return string(" successful"); + else + return string(" failed"); + */ } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 970f3c5f4..3b546efb1 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -41,7 +41,18 @@ slsDetectorUtils::slsDetectorUtils() { -void slsDetectorUtils::acquire(int delflag){ +int slsDetectorUtils::acquire(int delflag){ + + //ensure acquire isnt started multiple times by same client + pthread_mutex_lock(&mp); + if(getAcquiringFlag() == false) + setAcquiringFlag(true); + else{ + std::cout << "Error: Acquire has already been started." << std::endl; + return FAIL; + } + pthread_mutex_unlock(&mp); + bool receiver = (setReceiverOnline()==ONLINE_FLAG); if(!receiver){ @@ -526,6 +537,10 @@ void slsDetectorUtils::acquire(int delflag){ #ifdef VERBOSE cout << "acquisition finished callback done " << endl; #endif + + setAcquiringFlag(false); + return OK; + } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 4d5f15dd5..4225efa08 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -405,10 +405,10 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { reads the encoder (iof required for angualr conversion)
processes the data (flat field, rate, angular conversion and merging ::processData()) \param delflag 0 leaves the data in the final data queue - \returns nothing + \returns OK or FAIL depending on if it already started */ - void acquire(int delflag=1); + int acquire(int delflag=1); // double* convertAngles(){return convertAngles(currentPosition);}; @@ -778,8 +778,24 @@ virtual int setReceiverFifoDepth(int i = -1)=0; */ virtual int pulsePixelNMove(int n=0,int x=0,int y=0)=0; + /** + Pulse Chip + \param n is number of times to pulse + \returns OK or FAIL + */ + virtual int pulseChip(int n=0)=0; + /** + Set acquiring flag in shared memory + \param b acquiring flag + */ + virtual void setAcquiringFlag(bool b=false)=0; + /** + Get acquiring flag from shared memory + \returns acquiring flag + */ + virtual bool getAcquiringFlag() = 0; diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h index 85e25581f..b352a293c 100644 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h @@ -50,6 +50,7 @@ int enableTenGigabitEthernet(int val); int setCounterBit(int val); int pulsePixel(int n, int x, int y); int pulsePixelNMove(int n, int x, int y); +int pulseChip(int n); #endif #if defined(MYTHEND) || defined(GOTTHARDD) diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index 8f10944e4..e2c5dd2b5 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -178,7 +178,7 @@ int function_table() { flist[F_SET_COUNTER_BIT]=&set_counter_bit; flist[F_PULSE_PIXEL]=&pulse_pixel; flist[F_PULSE_PIXEL_AND_MOVE]=&pulse_pixel_and_move; - + flist[F_PULSE_CHIP]=&pulse_chip; #ifdef VERBOSE @@ -3766,3 +3766,52 @@ int pulse_pixel_and_move(int file_des) { } + + + +int pulse_chip(int file_des) { + + int ret=OK,ret1=OK; + int n; + int arg = -1; + + + sprintf(mess,"pulse chip failed\n"); + + n = receiveData(file_des,arg,sizeof(arg),INT32); + if (n < 0) { + sprintf(mess,"Error reading from socket\n"); + ret=FAIL; + } +#ifndef EIGERD + ret = FAIL; + strcpy(mess,"Not applicable/implemented for this detector\n"); +#else +#ifdef SLS_DETECTOR_FUNCTION_LIST + if (ret==OK) { + if (differentClients==1 && lockStatus==1) { + ret=FAIL; + sprintf(mess,"Detector locked by %s\n",lastClientIP); + } else + ret=pulseChip(arg); + } +#endif +#endif + if(ret==OK){ + if (differentClients) + ret=FORCE_UPDATE; + } + + /* 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); + + /*return ok/fail*/ + return ret; + +} + diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h index 3cf4122d0..c45da8b56 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h @@ -86,5 +86,7 @@ int set_all_trimbits(int); int set_counter_bit(int); int pulse_pixel(int); int pulse_pixel_and_move(int); +int pulse_chip(int); + #endif diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp index 11f17fceb..e5a5011a0 100644 --- a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp @@ -33,7 +33,6 @@ int receiverInterface::sendString(int fnum, char retval[], char arg[]){ std::cout<< "Receiver returned error: " << mess << std::endl; } dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); - dataSocket->Disconnect(); return ret; } @@ -54,7 +53,6 @@ int receiverInterface::sendUDPDetails(int fnum, char retval[], char arg[3][MAX_S } else dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); - dataSocket->Disconnect(); return ret; } @@ -72,7 +70,6 @@ int receiverInterface::sendInt(int fnum, int &retval, int arg){ std::cout<< "Receiver returned error: " << mess << std::endl; } dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - dataSocket->Disconnect(); return ret; } @@ -90,7 +87,6 @@ int receiverInterface::getInt(int fnum, int &retval){ std::cout<< "Receiver returned error: " << mess << std::endl; } dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - dataSocket->Disconnect(); return ret; } @@ -109,7 +105,6 @@ int receiverInterface::sendInt(int fnum, int64_t &retval, int64_t arg){ std::cout<< "Receiver returned error: " << mess << std::endl; } dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - dataSocket->Disconnect(); return ret; } @@ -128,7 +123,6 @@ int receiverInterface::sendIntArray(int fnum, int64_t &retval, int64_t arg[2]){ std::cout<< "Receiver returned error: " << mess << std::endl; } dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - dataSocket->Disconnect(); return ret; } @@ -141,7 +135,6 @@ int receiverInterface::getInt(int fnum, int64_t &retval){ dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - dataSocket->Disconnect(); return ret; } @@ -153,7 +146,6 @@ int receiverInterface::getLastClientIP(int fnum, char retval[]){ dataSocket->SendDataOnly(&fnum,sizeof(fnum)); dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); dataSocket->ReceiveDataOnly(retval,sizeof(retval)); - dataSocket->Disconnect(); return ret; } @@ -169,7 +161,6 @@ int receiverInterface::executeFunction(int fnum,char mess[]){ dataSocket->ReceiveDataOnly(mess,MAX_STR_LENGTH); std::cout<< "Receiver returned error: " << mess << std::endl; } - dataSocket->Disconnect(); return ret; }