diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 9b6dd92ea..b69d2103e 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -5070,10 +5070,14 @@ void multiSlsDetector::startReceivingDataThread(){ void *zmqsocket; context = zmq_ctx_new(); zmqsocket = zmq_socket(context, ZMQ_PULL); + //int hwmval = 10; + //zmq_setsockopt(zmqsocket,ZMQ_RCVHWM,&hwmval,sizeof(hwmval)); //set receive HIGH WATER MARK (8-9ms slower) zmq_connect(zmqsocket, hostname); cout << "ZMQ Client of " << ithread << " at " << hostname << endl; cprintf(BLUE,"%d Created socket\n",ithread); - + /* + zmq_pollitem_t pollitem = {zmqsocket, 0 , ZMQ_POLLIN , 0}; +*/ //initializations int numReadoutPerDetector = 1; bool jungfrau = false; @@ -5086,6 +5090,7 @@ void multiSlsDetector::startReceivingDataThread(){ int* image = new int[nel]; int len,idet = 0; singleframe[ithread]=NULL; + int datavalue = 2; threadStarted = true; //let calling function know thread started and obtained current @@ -5102,82 +5107,112 @@ void multiSlsDetector::startReceivingDataThread(){ //scan header------------------------------------------------------------------- zmq_msg_init (&message); - len = zmq_msg_recv(&message, zmqsocket, 0); - if (len == -1) { - zmq_msg_close(&message); - cprintf(RED, "%d message null\n",ithread); - continue; + while(1){ + + len = zmq_msg_recv(&message, zmqsocket, ZMQ_DONTWAIT); + if(len>0) + break;//also comment out the next recv +/* + zmq_poll(&pollitem, 1, 0); + //received something, get out + if(pollitem.revents & ZMQ_POLLIN){ + pollitem.revents = 0; + break; + } +*/ + //received nothing + else if (receiverStoppedFlag){ + //one more chance if receiver stopped + datavalue--; + + if(!datavalue){ + //#ifdef VERYVERBOSE + cprintf(RED,"End of socket for %d\n", ithread); + //#endif + singleframe[ithread] = NULL; + break; + } + + //wait to check again only if receiver stopped + //usleep(4000); + } + usleep(4000); } - // error if you print it - // cout << ithread << " header len:"<0 && (dataReady == NULL)){ @@ -148,17 +149,21 @@ int slsDetectorUtils::acquire(int delflag){ if(receiver){ if(getReceiverStatus()!=IDLE) stopReceiver(); - if(setReceiverOnline()==OFFLINE_FLAG) + if(setReceiverOnline()==OFFLINE_FLAG){ *stoppedFlag=1; - + receiverStoppedFlag = 1; + } //multi detectors shouldnt have different receiver read frequencies enabled/disabled if(setReadReceiverFrequency(0) < 0){ std::cout << "Error: The receiver read frequency is invalid:" << setReadReceiverFrequency(0) << std::endl; - *stoppedFlag=1; + *stoppedFlag=1; + receiverStoppedFlag = 1; } - if(setReceiverOnline()==OFFLINE_FLAG) + if(setReceiverOnline()==OFFLINE_FLAG){ *stoppedFlag=1; + receiverStoppedFlag = 1; + } } @@ -291,6 +296,7 @@ int slsDetectorUtils::acquire(int delflag){ if(setReceiverOnline()==OFFLINE_FLAG){ stopReceiver(); *stoppedFlag=1; + receiverStoppedFlag = 1; pthread_mutex_unlock(&mg); break; } @@ -298,6 +304,7 @@ int slsDetectorUtils::acquire(int delflag){ if(startReceiver() == FAIL) { stopReceiver(); *stoppedFlag=1; + receiverStoppedFlag = 1; pthread_mutex_unlock(&mg); break; } @@ -344,6 +351,7 @@ int slsDetectorUtils::acquire(int delflag){ pthread_mutex_lock(&mg); //offline if(setReceiverOnline()==OFFLINE_FLAG){ + receiverStoppedFlag = 1; if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){ if((*correctionMask)&(1<