diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 03d68c18d..26d7d640a 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -3536,56 +3536,46 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ //send acquisiton period/frame number to receiver - switch(thisDetector->myDetectorType){ - case EIGER: - if(index != FRAME_NUMBER) - return thisDetector->timerValue[index]; - break; - //for gotthard and moench, mythen returns anyway because of no rxr - default: - if(index != FRAME_PERIOD) - return thisDetector->timerValue[index]; - break; - } - - if((ret != FAIL) && (t != -1)){ - if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ - int64_t args[2]; - args[1] = retval; - if(index==FRAME_NUMBER) - args[0] = FRAME_NUMBER; - else{ - args[0] = FRAME_PERIOD; - //if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period - if(!retval) - args[1] = timerValue[ACQUISITION_TIME]; - } - + if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)) + { + if((ret != FAIL) && (t != -1)){ + if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + int64_t args[2]; + args[1] = retval; + if(index==FRAME_NUMBER){ #ifdef VERBOSE - if(index==FRAME_PERIOD) - std::cout << "Sending/Getting acquisition period to/from receiver " << retval << std::endl; - else - std::cout << "Sending/Getting number of frames to/from receiver " << retval << std::endl; + std::cout << "Sending/Getting number of frames to/from receiver " << retval << std::endl; #endif - if (connectData() == OK) - ret=thisReceiver->sendIntArray(fnum,ut,args); - if((ut != retval)|| (ret==FAIL)){ - ret = FAIL; - if(index==FRAME_PERIOD){ - cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << retval << endl; - setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); - }else{ - cout << "ERROR:Number of Frames in receiver set incorrectly to " << ut << " instead of " << retval << endl; - setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET)); + args[0] = FRAME_NUMBER; + }else{ +#ifdef VERBOSE + std::cout << "Sending/Getting acquisition period to/from receiver " << retval << std::endl; +#endif + args[0] = FRAME_PERIOD; + //if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period + if(!retval) + args[1] = timerValue[ACQUISITION_TIME]; + } + + if (connectData() == OK) + ret=thisReceiver->sendIntArray(fnum,ut,args); + if((ut != retval)|| (ret==FAIL)){ + ret = FAIL; + if(index==FRAME_PERIOD){ + cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << retval << endl; + setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); + }else{ + cout << "ERROR:Number of Frames in receiver set incorrectly to " << ut << " instead of " << retval << endl; + setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET)); + } + } + if(ret==FORCE_UPDATE) + updateReceiver(); } + } - if(ret==FORCE_UPDATE) - updateReceiver(); - } - - } - +} return thisDetector->timerValue[index]; }; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index f93ea3f9e..3e4393720 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -3975,9 +3975,11 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { myDet->startReceiver(); else if(!strcasecmp(args[1],"stop")){ myDet->startReceiverReadout(); - while(myDet->getReceiverStatus() != RUN_FINISHED) + runStatus s = myDet->getReceiverStatus(); + while((s != RUN_FINISHED)&&(s != IDLE)) usleep(50000); - myDet->stopReceiver(); + if(s != IDLE) + myDet->stopReceiver(); } else return helpReceiver(narg, args, action); diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index 912e6486d..40a9d411e 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -54,6 +54,7 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): packetIndexMask(GOTTHARD_PACKET_INDEX_MASK), frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET), acquisitionPeriod(SAMPLE_TIME_IN_NS), + numberOfFrames(0), shortFrame(-1), currframenum(0), prevframenum(0), @@ -74,18 +75,18 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): thread_started(0), currentWriterThreadIndex(-1), totalListeningFrameCount(0), - sfilefd(NULL), writerthreads_mask(0x0), listening_thread_running(0), killListeningThread(0), killAllWritingThreads(0), - cbAction(DO_EVERYTHING), + sfilefd(NULL), startAcquisitionCallBack(NULL), pStartAcquisition(NULL), acquisitionFinishedCallBack(NULL), pAcquisitionFinished(NULL), rawDataReadyCallBack(NULL), - pRawDataReady(NULL){ + pRawDataReady(NULL), + cbAction(DO_EVERYTHING){ maxPacketsPerFile = MAX_FRAMES_PER_FILE * packetsPerFrame; @@ -261,7 +262,7 @@ char* slsReceiverFunctionList::setFilePath(char c[]){ strcpy(filePath,c); }else{ strcpy(filePath,""); - cout<<"FilePath does not exist:"<getFileName(); + return receiver->getFileName(); else return fileName; } @@ -339,12 +340,9 @@ slsDetectorDefs::runStatus slsReceiverFunctionList::getStatus(){ char* slsReceiverFunctionList::setDetectorHostname(char c[]){ if(strlen(c)){ - char *c0 = receiver->getDetectorHostname(); - if(c0== NULL) + if(receiver->getDetectorHostname()== NULL) receiver->initialize(c); - delete[] c0; } - return receiver->getDetectorHostname(); } @@ -360,9 +358,17 @@ void slsReceiverFunctionList::setUDPPortNo(int p){ int32_t slsReceiverFunctionList::setNumberOfFrames(int32_t fnum){ - if(fnum >= 0) - receiver->setNumberOfFrames(fnum); - return receiver->getNumberOfFrames(); + if(fnum >= 0){ + if(myDetectorType == EIGER) + receiver->setNumberOfFrames(fnum); + else + numberOfFrames = fnum; + } + + if(myDetectorType == EIGER) + return receiver->getNumberOfFrames(); + else + return numberOfFrames; } int32_t slsReceiverFunctionList::setScanTag(int32_t stag){ @@ -418,6 +424,7 @@ int slsReceiverFunctionList::setNFrameToGui(int i){ int64_t slsReceiverFunctionList::setAcquisitionPeriod(int64_t index){ + if(index >= 0){ if(index != acquisitionPeriod){ acquisitionPeriod = index; @@ -1161,6 +1168,13 @@ int slsReceiverFunctionList::stopReceiver(){ void slsReceiverFunctionList::startReadout(){ + + if(myDetectorType == EIGER){ + receiver->stopReceiver(); + return; + } + + //wait so that all packets which take time has arrived usleep(50000); @@ -1201,7 +1215,7 @@ int slsReceiverFunctionList::startListening(){ #endif int lastpacketoffset, expected, rc, packetcount, maxBufferSize, carryonBufferSize; - int lastframeheader;// for moench to check for all the packets in last frame + uint32_t lastframeheader;// for moench to check for all the packets in last frame char* tempchar = NULL; @@ -1358,7 +1372,7 @@ int slsReceiverFunctionList::startListening(){ cout << "last packet offset:" << lastpacketoffset << endl; #endif - if((packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))+1) & (packetIndexMask))){ + if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))+1) & (packetIndexMask))){ memcpy(tempchar,buffer+lastpacketoffset, onePacketSize); #ifdef VERYDEBUG cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) @@ -1422,7 +1436,8 @@ int slsReceiverFunctionList::startWriting(){ thread_started = 1; - int numpackets,tempframenum, nf; + int numpackets, nf; + uint32_t tempframenum; char* wbuf; char *data=new char[bufferSize]; int iFrame = 0; @@ -1576,15 +1591,14 @@ int slsReceiverFunctionList::startWriting(){ int ndata; char* buff = 0; data = wbuf+ HEADER_SIZE_NUM_TOT_PACKETS; - int ir, ic; int remainingsize = numpackets * onePacketSize; int np; int once = 0; - double tot, tl, tr, bl, br, v; + double tot, tl, tr, bl, br; int xmin = 1, ymin = 1, ix, iy; - while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize )){ + while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ np = ndata/onePacketSize; //cout<<"buff framnum:"<> frameIndexOffset)<startReadout(); retval = slsReceiverList->getStatus(); - if((retval == TRANSMITTING) || (retval == RUN_FINISHED)) + if((retval == TRANSMITTING) || (retval == RUN_FINISHED) || (retval == IDLE)) ret = OK; else ret = FAIL;