Ignore:
Timestamp:
08/12/09 12:15:02 (15 years ago)
Author:
ogrimm
Message:
Number of HV boards (almost) unlimited.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • hvcontrol/src/ProcessIO.cc

    r98 r100  
    3636  LastBoard   = -1;
    3737  FirstChain  = 0;
    38   LastChain   = 3;
     38  LastChain   = NUM_CHAINS-1;
    3939 
    4040  if (config->fStatusRefreshRate >= MIN_RATE && config->fStatusRefreshRate <= MAX_RATE)
     
    4343   
    4444  // Open HV devices
    45   if(config->TestMode){
    46     fprintf(stdout,"Test mode: One HVBoard initialized as dummy.\n");
    47     fHVBoard[NumHVBoards] = new HVBoard(0, 0, this);
    48     NumHVBoards++;
    49   }
    50   else {
    51     for (int i=0; i<config->NumHVBoards; i++) {
    52       fHVBoard[NumHVBoards] = new HVBoard(config->USBDeviceNumber[i], config->fUSBDevice[i], this);
    53       if(fHVBoard[NumHVBoards]->fDescriptor >= 0) {
    54          printf("Synchronized and reset HV board %d (%s)\n",i,config->fUSBDevice[i]);
    55          NumHVBoards++;
    56       }
    57       else {
    58         printf("Failed to synchronize to HV board %d (%s)\n",i,config->fUSBDevice[i]);
    59         delete fHVBoard[NumHVBoards];
    60       }
     45  fHVBoard = new HVBoard* [config->NumHVBoards];
     46  for (int i=0; i<config->NumHVBoards; i++) {
     47    fHVBoard[NumHVBoards] = new HVBoard(i, config->fUSBDevice[i], this);
     48    if(fHVBoard[NumHVBoards]->fDescriptor >= 0) {
     49       printf("Synchronized and reset HV board %d (%s)\n",i,config->fUSBDevice[i]);
     50       NumHVBoards++;
     51    }
     52    else {
     53      printf("Failed to synchronize to HV board %d (%s)\n",i,config->fUSBDevice[i]);
     54      delete fHVBoard[NumHVBoards];
    6155    }
    6256  }
     
    7973ProcessIO::~ProcessIO() {
    8074 
     75  delete SlowDataClass;     
     76
    8177  for (int i=0; i<NumHVBoards; i++) delete fHVBoard[i];
    82 
    83   delete SlowDataClass;   delete config;    delete pm;
     78  delete[] fHVBoard;
     79   
     80  delete pm;   delete calib;    delete config;   
    8481 
    8582  if(Logfile != NULL) {
    86     if(!fclose(Logfile)) printf("Closing logfile\n");
    87     else perror("Error closing logfile");
     83    if(fclose(Logfile) != 0) perror("Error closing logfile");
    8884  }
    8985}
     
    145141      LastChain = 3;
    146142    }
    147     else if (NParam==2 && atoi(Param[1])>=0 && atoi(Param[1])<4) {
     143    else if (NParam==2 && atoi(Param[1])>=0 && atoi(Param[1])<NUM_CHAINS) {
    148144      FirstChain = atoi(Param[1]);
    149145      LastChain = FirstChain;
    150146    }
    151     else if (NParam==3 && atoi(Param[1])>=0 && atoi(Param[1])<4 &&
    152            atoi(Param[2])>0 && atoi(Param[2])<4) {
     147    else if (NParam==3 && atoi(Param[1])>=0 && atoi(Param[1])<NUM_CHAINS &&
     148           atoi(Param[2])>0 && atoi(Param[2])<NUM_CHAINS) {
    153149      FirstChain = atoi(Param[1]);
    154150      LastChain = atoi(Param[2]);
     
    164160    PrintMessage( " Log file:          %s\n"
    165161                  " Pixel map table:   %s\n"
    166                   " Test mode:         %s\n"
    167162                  " %d USB devices:\n", config->fLogFile, config->fPixMapTable,
    168                   config->TestMode ? "yes" : "no", config->NumHVBoards); 
    169     for (int i=0;i<NumHVBoards;i++) {
    170       PrintMessage(" Board%d: %s\n ", config->USBDeviceNumber[i], config->fUSBDevice[i]);
    171     }
    172     PrintMessage( "\n TimeOut:           %.2f s\n"
     163                  config->NumHVBoards); 
     164    for (int i=0; i<config->NumHVBoards; i++) {
     165      PrintMessage(" Board %d: %s\n ", i, config->fUSBDevice[i]);
     166    }
     167    PrintMessage( " TimeOut:           %.2f s\n"
    173168                  " StatusRefreshRate: %.2f Hz\n"
    174169                  " CCPort:            %d\n"
     
    211206
    212207
    213   // Set new high voltage --------------------------------------------------------------------------------------
     208  // Set new high voltage (if no boards available, simply returns OK)
     209  // First reponse to socket should be 'OK' if no error occurred.
    214210  if (Match(Param[0], "hv") || Match(Param[0], "hvdiff")) {
    215211
    216     if (!NumHVBoards) return;
    217 
    218     int hvoltage, DACValue, Errors=0, Board, Chain=0, Channel=0;
     212    int hvoltage, DACValue, Errors=0, Board=-1, Chain=-1, Channel=-1;
    219213    double hvoltageV;
    220     bool allchannels = false, SetDac = false;
    221    
    222     // Need two parameters or three if last is 'dac'
     214    bool SetDac;
     215   
     216    // Need two or parameters
    223217    if (NParam<3 || NParam>4) {
    224       PrintMessage("ERROR - usage: hv <channel>|<all> <voltage> [dac]\n");
    225       return;
    226     }
    227 
    228     if (NParam==4 && Match(Param[3], "dac")) SetDac = true;
    229    
     218      PrintMessage("Usage: hv/hvdiff <channel>|<all> <voltage> [dac]\n");
     219      return;
     220    }
     221
     222    // Evaluate voltage parameter
     223    if (NParam==4 && Match(Param[3], "dac")) {
     224      SetDac = true;
     225      if (!ConvertToInt(Param[2], &hvoltage)) {
     226        PrintMessage("Error: Wrong number format for DAC voltage setting\n");
     227        return;
     228      }
     229    }
     230    else {
     231      SetDac = false;
     232      if (!ConvertToDouble(Param[2], &hvoltageV)) {
     233        PrintMessage("Error: Wrong number format for voltage setting\n");
     234        return;
     235      }
     236    }
     237
    230238    // Evaluate pixel or channel parameter   
    231     if((Board = pm->Pixel_to_HVboard(Param[1])) != 999999999) {
     239    if(pm->Pixel_to_HVboard(Param[1]) != 999999999) {
     240      Board = pm->Pixel_to_HVboard(Param[1]);
    232241      Chain = pm->Pixel_to_HVchain(Param[1]);
    233242      Channel = pm->Pixel_to_HVchannel(Param[1]);
    234243    }
    235     else if (Match(Param[1], "all")) allchannels = true;
    236     else if (ConvertToInt(Param[1], &Channel)) {
    237       Board = -1;
    238       Chain = -1;
    239     }
    240     else {
    241       PrintMessage("ERROR - wrong input format - usage: hv <channel>|<all> <voltage>\n");
    242       return;
    243     }
    244     // Check channel limits (voltage limit is only checked in SetHV())
    245     if (Channel<0 || Channel>31) {
    246       PrintMessage("ERROR - channel out of range (0...31)!\n");
    247       return;
    248     }
    249 
    250     if (SetDac && !ConvertToInt(Param[2], &hvoltage)) {
    251       PrintMessage("ERROR - wrong number format for DAC voltage setting\n");
    252       return;
    253     }
    254     if (!SetDac && !ConvertToDouble(Param[2], &hvoltageV)) {
    255       PrintMessage("ERROR - wrong number format for voltage setting\n");
    256       return;
    257     }
     244    else if (!Match(Param[1], "all") && !ConvertToInt(Param[1], &Channel)) {
     245      PrintMessage("Error: Wrong channel identification\n");
     246      return;
     247    }
    258248
    259249    for (int i=FirstBoard; i<=LastBoard; i++) {
    260       if (!allchannels && Board != 999999999 && i != Board && Board!=-1) continue;
     250      if (i!=Board && Board!=-1) continue;
    261251
    262252      for (int j=FirstChain; j<=LastChain; j++) {
    263         if (!allchannels && Chain != 999999999 && j != Chain && Chain!=-1) continue;
     253        if (j!=Chain && Chain!=-1) continue;
    264254
    265255        for (int k=0; k<NUM_CHANNELS; k++) {
    266           if (!allchannels && k!= Channel) continue;
     256          if (k!=Channel && Channel!=-1) continue;
    267257
    268258          // Convert from HV to DAC values
     
    277267          }
    278268         
    279           // Set new voltage (if DAC value, update calilbrated value)
     269          // Set new voltage (if DAC value, update calibrated value)
    280270          if(!RampVoltage(DACValue, i, j, k)) Errors++;
    281           else if(SetDac) fHVBoard[i]->HVV[j][k] = calib->DACToHV(fHVBoard[i]->HV[j][k], i, j, k);
     271          if(SetDac) fHVBoard[i]->HVV[j][k] = calib->DACToHV(fHVBoard[i]->HV[j][k], i, j, k);
    282272
    283273        } // Channels   
     
    285275    } // Boards
    286276
    287     if (Errors > 0) PrintMessage("Warning: Errors on %d channel(s) occurred\n", Errors);
    288     else PrintMessage("OK - no error(s)\n");
     277    if (Errors > 0) PrintMessage("ERROR - Errors on %d channel(s) occurred\n", Errors);
     278    else PrintMessage("OK - no errors\n");
    289279   
    290280    return;
     
    436426    state = active;
    437427    pthread_kill(HVMonitor, SIGUSR1);
    438     PrintMessage("OK - status monitoring activated\n");
     428    PrintMessage("Status monitoring activated\n");
    439429    return; 
    440430  }
     
    617607
    618608    if (fHVBoard[Board]->SetHV(Chain, Channel, fHVBoard[Board]->HV[Chain][Channel]+Diff) == 1) {
    619       fHVBoard[Board]->HV[Chain][Channel] += Diff;
    620 
    621609      if (Verbose) {
    622         PrintMessage("OK - board %d: high voltage of chain %d channel %d set to %d | 0X%.4X | %f V\n",fHVBoard[Board]->GetBoardNumber(),Chain, Channel, Target, Target, calib->DACToHV(Target,fHVBoard[Board]->GetBoardNumber(),Chain,Channel));
     610        PrintMessage("Board %d: high voltage of chain %d channel %d set to %d | 0X%.4X | %f V\n",fHVBoard[Board]->GetBoardNumber(),Chain, Channel, Target, Target, calib->DACToHV(Target,fHVBoard[Board]->GetBoardNumber(),Chain,Channel));
    623611        PrintBoardStatus(Board);
    624612      }
    625613    }
    626614    else {
    627       PrintMessage("ERROR - Could not set HV of board %d, chain %d, channel %d. Skipping channel\n",fHVBoard[Board]->GetBoardNumber(),Chain,Channel);
    628       SlowDataClass->NewEntry("Error");
    629       SlowDataClass->AddToEntry("%s %d %d %d %d %.2f ",fHVBoard[Board]->BoardName,Board, Chain, Channel, Target, calib->DACToHV(Target,Board,Chain,Channel));
     615      PrintMessage("Error: Could not set HV of board %d, chain %d, channel %d. Skipping channel\n",fHVBoard[Board]->GetBoardNumber(),Chain,Channel);
     616      //SlowDataClass->NewEntry("Error");
     617      //SlowDataClass->AddToEntry("%s %d %d %d %d %.2f ",fHVBoard[Board]->BoardName,Board, Chain, Channel, Target, calib->DACToHV(Target,Board,Chain,Channel));
    630618      return false;
    631619    }
    632620  }
    633   SlowDataClass->NewEntry("Value");
    634   SlowDataClass->AddToEntry("%s %d %d %d %d %.2f ",fHVBoard[Board]->BoardName,Board, Chain, Channel, Target, calib->DACToHV(Target,Board,Chain,Channel));
     621  //SlowDataClass->NewEntry("Value");
     622  //SlowDataClass->AddToEntry("%s %d %d %d %d %.2f ",fHVBoard[Board]->BoardName,Board, Chain, Channel, Target, calib->DACToHV(Target,Board,Chain,Channel));
    635623  return true;
    636624}
     
    676664}
    677665
    678 
    679 // Get index of board with sequential number board
    680 int ProcessIO::GetBoardIdx(int board) {
    681 
    682   for (int i=0; i<MAX_NUM_HVBOARDS; i++) {
    683     if (board == fHVBoard[i]->GetBoardNumber()) return i;
    684   }
    685   return -1;
    686 }
    687666
    688667// Print current board status
Note: See TracChangeset for help on using the changeset viewer.