Changeset 229 for hvcontrol/src/HV.cc


Ignore:
Timestamp:
06/24/10 07:51:15 (14 years ago)
Author:
ogrimm
Message:
Config requests non-blocking if not made from main thread, adapted all servers to GetConfig() returning std::string, workaround for erroneous SERVICE_LIST
File:
1 edited

Legend:

Unmodified
Added
Removed
  • hvcontrol/src/HV.cc

    r220 r229  
    1414#include "ProcessIO.h" // Must be not in HV.h to avoid problem with declaring class ProcessIO
    1515
     16using namespace std;
     17
    1618// Constructor
    17 HVBoard::HVBoard(int DeviceNumber, char *DeviceName, class ProcessIO *PIO) {
     19HVBoard::HVBoard(int DeviceNumber, string Name, class ProcessIO *PIO) {
    1820   
    19   char *Buffer;
    2021  struct termios tio;
    2122 
    2223  m = PIO;
    23 
    2424  SetTimeOut(m->fTimeOut);
    2525  BoardNumber = DeviceNumber;
    26   BoardName = DeviceName;
    27  
     26  BoardName = new char [Name.size()+1];
     27  strcpy(BoardName, Name.c_str());
     28 
     29  stringstream Buf;
     30  Buf << setw(2) << BoardNumber;
     31  string Result =Buf.str();
     32
    2833  // Create DIM services
    29   if (asprintf(&Buffer, SERVER_NAME"/NAME/ID%.2d", BoardNumber) == -1) {
    30     m->PrintMessage(All, "asprintf() failed for DIM service name creation\n");
    31         return;
    32   }
    33   Name = new DimService (Buffer, BoardName);
    34   free(Buffer);
    35  
    36   if (asprintf(&Buffer, SERVER_NAME"/VOLT/ID%.2d", BoardNumber) == -1) {
    37     m->PrintMessage(All, "asprintf() failed for DIM service name creation\n");
    38         return;
    39   }
    40   BiasVolt = new DimService (Buffer, "D", HVV, NUM_CHAINS*NUM_CHANNELS*sizeof(double));
    41   free(Buffer);
     34  NameService = new DimService ((SERVER_NAME"/NAME/ID"+Result).c_str(), BoardName);
     35  BiasVolt = new DimService ((char *) (SERVER_NAME"/VOLT/ID"+Result).c_str(), (char *) "D", HVV, NUM_CHAINS*NUM_CHANNELS*sizeof(double));
    4236
    4337  for (int i=0; i<NUM_CHAINS; i++) Overcurrent[i] = false;
     
    4943  ClearVoltageArrays();
    5044
    51   // Open device (do not warn on non-existing device)
    52   if (asprintf(&Buffer, "/dev/%s",DeviceName) == -1) {
    53     m->PrintMessage(All, "asprintf() failed for device name creation\n");
    54         return;
    55   }
    56   if ((fDescriptor = open(Buffer, O_RDWR|O_NOCTTY|O_NDELAY)) == -1) {
    57     if(errno != 2) m->PrintMessage(All, "Error: Could not open device %d/%s (%s)\n", DeviceNumber,DeviceName, strerror(errno));
    58         free(Buffer);
     45  if ((fDescriptor = open(("/dev/"+Name).c_str(), O_RDWR|O_NOCTTY|O_NDELAY)) == -1) {
     46    if(errno != 2) m->PrintMessage(All, "Error: Could not open device %d/%s (%s)\n", DeviceNumber, Name.c_str(), strerror(errno));
    5947    return;
    6048  }
    61   free(Buffer);
    6249
    6350  // Get current serial port settings
     
    9683  }
    9784
    98   delete Name;
     85  delete NameService;
    9986  delete BiasVolt;
     87  delete[] BoardName;
    10088}
    10189
Note: See TracChangeset for help on using the changeset viewer.