Changeset 100 for hvcontrol/src/ProcessIO.cc
- Timestamp:
- 08/12/09 12:15:02 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
hvcontrol/src/ProcessIO.cc
r98 r100 36 36 LastBoard = -1; 37 37 FirstChain = 0; 38 LastChain = 3;38 LastChain = NUM_CHAINS-1; 39 39 40 40 if (config->fStatusRefreshRate >= MIN_RATE && config->fStatusRefreshRate <= MAX_RATE) … … 43 43 44 44 // 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]; 61 55 } 62 56 } … … 79 73 ProcessIO::~ProcessIO() { 80 74 75 delete SlowDataClass; 76 81 77 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; 84 81 85 82 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"); 88 84 } 89 85 } … … 145 141 LastChain = 3; 146 142 } 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) { 148 144 FirstChain = atoi(Param[1]); 149 145 LastChain = FirstChain; 150 146 } 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) { 153 149 FirstChain = atoi(Param[1]); 154 150 LastChain = atoi(Param[2]); … … 164 160 PrintMessage( " Log file: %s\n" 165 161 " Pixel map table: %s\n" 166 " Test mode: %s\n"167 162 " %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( " \nTimeOut: %.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" 173 168 " StatusRefreshRate: %.2f Hz\n" 174 169 " CCPort: %d\n" … … 211 206 212 207 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. 214 210 if (Match(Param[0], "hv") || Match(Param[0], "hvdiff")) { 215 211 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; 219 213 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 223 217 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 230 238 // 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]); 232 241 Chain = pm->Pixel_to_HVchain(Param[1]); 233 242 Channel = pm->Pixel_to_HVchannel(Param[1]); 234 243 } 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 } 258 248 259 249 for (int i=FirstBoard; i<=LastBoard; i++) { 260 if ( !allchannels && Board != 999999999 && i !=Board && Board!=-1) continue;250 if (i!=Board && Board!=-1) continue; 261 251 262 252 for (int j=FirstChain; j<=LastChain; j++) { 263 if ( !allchannels && Chain != 999999999 && j !=Chain && Chain!=-1) continue;253 if (j!=Chain && Chain!=-1) continue; 264 254 265 255 for (int k=0; k<NUM_CHANNELS; k++) { 266 if ( !allchannels && k!= Channel) continue;256 if (k!=Channel && Channel!=-1) continue; 267 257 268 258 // Convert from HV to DAC values … … 277 267 } 278 268 279 // Set new voltage (if DAC value, update cali lbrated value)269 // Set new voltage (if DAC value, update calibrated value) 280 270 if(!RampVoltage(DACValue, i, j, k)) Errors++; 281 elseif(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); 282 272 283 273 } // Channels … … 285 275 } // Boards 286 276 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"); 289 279 290 280 return; … … 436 426 state = active; 437 427 pthread_kill(HVMonitor, SIGUSR1); 438 PrintMessage(" OK - status monitoring activated\n");428 PrintMessage("Status monitoring activated\n"); 439 429 return; 440 430 } … … 617 607 618 608 if (fHVBoard[Board]->SetHV(Chain, Channel, fHVBoard[Board]->HV[Chain][Channel]+Diff) == 1) { 619 fHVBoard[Board]->HV[Chain][Channel] += Diff;620 621 609 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)); 623 611 PrintBoardStatus(Board); 624 612 } 625 613 } 626 614 else { 627 PrintMessage("E RROR -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)); 630 618 return false; 631 619 } 632 620 } 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)); 635 623 return true; 636 624 } … … 676 664 } 677 665 678 679 // Get index of board with sequential number board680 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 }687 666 688 667 // Print current board status
Note:
See TracChangeset
for help on using the changeset viewer.