Index: fact/FADctrl/FAD.cc
===================================================================
--- fact/FADctrl/FAD.cc	(revision 11259)
+++ fact/FADctrl/FAD.cc	(revision 11289)
@@ -28,5 +28,5 @@
    {"sclk", &FAD::cmd_sclk, true, 1, "<on|off>", "Set SCLK"},
    {"trigger", &FAD::cmd_trigger, false, 0, "[n|cont [rate]|stop|enable|disable]", "Issue software triggers"},
-   {"drsreset", &FAD::cmd_drsreset, true, 1, "<low|high>", "set DRS reset line"},
+   {"drsreset", &FAD::cmd_drsreset, true, 1, "<low|high>", "Set DRS reset line"},
    {"reset", &FAD::cmd_reset, true, 0, "", "Reset internal trigger counter"},
    {"runnumber", &FAD::cmd_runnumber, true, 1, "<n>", "Set runnumber"},
@@ -62,6 +62,5 @@
   Mode = idle;
   Datafile = -1;
-  EventUpdateDelay = atof(GetConfig("EventUpdateDelay", "0.5").c_str());
-  TimeForDIMUpdate = 0;
+  EventUpdateDelay = atof(GetConfig("EventUpdateDelay", "2").c_str());
 
   // Create pipe for data exchange
@@ -106,4 +105,9 @@
 
   int Ret;
+
+  ExitRequest = true;
+
+  // Stop run if in progress
+  if (Mode != idle) cmd_stop();
 
   // Close pipe (will make read() on pipe in DIM service thread return)
@@ -214,6 +218,6 @@
 
   for (unsigned int i=0; i<Boards.size(); i++) {
-	if (Match(Parameter[1],"low")) Boards[i]->Send(CMD_DRS_RST_LOW);
-	else if (Match(Parameter[1],"high")) Boards[i]->Send(CMD_DRS_RST_HIGH);
+	if (Match(Parameter[1], "low")) Boards[i]->Send(CMD_DRS_RST_LOW);
+	else if (Match(Parameter[1], "high")) Boards[i]->Send(CMD_DRS_RST_HIGH);
 	else {
 	  PrintUsage();
@@ -223,14 +227,11 @@
 }
 
-
 //
 // Execute: Confirm new ROI, DAC or what ever settings
 //
-
 void FAD::cmd_execute() {
 
   for (unsigned int i=0; i<Boards.size(); i++) Boards[i]->Send(CMD_Execute);
 }
-
 
 //
@@ -259,9 +260,6 @@
 //
 // Switch socket mode
-// "com" - command mode (only socket 0 is used)
+// "com" - command mode (only socket 0 is used for event data transmission)
 // "daq" - daq mode (only sockets 1 - 7 are used)
-// 
-//	Note that socket 0 is always used to issue commands
-//
 void FAD::cmd_socketmode() {
 
@@ -652,5 +650,4 @@
 	else if (Mode == acalib) PrintMessage("Current mode is ACALIB (3x%d events, slowest board %d has %d events)\n", NumEventsRequested, SlowestBoard, MinCount);
 	else if (Mode == datarun) PrintMessage("Current mode is DATARUN (%d events requested, %d events taken)\n", NumEventsRequested, NumEvents);
-	PrintMessage("Execution time of last DIM event update %d seconds\n", TimeForDIMUpdate);
 	return;
   }    
@@ -808,10 +805,5 @@
 void FAD::cmd_exit() {
 
-  if (Mode != idle) cmd_stop();
-
   ExitRequest = true;
-
-  // Wait to allow console input to arrive at readline()
-  usleep(10000);
   pthread_kill(MainThread, SIGTERM);
 }
@@ -889,12 +881,10 @@
   DimService FileSizeService(SERVER_NAME"/FileSizeMB", FileSizeMB);
 
-  // Calculate pointers to EventData array (will be updated when active number of boards changes)
+  // Set/allocate pointers
   RunHeader *RHeader = (RunHeader *) EventData;
   BoardStructure **BStruct = new BoardStructure * [Boards.size()];
-
-  for (unsigned int i=0; i<Boards.size(); i++) BStruct[i] = ((BoardStructure *) (RHeader + 1)) + i;
-  EventHeader *EHeader = (EventHeader *) ((char *) (RHeader + 1) + Boards.size()*sizeof(BoardStructure));
-  int *TriggerCell = (int *) (EHeader + 1);
-  short *Data = (short *) (TriggerCell + NChips*Boards.size());
+  EventHeader *EHeader;
+  int *TriggerCell;
+  short *Data;
 
   // Fill fixed entries in M0 RunHeader
@@ -933,16 +923,18 @@
 	IDString.append(string(Buffer, Ret));
 
-	// Active boards for DIM and data taking must only change when idle
-	if (Mode == idle) {
+	// Active boards must not change during data taking
+	if (Mode != datarun || NumEvents == 0) {
 	  ActiveBoards.clear();
-	  for (unsigned int i=0; i<Boards.size(); i++) if (Boards[i]->Active) ActiveBoards.push_back(Boards[i]);
+	  for (unsigned int i=0; i<Boards.size(); i++) {
+		if (Boards[i]->Active) ActiveBoards.push_back(Boards[i]);
+	  }
 	  RHeader->NBoards = ActiveBoards.size();
+	}
 	  
-	  // Calculate updated pointers to EventData array
-	  for (unsigned int i=0; i<ActiveBoards.size(); i++) BStruct[i] = ((BoardStructure *) (RHeader + 1)) + i;
-	  EHeader = (EventHeader *) ((char *) (RHeader + 1) + ActiveBoards.size()*sizeof(BoardStructure));
-	  TriggerCell = (int *) (EHeader + 1);
-	  Data = (short *) (TriggerCell + NChips*ActiveBoards.size());
-	}
+	// Calculate pointers to EventData array
+	for (unsigned int i=0; i<ActiveBoards.size(); i++) BStruct[i] = ((BoardStructure *) (RHeader + 1)) + i;
+	EHeader = (EventHeader *) ((char *) (RHeader + 1) + ActiveBoards.size()*sizeof(BoardStructure));
+	TriggerCell = (int *) (EHeader + 1);
+	Data = (short *) (TriggerCell + NChips*ActiveBoards.size());
 
 	// If amplitude calibration mode, check if all boards finished procedure
@@ -993,5 +985,5 @@
 	  for(unsigned int i=0; i<NChips; i++) TriggerCell[Brd*NChips+i] = (int) S.TriggerCell[i];
 
-	  // Write channel data (12 bit signed two's complement with out-of-range-bit and leading zeroes)
+	  // Write channel data
 	  int Count = Brd*NChips*NChannels*NBins;
 	  memset(Data+Count, 0, NChips*NChannels*NBins*sizeof(short));
@@ -1024,6 +1016,6 @@
 	}
 
-	// Check if DIM service should be updated (delay between updates at least 10xtime to update)
-	if ((Time.tv_sec-LastUpdate.tv_sec)*1e6 + Time.tv_usec-LastUpdate.tv_usec > max(10*TimeForDIMUpdate, EventUpdateDelay)*1e6) {
+	// Check if DIM service should be updated 
+	if ((Time.tv_sec-LastUpdate.tv_sec)*1e6 + Time.tv_usec-LastUpdate.tv_usec >  EventUpdateDelay*1e6) {
 	  gettimeofday(&LastUpdate, NULL);
 
@@ -1031,5 +1023,4 @@
 	  EventNumService.updateService();
 
-	  TimeForDIMUpdate = time(NULL) - LastUpdate.tv_sec;
 	  if (Mode == datarun) FileSizeService.updateService();
 	}
@@ -1110,5 +1101,5 @@
 	  // Close data file and terminate run
 	  if(close(Datafile) == -1) Message(ERROR, "Could not close data file (%s)", strerror(errno));
-	  else PrintMessage("Data file closed (size %.1f MByte, %d events).\n", FileSizeMB, NumEvents);
+	  else PrintMessage("Data file closed (size %.1f MByte, rate %.1f MByte/s, %d events).\n", FileSizeMB, FileSizeMB/(FileRHeader.EndSecond-FileRHeader.StartSecond+(FileRHeader.EndMicrosecond-FileRHeader.StartMicrosecond)/1000000.0), NumEvents);
 
 	  Datafile = -1;
Index: fact/FADctrl/FAD.h
===================================================================
--- fact/FADctrl/FAD.h	(revision 11259)
+++ fact/FADctrl/FAD.h	(revision 11289)
@@ -47,5 +47,4 @@
 	static void LaunchEventThread(class FAD *);
 	pthread_t Thread;
-	float TimeForDIMUpdate;
 
     int Datafile;
Index: fact/FADctrl/FADctrl.cc
===================================================================
--- fact/FADctrl/FADctrl.cc	(revision 11259)
+++ fact/FADctrl/FADctrl.cc	(revision 11289)
@@ -49,4 +49,7 @@
     if (Command == NULL) continue;
 
+	// Process exit request for reasons of responsiveness here
+	if (strcmp(Command, "exit") == 0) break;
+	
 	// Add command to history
     if(strlen(Command) > 0 && LastHist != Command) {
Index: fact/FADctrl/History.txt
===================================================================
--- fact/FADctrl/History.txt	(revision 11259)
+++ fact/FADctrl/History.txt	(revision 11289)
@@ -34,2 +34,3 @@
 21/6/2011	Command 'boards' takes 'none as argument
 24/6/2011	PLL lock status published as DIM service
+7/7/2011	Fixed error in setting the active boards in EventThread()
