Changeset 98 for hvcontrol


Ignore:
Timestamp:
07/29/09 08:50:44 (15 years ago)
Author:
ogrimm
Message:
Fixed bug with loading of HV settings. Negative DAC values are set to zero without error.
Location:
hvcontrol
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • hvcontrol/History.txt

    r93 r98  
    191924/7/2009   Lockfile is deleted if configuration file cannot be read
    202027/7/2009   Slow data is written for every HV ramp to file given in configuration
     2129/7/2009   Fixed bug with loading HV settings. No error is produced on negative
     22            DAC values (the value is set to zero).
  • hvcontrol/src/HV.cc

    r93 r98  
    162162
    163163/* Set high voltage - uses TRead() and has same return values */
    164 int HVBoard::SetHV(int chain, unsigned int channel, unsigned int hv) {
     164int HVBoard::SetHV(int chain, unsigned int channel, int hv) {
    165165
    166166  if (fTestMode){
     
    171171  unsigned char wbuf[] = {0,0,0};
    172172
    173   if (!(hv>=0 && hv<=0x3FFF)) {
    174     m->PrintMessage(" Error: HV beyond limits [0 - 0x3FFF]\n");
    175     return 0;
    176   }
     173  if (hv > 0x3FFF) {
     174    m->PrintMessage(" Error: HV beyond upper 0x3FFF\n");
     175    return 0;
     176  }
     177  if (hv<0) hv = 0;
    177178 
    178179  switch (chain) {
  • hvcontrol/src/HV.h

    r93 r98  
    5656   int Reset();
    5757   int GetStatus();
    58    int SetHV(int, unsigned int, unsigned int);
     58   int SetHV(int, unsigned int, int);
    5959   int GetBoardNumber() {return BoardNumber;}
    6060   int Communicate(unsigned char*, int);
  • hvcontrol/src/ProcessIO.cc

    r93 r98  
    296296
    297297    char Buffer[MAX_COM_SIZE];
    298     int NBoards = 0, Errors = 0, Chain;
     298    int NBoards = 0, Errors = 0, Chain, Channel;
    299299    unsigned int DACValue;
    300300    FILE *File;
     
    313313      for (int Board=0; Board<NumHVBoards; Board++) {
    314314        if (Match(fHVBoard[Board]->BoardName, Buffer)) {
    315 
    316           PrintMessage("Found HV settings for board %d (%s)\n",fHVBoard[Board]->GetBoardNumber(), fHVBoard[Board]->BoardName);
    317 
    318           Chain = 0;
    319           while (fgets(Buffer, sizeof(Buffer), File) && Chain<NUM_CHAINS) {
    320             if (strlen(Buffer) == 1) continue;  // Ignore if only newline character
    321 
    322             for (int Channel=0; Channel<NUM_CHANNELS; Channel++) {
    323               if (sscanf(Buffer, "%u", &DACValue) != 1) {
    324                 PrintMessage("Error reading DAC values from file, terminating\n");
    325                 return;
    326               }       
    327               if (!RampVoltage(DACValue, Board, Chain, Channel)) Errors++;
     315          PrintMessage("Found HV settings for board %d (%s)\n\r",fHVBoard[Board]->GetBoardNumber(), fHVBoard[Board]->BoardName);
     316
     317          Chain = 0;  Channel = 0;
     318          while (fscanf(File, "%u", &DACValue)==1 && Chain<NUM_CHAINS) {
     319            if (!RampVoltage(DACValue, Board, Chain, Channel)) {
     320              Errors++;
     321              PrintMessage("Error: Could not ramp chain %d, channel %d\n", Chain, Channel);
     322            }
     323            else {
     324              PrintMessage("Ramped chain %d, channel %d to %u (%.2f V)                         \r",
     325                 Chain,Channel,DACValue,calib->DACToHV(DACValue,Board,Chain,Channel));
     326            }
     327            fHVBoard[Board]->HVV[Chain][Channel] = calib->DACToHV(fHVBoard[Board]->HV[Chain][Channel], Board, Chain, Channel);
     328            if(++Channel == NUM_CHANNELS) {
     329              Chain++;
     330              Channel = 0;
    328331            }
    329             Chain++;
    330332          }
    331           PrintMessage("Finished updating board.\n");
     333          if (ferror(File) != 0) {
     334            PrintMessage("Error reading DAC value from file, terminating. (%s)\n",strerror(errno));
     335            return;
     336          }
     337          else PrintMessage("\nFinished updating board\n");
    332338          NBoards++;
    333339        }
     
    583589    if(strlen(Textbuffer)>0 && Textbuffer[strlen(Textbuffer)-1]=='\n') {
    584590      printf("\r%s%s", Textbuffer, Prompt);   // New prompt
    585       fflush(stdout);
    586591    }
    587592    else printf("%s", Textbuffer);
    588   }
    589   // Print to log file
    590   if((Target & MsgToLog) && Logfile!=NULL) {
    591     fprintf(Logfile, "%s", Textbuffer);
    592     fflush(Logfile);
     593    fflush(stdout);
    593594  }
    594595  // Print to socket
    595596  if((Target & MsgToSocket) && Socket!=-1) {
    596597    write(Socket, Textbuffer, strlen(Textbuffer));
     598  }
     599  // Print to log file (repace carriage return by linefeed)
     600  if((Target & MsgToLog) && Logfile!=NULL) {
     601    for (unsigned int i=0; i<strlen(Textbuffer); i++) {
     602      if(Textbuffer[i] == '\r') Textbuffer[i] = '\n';
     603    }
     604    fprintf(Logfile, "%s", Textbuffer);
     605    fflush(Logfile);
    597606  }
    598607}
Note: See TracChangeset for help on using the changeset viewer.