Index: hvcontrol/src/HV.cc
===================================================================
--- hvcontrol/src/HV.cc	(revision 90)
+++ hvcontrol/src/HV.cc	(revision 93)
@@ -12,16 +12,18 @@
 
 #include "HV.h"
-
+#include "ProcessIO.h" // Must be not in HV.h to avoid problem with declaring class ProcessIO
 
 // Constructor
-HVBoard::HVBoard(int DeviceNumber, char *DeviceName, bool TestMode, float TimeOut, bool verbose) {
+HVBoard::HVBoard(int DeviceNumber, char *DeviceName, class ProcessIO *PIO) {
    
   char Buffer[BUFFER_LENGTH];
   struct termios tio;
  
-  fTestMode = TestMode;
+  m = PIO;
+
+  fTestMode = m->config->TestMode;
   fTestModeWrap = 0;
-
-  SetTimeOut(TimeOut);
+  
+  SetTimeOut(m->config->fTimeOut);
   BoardNumber = DeviceNumber;
   BoardName = DeviceName;
@@ -42,5 +44,5 @@
   snprintf(Buffer, BUFFER_LENGTH, "/dev/%s",DeviceName);
   if ((fDescriptor = open(Buffer, O_RDWR|O_NOCTTY|O_NDELAY)) == -1) {
-    if(errno != 2) printf("Error: Could not open device %d/%s (%s)\n", DeviceNumber,DeviceName, strerror(errno));
+    if(errno != 2) m->PrintMessage("Error: Could not open device %d/%s (%s)\n", DeviceNumber,DeviceName, strerror(errno));
     return;
   }
@@ -48,12 +50,12 @@
   // Get current serial port settings
   if (tcgetattr(fDescriptor, &tio) == -1) {
-    printf("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) printf("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) printf("Errsor with tcsetattr(...) (%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) 
@@ -62,6 +64,6 @@
   
   while(++trial<=3) {
-    if((ret = Communicate(stdout, &wbuf, 1, verbose)) == 1) {
-      Reset(stdout, verbose);
+    if((ret = Communicate(&wbuf, 1)) == 1) {
+      Reset();
       return;
     }
@@ -77,5 +79,5 @@
 HVBoard::~HVBoard() {
   if(fDescriptor >= 0 && !fTestMode) {
-    Reset(stdout, false);
+    Reset();
     close(fDescriptor);
   }
@@ -86,5 +88,5 @@
 //
 // Returns: 0 read error, 1 success, -1 fTimeOut exceeded
-int HVBoard::Communicate(FILE* fptr, unsigned char* wbuf, int Bytes, bool verbose) {
+int HVBoard::Communicate(unsigned char* wbuf, int Bytes) {
 
   unsigned char rbuf;
@@ -94,10 +96,10 @@
   // === Write data ===
   if (write(fDescriptor, wbuf, Bytes) < Bytes) {
-    fprintf(fptr," Error: could not write (all) data to HV board\n");
-    return 0;
-  }
-  if (verbose) {
-    fprintf(fptr,"%d bytes written:\n", Bytes);
-    for (int i=0; i<Bytes; i++) fprintf(fptr," Byte %d: %#.2x\n",i,wbuf[i]);
+    m->PrintMessage("Error: could not write (all) data to HV board\n");
+    return 0;
+  }
+  if (m->Verbose) {
+    m->PrintMessage("%d bytes written:\n", Bytes);
+    for (int i=0; i<Bytes; i++) m->PrintMessage(" Byte %d: %#.2x\n",i,wbuf[i]);
   }
 
@@ -106,15 +108,15 @@
   struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)};
   if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) {
-    printf("Error with select() (%d/%s)\n", errno,strerror(errno));
+    m->PrintMessage("Error with select() (%d/%s)\n", errno,strerror(errno));
     return 0;
   }
   // Time-out expired?
   if (!FD_ISSET(fDescriptor, &SelectDescriptor)) {
-    if (verbose) printf("Time-out of %.2f seconds expired while reading\n", fTimeOut);
+    if (m->Verbose) m->PrintMessage("Time-out of %.2f seconds expired while reading\n", fTimeOut);
     return -1;
   }
   // Read error?    
   if ((ret = read(fDescriptor, &rbuf, 1)) == -1) {
-    fprintf(stderr, " Read error (%s)\n", strerror(errno));
+    m->PrintMessage("Read error (%s)\n", strerror(errno));
     return 0;
   }
@@ -129,5 +131,5 @@
   ResetButton = (bool) (rbuf & 0X80);
 
-  if (verbose && ret==1) fprintf(fptr," 1 byte read: %#.2x\n", rbuf);  
+  if (m->Verbose && ret==1) m->PrintMessage(" 1 byte read: %#.2x\n", rbuf);  
   
   return 1;
@@ -136,5 +138,5 @@
 
 /* Reset HV board - uses TRead() and has same return values */
-int HVBoard::Reset(FILE* fptr, bool verbose) {
+int HVBoard::Reset() {
   
   if (fTestMode) return 1; 
@@ -143,5 +145,5 @@
   int ret;
   
-  if((ret = Communicate(fptr, wbuf, 3, verbose)) == 1) ClearVoltageArrays();  
+  if((ret = Communicate(wbuf, 3)) == 1) ClearVoltageArrays();  
   return ret;
 }
@@ -149,5 +151,5 @@
 
 /* Read status register - uses TRead() and has same return values */
-int HVBoard::GetStatus(FILE* fptr, bool verbose) {
+int HVBoard::GetStatus() {
 
   if (fTestMode) return 1;
@@ -155,13 +157,13 @@
   unsigned char wbuf[] = {REG_STATUS,0,0};
   
-  return Communicate(fptr, wbuf, 3, verbose);
+  return Communicate(wbuf, 3);
 }
 
 
 /* Set high voltage - uses TRead() and has same return values */
-int HVBoard::SetHV(FILE* fptr, int chain, unsigned int channel, unsigned int hv, bool verbose) {
+int HVBoard::SetHV(int chain, unsigned int channel, unsigned int hv) {
 
   if (fTestMode){
-    printf("Test mode: Nothing to be done. \n");
+    m->PrintMessage("Test mode: Nothing to be done. \n");
     return 1;
   }
@@ -170,5 +172,5 @@
 
   if (!(hv>=0 && hv<=0x3FFF)) {
-    fprintf(fptr," Error: HV beyond limits [0 - 0x3FFF]\n"); 
+    m->PrintMessage(" Error: HV beyond limits [0 - 0x3FFF]\n"); 
     return 0;
   }
@@ -180,5 +182,5 @@
     case 3: wbuf[0] = REG_HV3; break;
 
-    default : fprintf(fptr," Error: chain %d does not exist\n",chain); return 0;
+    default : m->PrintMessage(" Error: chain %d does not exist\n",chain); return 0;
   }
  
@@ -189,5 +191,5 @@
   wbuf[2] |= (unsigned char)(hv & 0X000000FF);              // Add [D7-D0]
    
-  return Communicate(fptr, wbuf, 3, verbose);
+  return Communicate(wbuf, 3);
 }
 
