Index: hvcontrol/History.txt
===================================================================
--- hvcontrol/History.txt	(revision 229)
+++ hvcontrol/History.txt	(revision 230)
@@ -36,3 +36,4 @@
 4/6/2010	Command 'hv' allows an array of pixel IDs/voltages (used by feedback)
 15/6/2010	'Channels' now is counted continously from 0 to NUM_CHAINS*NUM_CHANNELS,
-			removed 'chain' command
+			removed 'chain' command.
+24/6/2010	Removed 'Target' from PrintMessage (can now use SendToLog() if needed)
Index: hvcontrol/src/HV.cc
===================================================================
--- hvcontrol/src/HV.cc	(revision 229)
+++ hvcontrol/src/HV.cc	(revision 230)
@@ -27,12 +27,12 @@
   strcpy(BoardName, Name.c_str());
   
-  stringstream Buf;
-  Buf << setw(2) << BoardNumber;
-  string Result =Buf.str();
-
   // Create DIM services
-  NameService = new DimService ((SERVER_NAME"/NAME/ID"+Result).c_str(), BoardName);
-  BiasVolt = new DimService ((char *) (SERVER_NAME"/VOLT/ID"+Result).c_str(), (char *) "D", HVV, NUM_CHAINS*NUM_CHANNELS*sizeof(double));
-
+  stringstream ID;
+  ID << setfill('0') << setw(2) << BoardNumber;
+
+  NameService = new DimService ((SERVER_NAME"/NAME/ID"+ID.str()).c_str(), BoardName);
+  BiasVolt = new DimService ((char *) (SERVER_NAME"/VOLT/ID"+ID.str()).c_str(), (char *) "D", HVV, NUM_CHAINS*NUM_CHANNELS*sizeof(double));
+
+  // Initialise board variables
   for (int i=0; i<NUM_CHAINS; i++) Overcurrent[i] = false;
   ResetButton = false;
@@ -43,6 +43,7 @@
   ClearVoltageArrays();
 
+  // Open device
   if ((fDescriptor = open(("/dev/"+Name).c_str(), O_RDWR|O_NOCTTY|O_NDELAY)) == -1) {
-    if(errno != 2) m->PrintMessage(All, "Error: Could not open device %d/%s (%s)\n", DeviceNumber, Name.c_str(), strerror(errno));
+    if(errno != 2) m->PrintMessage("Error: Could not open device %d/%s (%s)\n", DeviceNumber, Name.c_str(), strerror(errno));
     return;
   }
@@ -50,12 +51,12 @@
   // Get current serial port settings
   if (tcgetattr(fDescriptor, &tio) == -1) {
-    m->PrintMessage(All, "Error: tcgetattr() failed (%d/%s)\n", errno, strerror(errno));
+    m->PrintMessage("Error: tcgetattr() failed (%d/%s)\n", errno, strerror(errno));
     return;   
   }
 
   // Set baudrate and raw mode
-  if (cfsetspeed(&tio, BAUDRATE) == -1) m->PrintMessage(All, "Error: Could not set baud rate (%s)\n", strerror(errno));
+  if (cfsetspeed(&tio, BAUDRATE) == -1) m->PrintMessage("Error: Could not set baud rate (%s)\n", strerror(errno));
   cfmakeraw(&tio);
-  if (tcsetattr(fDescriptor, TCSANOW, &tio ) == -1) m->PrintMessage(All, "Error: tcsetattr() failed (%s)\n", strerror(errno));
+  if (tcsetattr(fDescriptor, TCSANOW, &tio ) == -1) m->PrintMessage("Error: tcsetattr() failed (%s)\n", strerror(errno));
 
   //  Synchronize HV board (if fails, closes device and sets fDescriptor to -2) 
@@ -100,6 +101,6 @@
   // === Write data ===
   if ((ret=write(fDescriptor, wbuf, Bytes)) < Bytes) {
-    if (ret == -1) m->PrintMessage(All, "Could not write data to HV board (%s)\n", strerror(errno));
-    else m->PrintMessage(All, "Could write only %d of %d bytes to HV board\n", ret, Bytes);
+    if (ret == -1) m->Message(m->ERROR, "Could not write data to HV board (%s)", strerror(errno));
+    else m->Message(m->ERROR, "Could write only %d of %d bytes to HV board", ret, Bytes);
     ErrorCount++;
     return 0;
@@ -110,5 +111,5 @@
   struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)};
   if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) {
-    m->PrintMessage(All, "Error with select() (%s)\n", strerror(errno));
+    m->Message(m->ERROR, "Error with select() (%s)", strerror(errno));
     return 0;
   }
@@ -118,5 +119,5 @@
   // Read error?    
   if ((ret = read(fDescriptor, &rbuf, 1)) == -1) {
-    m->PrintMessage(All, "Read error (%s)\n", strerror(errno));
+    m->Message(m->ERROR, "Read error (%s)", strerror(errno));
     ErrorCount++;
     return 0;
Index: hvcontrol/src/ProcessIO.cc
===================================================================
--- hvcontrol/src/ProcessIO.cc	(revision 229)
+++ hvcontrol/src/ProcessIO.cc	(revision 230)
@@ -64,5 +64,4 @@
   // Get configuration data
   vector<string> Boards = Tokenize(GetConfig("Boards"), " \t");
-  fPixMapTable = GetConfig("PixMapTable");
   fTimeOut = atof(GetConfig("TimeOut").c_str());
   fStatusRefreshRate = atof(GetConfig("StatusRefreshRate").c_str());
@@ -84,5 +83,5 @@
     }
     else {
-      PrintMessage(All, "Failed to synchronize board %d (%s)\n", NumHVBoards, fHVBoard[NumHVBoards]->BoardName);
+      Message(WARN, "Failed to synchronize board %d (%s)", NumHVBoards, fHVBoard[NumHVBoards]->BoardName);
       delete fHVBoard[NumHVBoards];
     }
@@ -92,5 +91,5 @@
   // Create instances
   calib  = new HVCalib(this);
-  pm 	 = new PixelMap(fPixMapTable);
+  pm 	 = new PixelMap(GetConfig("PixMapTable"));
   
   // Install DIM command (after all initialized)
@@ -196,6 +195,5 @@
 void ProcessIO::cmd_config() {
 
-  PrintMessage( " Pixel map table:   %s\n"
-    	    	" %d USB devices:\n", fPixMapTable.c_str(), NumHVBoards);  
+  PrintMessage(	" %d USB devices:\n", NumHVBoards);  
 
   for (int i=0; i<NumHVBoards; i++) PrintMessage(" Board %d: %s\n", i, fHVBoard[i]->BoardName);
@@ -414,5 +412,5 @@
   state = active;
   pthread_kill(HVMonitor, SIGUSR1);
-  PrintMessage(All, "Status monitoring activated\n");
+  Message(INFO, "Status monitoring activated");
 }
 
@@ -448,5 +446,5 @@
   state = stopped;
   pthread_kill(HVMonitor, SIGUSR1);
-  PrintMessage(All, "Status monitor stopped\n");
+  Message(INFO, "Status monitor stopped");
 }
 
@@ -481,42 +479,23 @@
   
 
-// Print message to selected target
-void ProcessIO::PrintMessage(MsgTarget Target, const char *Format, ...) {
-
-  va_list ArgumentPointer;
-  va_start(ArgumentPointer, Format); 
-  DoPrintMessage(Format, ArgumentPointer, Target);
-  va_end(ArgumentPointer);
-}
-
-// Print message to log file, and screen or socket (depending on command origin)
+// Print message to screen and to DIM text service
 void ProcessIO::PrintMessage(const char *Format, ...) {
 
+  static char Error[] = "vasprintf() failed in PrintMessage()";
+  char *Text;
+
+  // Evaluate arguments    
   va_list ArgumentPointer;
   va_start(ArgumentPointer, Format);
-  DoPrintMessage(Format, ArgumentPointer, Console);
+  if (vasprintf(&Text, Format, ArgumentPointer) == -1) Text = Error;
   va_end(ArgumentPointer);
-}
-
-// Function doing the actual printing work
-// Be careful with overloading variadic functions!
-void ProcessIO::DoPrintMessage(const char *Format, va_list ArgumentPointer, MsgTarget Target) {
-
-  static char Error[] = "vasprintf() failed in DoPrintMessage()";
-  char *Text;
-
-  // Evaluate arguments    
-  if (vasprintf(&Text, Format, ArgumentPointer) == -1) Text = Error;
-  
+ 
   // Print to console
-  if(Target & Console) {
-    if(strlen(Text)>0 && Text[strlen(Text)-1]=='\n') printf("\r%s%s", Text, Prompt); // New prompt
-    else printf("%s", Text);
-    fflush(stdout);
-  }
-
-  // Send to DIM console service and log
+  if(strlen(Text)>0 && Text[strlen(Text)-1]=='\n') printf("\r%s%s", Text, Prompt); // New prompt
+  else printf("%s", Text);
+  fflush(stdout);
+
+  // Send to DIM text service
   ConsoleOut->updateService(Text); 
-  if(Target & Log) SendToLog("%s %s", SERVER_NAME, Text);
 
   // Free old text
@@ -524,4 +503,5 @@
   ConsoleText = Text; 
 }
+
 
 // Ramp to new voltage with maximum step size given in fHVMaxDiff
@@ -558,6 +538,5 @@
       if (!Warned) {
         Warned = true;
-        PrintMessage(All, "Warning: Some board has many read/write errors, status monitor disabled\n");
-        Message(WARN, "Warning: Some board has many read/write errors, status monitor disabled\n");
+        Message(WARN, "Warning: Board %d has many read/write errors, status monitor disabled", i);
       }
       continue;
@@ -565,23 +544,19 @@
 
     if (fHVBoard[i]->GetStatus() != 1) {
-      PrintMessage(All, "Error: Monitor could not read status of board %d\n", fHVBoard[i]->GetBoardNumber());
-      Message(ERROR, "Error: Monitor could not read status of board %d\n", fHVBoard[i]->GetBoardNumber());
+      Message(ERROR, "Error: Monitor could not read status of board %d", fHVBoard[i]->GetBoardNumber());
     }
     
     if (fHVBoard[i]->ResetButton) {
-      PrintMessage(All, "Manual reset of board %d\n",fHVBoard[i]->GetBoardNumber());
-      Message(INFO, "Manual reset of board %d\n",fHVBoard[i]->GetBoardNumber());
+      Message(INFO, "Manual reset of board %d", fHVBoard[i]->GetBoardNumber());
       ResetBoard(i);
     }
     
     if (!fHVBoard[i]->WrapOK) {
-      PrintMessage(All, "Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber());
-      Message(ERROR, "Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber());
+      Message(ERROR, "Error: Wrap counter mismatch board %d",fHVBoard[i]->GetBoardNumber());
     }
 
     for (int j=0; j<NUM_CHAINS; j++) {
       if (fHVBoard[i]->Overcurrent[j]) {
-		PrintMessage(All, "Warning: Overcurrent in chain %d of board %d\n",j,fHVBoard[i]->GetBoardNumber());
-		Message(WARN, "Warning: Overcurrent in chain %d of board %d\n",j,fHVBoard[i]->GetBoardNumber());
+		Message(WARN, "Warning: Overcurrent in chain %d of board %d",j,fHVBoard[i]->GetBoardNumber());
 		ResetBoard(i);
       }
@@ -631,5 +606,8 @@
   }
 
-  if (getCommand() == Command) CommandControl(getCommand()->getString());
+  if ((getCommand()==Command) && (*(Command->getString()+Command->getSize()-1)=='\0')) {
+	SendToLog("Command '%s' from %s (ID %d)", Command->getString(), getClientName(), getClientId());
+	CommandControl(Command->getString());
+  }
 
   if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {
Index: hvcontrol/src/ProcessIO.h
===================================================================
--- hvcontrol/src/ProcessIO.h	(revision 229)
+++ hvcontrol/src/ProcessIO.h	(revision 230)
@@ -26,5 +26,4 @@
 #define MAX_RATE 50.0
 
-enum MsgTarget {Console=1, Log=2, All=7};
 typedef enum stateenum {active, stopped, na} state_enum;
 
@@ -47,5 +46,4 @@
 
 	// Configuration data
-	std::string fPixMapTable;
 	float fTimeOut;
 	float fStatusRefreshRate;
@@ -69,7 +67,5 @@
 	~ProcessIO();
 
-	void PrintMessage(MsgTarget, const char *, ...);
 	void PrintMessage(const char *, ...);
-	void DoPrintMessage(const char *, va_list, MsgTarget);
 	void CommandControl(char*);
 	bool RampVoltage(unsigned int, int, int, int);
