Changeset 113


Ignore:
Timestamp:
09/24/09 15:28:15 (15 years ago)
Author:
ogrimm
Message:
Small bug fix
Location:
hvcontrol/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • hvcontrol/src/HV.cc

    r100 r113  
    3030  WrapOK = true;
    3131  LastWrapCount = -1;
     32  ErrorCount = 0;
    3233 
    3334  ClearVoltageArrays();
     
    8788 
    8889  // === Write data ===
    89   if (write(fDescriptor, wbuf, Bytes) < Bytes) {
    90     m->PrintMessage("Error: Could not write (all) data to HV board\n");
     90  if ((ret=write(fDescriptor, wbuf, Bytes)) < Bytes) {
     91    if (ret == -1) m->PrintMessage("Could not write data to HV board (%s)\n", strerror(errno));
     92    else m->PrintMessage("Could write only %d of %d bytes to HV board\n", ret, Bytes);
     93    ErrorCount++;
    9194    return 0;
    9295  }
     
    100103  struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)};
    101104  if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) {
    102     m->PrintMessage("Error with select() (%d/%s)\n", errno,strerror(errno));
     105    m->PrintMessage("Error with select() (%s)\n", strerror(errno));
    103106    return 0;
    104107  }
     
    111114  if ((ret = read(fDescriptor, &rbuf, 1)) == -1) {
    112115    m->PrintMessage("Read error (%s)\n", strerror(errno));
     116    ErrorCount++;
    113117    return 0;
    114118  }
     
    135139  int ret;
    136140 
    137   if((ret = Communicate(wbuf, 3)) == 1) ClearVoltageArrays(); 
     141  if((ret = Communicate(wbuf, 3)) == 1) {
     142    ClearVoltageArrays();
     143    ErrorCount = 0;
     144  } 
    138145  return ret;
    139146}
  • hvcontrol/src/HV.h

    r100 r113  
    4646   int LastWrapCount;
    4747   double fTimeOut;      // [s] timeout to return from read
    48  
     48   int ErrorCount;
     49   
    4950   char *BoardName;
    5051   int HV[NUM_CHAINS][NUM_CHANNELS];      // HV value in DAC units
  • hvcontrol/src/ProcessIO.cc

    r112 r113  
    163163                  config->NumHVBoards); 
    164164    for (int i=0; i<config->NumHVBoards; i++) {
    165       PrintMessage(" Board %d: %s\n ", i, config->fUSBDevice[i]);
     165      PrintMessage(" Board %d: %s\n", i, config->fUSBDevice[i]);
    166166    }
    167167    PrintMessage( " TimeOut:           %.2f s\n"
     
    439439    PrintMessage(" Socket state: %s\n", Socket==-1 ? "disconnected":"connected");
    440440    PrintMessage(" Total number of HV boards: %d\n", NumHVBoards);
    441     PrintMessage(" Active HV boards: %d\n\n ", LastBoard - FirstBoard + 1);
     441    PrintMessage(" Active HV boards: %d\n\n", LastBoard - FirstBoard + 1);
    442442
    443443    for (int i=FirstBoard; i<=LastBoard; i++) {
    444       PrintMessage(" BOARD %d (%s)   Wrap counter: %s (%d)  Manual reset: %s  Time-out: %.2f s\n\n",
     444      PrintMessage(" BOARD %d (%s)   Wrap counter: %s (%d)  Manual reset: %s\n    Time-out: %.2f s  Error count: %d\n\n",
    445445        fHVBoard[i]->GetBoardNumber(), fHVBoard[i]->BoardName,
    446446        fHVBoard[i]->WrapOK ? "ok":"error",
    447447        fHVBoard[i]->LastWrapCount,
    448448        fHVBoard[i]->ResetButton ? "yes" : "no",
    449         fHVBoard[i]->fTimeOut);
     449        fHVBoard[i]->fTimeOut,
     450        fHVBoard[i]->ErrorCount);
    450451
    451452      for (int j=FirstChain; j<=LastChain; j++) {
    452         PrintMessage("  CHAIN %d     Over-current: %s\n ", j, fHVBoard[i]->Overcurrent[j] ? "yes" : "no");
     453        PrintMessage("  CHAIN %d     Over-current: %s\n", j, fHVBoard[i]->Overcurrent[j] ? "yes" : "no");
    453454        for (int k=0;k<4;k++) {
     455          PrintMessage("\r");
    454456          for (int l=0;l<8;l++) {
    455457            if(NParam == 2) PrintMessage("%5d ",fHVBoard[i]->HV[j][k*8+l]);
    456458            else PrintMessage("%#5.2f ",fHVBoard[i]->HVV[j][k*8+l]);
    457459          }
    458           PrintMessage("\n ");
     460          PrintMessage("\n");
    459461        }
    460           PrintMessage("\n ");
    461462      }
    462463    }
     
    554555  va_list ArgumentPointer;
    555556  va_start(ArgumentPointer, Format);
    556   PrintMessage(Format, ArgumentPointer, Target);
     557  DoPrintMessage(Format, ArgumentPointer, Target);
    557558  va_end(ArgumentPointer);
    558559}
     
    562563  va_list ArgumentPointer;
    563564  va_start(ArgumentPointer, Format);
    564   if (CmdFromSocket) PrintMessage(Format, ArgumentPointer, MsgToSocket|MsgToLog);
    565   else PrintMessage(Format, ArgumentPointer, MsgToConsole|MsgToLog);
     565  if (CmdFromSocket) DoPrintMessage(Format, ArgumentPointer, MsgToSocket|MsgToLog);
     566  else DoPrintMessage(Format, ArgumentPointer, MsgToConsole|MsgToLog);
    566567  va_end(ArgumentPointer);
    567568}
    568569
    569570// Function doing the actual printing work
    570 // It is important that Target is here the last argument, otherwise
    571 // there can be confusion with the variadic versions (this function is
    572 // called instead of PrintMessage(int, const char *, ...)
    573 void ProcessIO::PrintMessage(const char *Format, va_list ArgumentPointer, int Target) {
     571// Be careful with overloading variadic functions!
     572void ProcessIO::DoPrintMessage(const char *Format, va_list ArgumentPointer, int Target) {
    574573
    575574  char Textbuffer[MAX_COM_SIZE];
     
    590589    write(Socket, Textbuffer, strlen(Textbuffer));
    591590  }
    592   // Print to log file (repace carriage return by linefeed)
     591  // Print to log file (replace carriage return by linefeed)
    593592  if((Target & MsgToLog) && Logfile!=NULL) {
    594593    for (unsigned int i=0; i<strlen(Textbuffer); i++) {
     
    630629
    631630
    632 // Check board status
     631// Check board status (ignore board if it has more than 10 read/write errors)
    633632void ProcessIO::Monitor() {
    634633
    635   static unsigned int MismatchCount, ErrorCount;
     634  static bool Warned = false;
    636635 
    637636  for (int i=0; i<NumHVBoards; i++) {
     637    if (fHVBoard[i]->ErrorCount > 10) {
     638      if (!Warned) {
     639        Warned = true;
     640        PrintMessage("Warning: Some board has many read/write errors, status monitor disabled\n");
     641      }
     642      continue;
     643    }
    638644
    639645    if (fHVBoard[i]->GetStatus() != 1) {
    640646      PrintMessage("Error: Monitor could not read status of board %d\n", fHVBoard[i]->GetBoardNumber());
    641       sleep(1);
    642       if (ErrorCount++ > 10) {
    643         PrintMessage("Too many errors from HV monitor, terminating program after next command\n");
    644         Exit = true;
    645         pthread_kill(SocketThread, SIGUSR1);
    646       }
    647647    }
    648648   
     
    653653   
    654654    if (!fHVBoard[i]->WrapOK) {
    655       if (MismatchCount++>10) PrintMessage("Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber());
    656       else PrintMessage("Too many wrap counter mismatches, stopping messages\n");
     655      PrintMessage("Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber());
    657656    }
    658657
  • hvcontrol/src/ProcessIO.h

    r112 r113  
    6565  void PrintMessage(int, const char *, ...);
    6666  void PrintMessage(const char *, ...);
    67   void PrintMessage(const char *, va_list, int);
     67  void DoPrintMessage(const char *, va_list, int);
    6868  void CommandControl(char*);
    6969  bool RampVoltage(unsigned int, int, int, int);
Note: See TracChangeset for help on using the changeset viewer.