diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index d35ed57e9..ae8117394 100755 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -2149,17 +2149,43 @@ int startStateMachine(){ #ifdef VIRTUAL void* start_timer(void* arg) { - int wait_in_s = (getNumFrames() * - getNumTriggers() * - (getPeriod()/(1E9))); - FILE_LOG(logDEBUG1, ("going to wait for %d s\n", wait_in_s)); - while(!virtual_stop && (wait_in_s >= 0)) { - usleep(1000 * 1000); - wait_in_s--; - } - FILE_LOG(logINFOGREEN, ("Virtual Timer Done\n")); + int64_t periodns = getPeriod(); + int numFrames = (getNumFrames() * + getNumTriggers() ); + int64_t exp_ns = getExpTime(); + int frameNr = 0; + // loop over number of frames + for(frameNr=0; frameNr!= numFrames; ++frameNr ) { + + //check if virtual_stop is high + if(virtual_stop == 1){ + break; + } + + // sleep for exposure time + struct timespec begin, end; + clock_gettime(CLOCK_REALTIME, &begin); + usleep(exp_ns / 1000); + clock_gettime(CLOCK_REALTIME, &end); + + // calculate time left in period + int64_t time_ns = ((end.tv_sec - begin.tv_sec) * 1E9 + + (end.tv_nsec - begin.tv_nsec)); + + // sleep for (period - exptime) + if (frameNr < numFrames) { // if there is a next frame + if (periodns > time_ns) { + usleep((periodns - time_ns)/ 1000); + } + } + + // set register frames left + } + + // set status to idle virtual_status = 0; + FILE_LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } #endif @@ -2270,10 +2296,11 @@ void readandSendUDPFrames(int *ret, char *mess) { void readFrame(int *ret, char *mess) { #ifdef VIRTUAL - while(virtual_status) { - //FILE_LOG(logERROR, ("Waiting for finished flag\n"); - usleep(5000); - } + // wait for acquisition to be done + while(runBusy()){ + usleep(500); // random + } + FILE_LOG(logINFOGREEN, ("acquisition successfully finished\n")); return; #endif // 1G diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 49453f472..0e4d58525 100755 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -1743,6 +1743,7 @@ void* start_timer(void* arg) { closeUDPSocket(0); virtual_status = 0; + FILE_LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } #endif diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index fe63db7e8..e39a8e193 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -960,9 +960,11 @@ void* start_timer(void* arg) { (end.tv_nsec - begin.tv_nsec)); // sleep for (period - exptime) - if (periodns > time_ns) { - usleep((periodns - time_ns)/ 1000); - } + if (frameNr < numFrames) { // if there is a next frame + if (periodns > time_ns) { + usleep((periodns - time_ns)/ 1000); + } + } // set register frames left } @@ -970,6 +972,7 @@ void* start_timer(void* arg) { closeUDPSocket(0); // set status to idle virtual_status = 0; + FILE_LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } #endif