Changeset 113
- Timestamp:
- 09/24/09 15:28:15 (15 years ago)
- Location:
- hvcontrol/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
hvcontrol/src/HV.cc
r100 r113 30 30 WrapOK = true; 31 31 LastWrapCount = -1; 32 ErrorCount = 0; 32 33 33 34 ClearVoltageArrays(); … … 87 88 88 89 // === 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++; 91 94 return 0; 92 95 } … … 100 103 struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)}; 101 104 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)); 103 106 return 0; 104 107 } … … 111 114 if ((ret = read(fDescriptor, &rbuf, 1)) == -1) { 112 115 m->PrintMessage("Read error (%s)\n", strerror(errno)); 116 ErrorCount++; 113 117 return 0; 114 118 } … … 135 139 int ret; 136 140 137 if((ret = Communicate(wbuf, 3)) == 1) ClearVoltageArrays(); 141 if((ret = Communicate(wbuf, 3)) == 1) { 142 ClearVoltageArrays(); 143 ErrorCount = 0; 144 } 138 145 return ret; 139 146 } -
hvcontrol/src/HV.h
r100 r113 46 46 int LastWrapCount; 47 47 double fTimeOut; // [s] timeout to return from read 48 48 int ErrorCount; 49 49 50 char *BoardName; 50 51 int HV[NUM_CHAINS][NUM_CHANNELS]; // HV value in DAC units -
hvcontrol/src/ProcessIO.cc
r112 r113 163 163 config->NumHVBoards); 164 164 for (int i=0; i<config->NumHVBoards; i++) { 165 PrintMessage(" Board %d: %s\n 165 PrintMessage(" Board %d: %s\n", i, config->fUSBDevice[i]); 166 166 } 167 167 PrintMessage( " TimeOut: %.2f s\n" … … 439 439 PrintMessage(" Socket state: %s\n", Socket==-1 ? "disconnected":"connected"); 440 440 PrintMessage(" Total number of HV boards: %d\n", NumHVBoards); 441 PrintMessage(" Active HV boards: %d\n\n 441 PrintMessage(" Active HV boards: %d\n\n", LastBoard - FirstBoard + 1); 442 442 443 443 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", 445 445 fHVBoard[i]->GetBoardNumber(), fHVBoard[i]->BoardName, 446 446 fHVBoard[i]->WrapOK ? "ok":"error", 447 447 fHVBoard[i]->LastWrapCount, 448 448 fHVBoard[i]->ResetButton ? "yes" : "no", 449 fHVBoard[i]->fTimeOut); 449 fHVBoard[i]->fTimeOut, 450 fHVBoard[i]->ErrorCount); 450 451 451 452 for (int j=FirstChain; j<=LastChain; j++) { 452 PrintMessage(" CHAIN %d Over-current: %s\n 453 PrintMessage(" CHAIN %d Over-current: %s\n", j, fHVBoard[i]->Overcurrent[j] ? "yes" : "no"); 453 454 for (int k=0;k<4;k++) { 455 PrintMessage("\r"); 454 456 for (int l=0;l<8;l++) { 455 457 if(NParam == 2) PrintMessage("%5d ",fHVBoard[i]->HV[j][k*8+l]); 456 458 else PrintMessage("%#5.2f ",fHVBoard[i]->HVV[j][k*8+l]); 457 459 } 458 PrintMessage("\n 460 PrintMessage("\n"); 459 461 } 460 PrintMessage("\n ");461 462 } 462 463 } … … 554 555 va_list ArgumentPointer; 555 556 va_start(ArgumentPointer, Format); 556 PrintMessage(Format, ArgumentPointer, Target);557 DoPrintMessage(Format, ArgumentPointer, Target); 557 558 va_end(ArgumentPointer); 558 559 } … … 562 563 va_list ArgumentPointer; 563 564 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); 566 567 va_end(ArgumentPointer); 567 568 } 568 569 569 570 // 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! 572 void ProcessIO::DoPrintMessage(const char *Format, va_list ArgumentPointer, int Target) { 574 573 575 574 char Textbuffer[MAX_COM_SIZE]; … … 590 589 write(Socket, Textbuffer, strlen(Textbuffer)); 591 590 } 592 // Print to log file (rep ace carriage return by linefeed)591 // Print to log file (replace carriage return by linefeed) 593 592 if((Target & MsgToLog) && Logfile!=NULL) { 594 593 for (unsigned int i=0; i<strlen(Textbuffer); i++) { … … 630 629 631 630 632 // Check board status 631 // Check board status (ignore board if it has more than 10 read/write errors) 633 632 void ProcessIO::Monitor() { 634 633 635 static unsigned int MismatchCount, ErrorCount;634 static bool Warned = false; 636 635 637 636 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 } 638 644 639 645 if (fHVBoard[i]->GetStatus() != 1) { 640 646 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 }647 647 } 648 648 … … 653 653 654 654 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()); 657 656 } 658 657 -
hvcontrol/src/ProcessIO.h
r112 r113 65 65 void PrintMessage(int, const char *, ...); 66 66 void PrintMessage(const char *, ...); 67 void PrintMessage(const char *, va_list, int);67 void DoPrintMessage(const char *, va_list, int); 68 68 void CommandControl(char*); 69 69 bool RampVoltage(unsigned int, int, int, int);
Note:
See TracChangeset
for help on using the changeset viewer.