diff --git a/slsDetectorSoftware/eigerDetectorServer/9mhvserial_bf.c b/slsDetectorSoftware/eigerDetectorServer/9mhvserial_bf.c new file mode 100644 index 000000000..4e4ee0ac6 --- /dev/null +++ b/slsDetectorSoftware/eigerDetectorServer/9mhvserial_bf.c @@ -0,0 +1,187 @@ +#include "ansi.h" + +#include /* POSIX terminal control definitions */ +#include +#include // atoi +#include // File control definitions +#include // ioctl +#include // read, close +#include // memset +#include // I2C_SLAVE, __u8 reg + +#define PORTNAME "/dev/ttyBF1" +#define GOODBYE 200 +#define BUFFERSIZE 16 +#define I2C_DEVICE_FILE "/dev/i2c-0" +#define I2C_DEVICE_ADDRESS 0x4C +//#define I2C_DEVICE_ADDRESS 0x48 +#define I2C_REGISTER_ADDRESS 0x40 + + + +int i2c_open(const char* file,unsigned int addr){ + + //device file + int fd = open( file, O_RDWR ); + if (fd < 0) { + cprintf(RED,"Warning: Unable to open file %s\n",file); + return -1; + } + + //device address + if( ioctl( fd, I2C_SLAVE, addr&0x7F ) < 0 ) { + cprintf(RED,"Warning: Unable to set slave address:0x%x \n",addr); + return -2; + } + return fd; +} + + +int i2c_read(){ + + int fd = i2c_open(I2C_DEVICE_FILE, I2C_DEVICE_ADDRESS); + __u8 reg = I2C_REGISTER_ADDRESS & 0xff; + + unsigned char buf = reg; + if (write(fd, &buf, 1)!= 1){ + cprintf(RED,"Warning: Unable to write read request to register %d\n", reg); + return -1; + } + //read and update value (but old value read out) + if(read(fd, &buf, 1) != 1){ + cprintf(RED,"Warning: Unable to read register %d\n", reg); + return -2; + } + //read again to read the updated value + if(read(fd, &buf, 1) != 1){ + cprintf(RED,"Warning: Unable to read register %d\n", reg); + return -2; + } + close(fd); + return buf; +} + + +int i2c_write(unsigned int value){ + + __u8 val = value & 0xff; + + int fd = i2c_open(I2C_DEVICE_FILE, I2C_DEVICE_ADDRESS); + if(fd < 0) + return fd; + + __u8 reg = I2C_REGISTER_ADDRESS & 0xff; + char buf[3]; + buf[0] = reg; + buf[1] = val; + if (write(fd, buf, 2) != 2) { + cprintf(RED,"Warning: Unable to write %d to register %d\n",val, reg); + return -1; + } + + close(fd); + return 0; +} + + + + + +int main(int argc, char* argv[]) { + + int fd = open(PORTNAME, O_RDWR | O_NOCTTY); + if(fd < 0){ + cprintf(RED,"Warning: Unable to open port %s\n", PORTNAME); + return -1; + } + + struct termios serial_conf; + // Get the current options for the port + tcgetattr(fd, &serial_conf); + // reset structure + memset(&serial_conf,0,sizeof(serial_conf)); + // control options + serial_conf.c_cflag = B2400 | CS8 | CREAD | CLOCAL; + // input options + serial_conf.c_iflag = IGNPAR; + // output options + serial_conf.c_oflag = 0; + // line options + serial_conf.c_lflag = ICANON; + // flush input + tcflush(fd, TCIFLUSH); + // set new options for the port, TCSANOW:changes occur immediately without waiting for data to complete + tcsetattr(fd, TCSANOW, &serial_conf); + + + + + int ret = 0; + int n = 0; + int ival= 0; + char buffer[BUFFERSIZE]; + buffer[BUFFERSIZE-2] = '\0'; + buffer[BUFFERSIZE-1] = '\n'; + cprintf(GREEN,"Ready...\n"); + + while(ret != GOODBYE){ + n = read(fd,buffer,BUFFERSIZE); +#ifdef VERBOSE + cprintf(BLUE,"Received %d Bytes\n", n); +#endif + cprintf(BLUE,"Got message: %s\n",buffer); + + switch(buffer[0]){ + case 'p': + if (!sscanf(&buffer[1],"%d",&ival)){ + cprintf(RED,"Warning: cannot scan voltage value\n"); + break; + } + + if(i2c_write(ival)<0) + strcpy(buffer,"fail "); + else + strcpy(buffer,"success "); + cprintf(GREEN,"%s\n",buffer); + n = write(fd, buffer, BUFFERSIZE); +#ifdef VERBOSE + cprintf(BLUE,"Sent %d Bytes\n", n); +#endif + break; + + case 'g': + ival = i2c_read(); + //ok/ fail + if(ival < 0) + strcpy(buffer,"fail "); + else + strcpy(buffer,"success "); + n = write(fd, buffer, BUFFERSIZE); +#ifdef VERBOSE + cprintf(BLUE,"Sent %d Bytes\n", n); +#endif + //value + if(ival >= 0){ + cprintf(GREEN,"%d\n",ival); + sprintf(buffer,"%d ",ival); + n = write(fd, buffer, BUFFERSIZE); +#ifdef VERBOSE + cprintf(BLUE,"Sent %d Bytes\n", n); +#endif + }else cprintf(GREEN,"%s\n",buffer); + break; + + case 'e': + printf("Exiting Program\n"); + ret = GOODBYE; + break; + default: + printf("Unknown Command. buffer:%s\n",buffer); + break; + } + } + + close(fd); + printf("Goodbye Serial Communication for HV(9M)\n"); + return 0; +} diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.c b/slsDetectorSoftware/eigerDetectorServer/FebControl.c index 1786f16a3..ead19d2b7 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.c +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.c @@ -12,13 +12,7 @@ #include #include #include - -//#include -//#include -//#include -//#include - - +#include // POSIX terminal control definitions(CS8, CREAD, CLOCAL..) #include "FebRegisterDefs.h" #include "FebControl.h" @@ -68,6 +62,7 @@ double Feb_Control_rate_meas[16384]; double ratemax=-1; int Feb_Control_activated = 1; +int Feb_Control_hv_fd = -1; void Module_Module(struct Module* mod,unsigned int number, unsigned int address_top){ @@ -224,10 +219,45 @@ int Feb_Control_Init(int master, int top, int normal, int module_num){ if(Feb_Control_activated) Feb_Interface_SetByteOrder(); + return 1; +} + + +int Feb_Control_OpenSerialCommunication(){ + cprintf(BG_BLUE,"opening serial communication of hv\n"); + if(Feb_Control_hv_fd != -1) + close(Feb_Control_hv_fd); + Feb_Control_hv_fd = open(SPECIAL9M_HIGHVOLTAGE_PORT, O_RDWR | O_NOCTTY); + if(Feb_Control_hv_fd < 0){ + cprintf(RED,"Warning: Unable to open port %s to set up high voltage serial communciation to the blackfin\n", SPECIAL9M_HIGHVOLTAGE_PORT); + return 0; + } + + struct termios serial_conf; + // Get the current options for the port + tcgetattr(Feb_Control_hv_fd, &serial_conf); + // reset structure + memset(&serial_conf,0,sizeof(serial_conf)); + // control options + serial_conf.c_cflag = B2400 | CS8 | CREAD | CLOCAL;//57600 too high + // input options + serial_conf.c_iflag = IGNPAR; + // output options + serial_conf.c_oflag = 0; + // line options + serial_conf.c_lflag = ICANON; + // flush input + tcflush(Feb_Control_hv_fd, TCIFLUSH); + // set new options for the port, TCSANOW:changes occur immediately without waiting for data to complete + tcsetattr(Feb_Control_hv_fd, TCSANOW, &serial_conf); return 1; } +void Feb_Control_CloseSerialCommunication(){ + if(Feb_Control_hv_fd != -1) + close(Feb_Control_hv_fd); +} void Feb_Control_PrintModuleList(){ @@ -347,7 +377,8 @@ int Feb_Control_CheckSetup(int master){ ok=0; } } - if((Feb_control_master) &&(Module_GetHighVoltage(&modules[i])<0)){ + int value = 0; + if((Feb_control_master) && (!Feb_Control_GetHighVoltage(&value))){ cprintf(RED,"Warning: module %d's high voltage not set.\n",Module_GetModuleNumber(&modules[i])); ok=0; } @@ -496,89 +527,191 @@ float Feb_Control_DACToVoltage(unsigned int digital,unsigned int nsteps,float vm //only master gets to call this function int Feb_Control_SetHighVoltage(int value){ - - if(!Feb_control_normal){ - cprintf(RED,"\nError: Setting High Voltage not implemented for special modules\n"); - return 0; - } - - printf(" Setting High Voltage: %d(v)\t",value); - - static const unsigned int nsteps = 256; - static const float vmin=0; - static const float vmax=300; + printf(" Setting High Voltage:\t"); + /* + * maximum voltage of the hv dc/dc converter: + * 300 for single module power distribution board + * 200 for 9M power distribution board + * but limit is 200V for both + */ + const float vmin=0; + float vmax=200; + if(Feb_control_normal) + vmax=300; + const float vlimit=200; + const unsigned int ntotalsteps = 256; + unsigned int nsteps = ntotalsteps*vlimit/vmax; unsigned int dacval = 0; - //open file - FILE* fd=fopen("/sys/class/hwmon/hwmon5/device/out0_output","w"); - if(fd==NULL){ - cprintf(RED,"\nWarning: Could not open file for writing to set high voltage\n"); - return 0; - } //calculate dac value - if(!Feb_Control_VoltageToDAC(value,&dacval,nsteps,vmin,vmax)){ - cprintf(RED,"\nWarning: SetHighVoltage bad value, %d. The range is 0 to 300 V.\n",value); - return 0; + if(!Feb_Control_VoltageToDAC(value,&dacval,nsteps,vmin,vlimit)){ + cprintf(RED,"\nWarning: SetHighVoltage bad value, %d. The range is 0 to %d V.\n",value, (int)vlimit); + return -1; } - //convert to string, add 0 and write to file - fprintf(fd, "%d0\n", dacval); + printf("(%d dac):\t%dV\n", dacval, value); - printf("%d(dac)\n", dacval); - fclose(fd); - - return 1; + return Feb_Control_SendHighVoltage(dacval); } int Feb_Control_GetHighVoltage(int* value){ - - if(!Feb_control_normal){ - cprintf(RED,"\nError: Getting High Voltage not implemented for special modules\n"); - return 0; - } - - printf(" Getting High Voltage: "); - static const unsigned int nsteps = 256; - static const float vmin=0; - static const float vmax=300; - + printf(" Getting High Voltage:\t"); unsigned int dacval = 0; - size_t readbytes=0; - char* line=NULL; + if(!Feb_Control_ReceiveHighVoltage(&dacval)) + return 0; - //open file - FILE* fd=fopen("/sys/class/hwmon/hwmon5/device/in0_input","r"); - if(fd==NULL){ - cprintf(RED,"\nWarning: Could not open file for writing to get high voltage\n"); - return 0; - } - // Read twice, since the first value is sometimes outdated - if(getline(&line, &readbytes, fd) == -1){ - cprintf(RED,"\nWarning: could not read file to get high voltage\n"); - return 0; - } - rewind(fd); - free(line); - readbytes=0; - readbytes = getline(&line, &readbytes, fd); - if(readbytes == -1){ - cprintf(RED,"\nWarning: could not read file to get high voltage\n"); - return 0; - } - - // Remove the trailing 0 - dacval = atoi(line)/10; - //convert dac to v - *value = (int)(Feb_Control_DACToVoltage(dacval,nsteps,vmin,vmax)+0.5); - printf("%d(v)\t%d(dac)\n", *value, dacval); - free(line); - fclose(fd); + //ok, convert dac to v + /* + * maximum voltage of the hv dc/dc converter: + * 300 for single module power distribution board + * 200 for 9M power distribution board + * but limit is 200V for both + */ + const float vmin=0; + float vmax=200; + if(Feb_control_normal) + vmax=300; + const float vlimit=200; + const unsigned int ntotalsteps = 256; + unsigned int nsteps = ntotalsteps*vlimit/vmax; + *value = (int)(Feb_Control_DACToVoltage(dacval,nsteps,vmin,vlimit)+0.5); + printf("(%d dac)\t%dV\n", dacval, *value); return 1; } +int Feb_Control_SendHighVoltage(int dacvalue){ + //normal + if(Feb_control_normal){ + //open file + FILE* fd=fopen(NORMAL_HIGHVOLTAGE_OUTPUTPORT,"w"); + if(fd==NULL){ + cprintf(RED,"\nWarning: Could not open file for writing to set high voltage\n"); + return 0; + } + //convert to string, add 0 and write to file + fprintf(fd, "%d0\n", dacvalue); + fclose(fd); + } + + //9m + else{ + /*Feb_Control_OpenSerialCommunication();*/ + if (Feb_Control_hv_fd == -1){ + cprintf(RED,"\nWarning: High voltage serial communication not set up for 9m\n"); + return 0; + } + + char buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE]; + buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-2]='\0'; + buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1]='\n'; + int n = 0; + sprintf(buffer,"p%d ",dacvalue); + n = write(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE); +#ifdef VERBOSEI + cprintf(BLUE,"Sent %d Bytes\n", n); +#endif + //ok/fail + n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE); +#ifdef VERBOSEI + cprintf(BLUE,"Received %d Bytes\n", n); +#endif + fflush(stdout); + /*Feb_Control_CloseSerialCommunication();*/ + if(buffer[0] != 's'){ + cprintf(RED,"\nError: Failed to set high voltage\n"); + return 0; + } + cprintf(GREEN,"%s\n",buffer); + + } + + return 1; +} + + + + + + + +int Feb_Control_ReceiveHighVoltage(unsigned int* value){ + + //normal + if(Feb_control_normal){ + //open file + FILE* fd=fopen(NORMAL_HIGHVOLTAGE_INPUTPORT,"r"); + if(fd==NULL){ + cprintf(RED,"\nWarning: Could not open file for writing to get high voltage\n"); + return 0; + } + + //read, assigning line to null and readbytes to 0 then getline allocates initial buffer + size_t readbytes=0; + char* line=NULL; + if(getline(&line, &readbytes, fd) == -1){ + cprintf(RED,"\nWarning: could not read file to get high voltage\n"); + return 0; + } + //read again to read the updated value + rewind(fd); + free(line); + readbytes=0; + readbytes = getline(&line, &readbytes, fd); + if(readbytes == -1){ + cprintf(RED,"\nWarning: could not read file to get high voltage\n"); + return 0; + } + // Remove the trailing 0 + *value = atoi(line)/10; + free(line); + fclose(fd); + } + + + //9m + else{ + /*Feb_Control_OpenSerialCommunication();*/ + + if (Feb_Control_hv_fd == -1){ + cprintf(RED,"\nWarning: High voltage serial communication not set up for 9m\n"); + return 0; + } + char buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE]; + buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-2]='\0'; + buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1]='\n'; + int n = 0; + //request + strcpy(buffer,"g "); + n = write(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE); +#ifdef VERBOSEI + cprintf(BLUE,"Sent %d Bytes\n", n); +#endif + + //ok/fail + n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE); +#ifdef VERBOSEI + cprintf(BLUE,"Received %d Bytes\n", n); +#endif + if(buffer[0] != 's'){ + cprintf(RED,"\nWarning: failed to read high voltage\n"); + return 0; + } + + n = read(Feb_Control_hv_fd, buffer, SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE); +#ifdef VERBOSEI + cprintf(BLUE,"Received %d Bytes\n", n); +#endif + /*Feb_Control_OpenSerialCommunication();*/ + if (!sscanf(buffer,"%d",value)){ + cprintf(RED,"\nWarning: failed to scan high voltage read\n"); + return 0; + } + } + return 1; +} diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.h b/slsDetectorSoftware/eigerDetectorServer/FebControl.h index 620ab003a..fb75c8a67 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.h +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.h @@ -112,6 +112,8 @@ int Feb_Control_GetModuleNumber(); void Feb_Control_FebControl(); int Feb_Control_Init(int master, int top, int normal, int module_num); + int Feb_Control_OpenSerialCommunication(); + void Feb_Control_CloseSerialCommunication(); int Feb_Control_CheckSetup(); unsigned int Feb_Control_GetNModules(); @@ -120,6 +122,9 @@ int Feb_Control_GetModuleNumber(); int Feb_Control_SetHighVoltage(int value); int Feb_Control_GetHighVoltage(int* value); + int Feb_Control_SendHighVoltage(int dacvalue); + int Feb_Control_ReceiveHighVoltage(unsigned int* value); + int Feb_Control_SetIDelays(unsigned int module_num, unsigned int ndelay_units); int Feb_Control_SetIDelays1(unsigned int module_num, unsigned int chip_pos, unsigned int ndelay_units); diff --git a/slsDetectorSoftware/eigerDetectorServer/Makefile b/slsDetectorSoftware/eigerDetectorServer/Makefile index 462930bac..3a9cc6c59 100755 --- a/slsDetectorSoftware/eigerDetectorServer/Makefile +++ b/slsDetectorSoftware/eigerDetectorServer/Makefile @@ -1,6 +1,7 @@ CC = powerpc-4xx-softfloat-gcc CCX = powerpc-4xx-softfloat-g++ -CFLAGS += -Wall -DDACS_INT -DEIGERD -DSLS_DETECTOR_FUNCTION_LIST -DDACS_INT -DSTOP_SERVER #-DVERBOSE #-DVIRTUAL -DPCCOMPILE -DMARTIN +BLACKFIN_CC = bfin-uclinux-gcc +CFLAGS += -Wall -DDACS_INT -DEIGERD -DSLS_DETECTOR_FUNCTION_LIST -DDACS_INT -DSTOP_SERVER #-DVERBOSEI #-DVERBOSE #-DVIRTUAL -DPCCOMPILE -DMARTIN LDLIBS += -lm -lstdc++ PROGS = eigerDetectorServer @@ -15,7 +16,7 @@ SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c OBJS = $(SRC_CLNT:.c=.o) -all: clean $(PROGS) #feb_debug beb_debug +all: clean $(PROGS) hv9m_blackfin_server #feb_debug beb_debug boot: $(OBJS) @@ -33,7 +34,12 @@ feb_debug:$(SRC_CLNT2) beb_debug:$(SRC_CLNT3) $(CCX) -o beb_debug $(SRC_CLNT3) -I. mv beb_debug $(DESTDIR) + +hv9m_blackfin_server:9mhvserial_bf.c + $(BLACKFIN_CC) -o hv9m_blackfin_server 9mhvserial_bf.c -Wall #-DVERBOSE + mv hv9m_blackfin_server $(DESTDIR) + rm hv9m_blackfin_server.gdb clean: - rm -rf $(DESTDIR)/$(PROGS) *.o + rm -rf $(DESTDIR)/$(PROGS) *.o $(DESTDIR)/hv9m_blackfin_server diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.4 b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.5 similarity index 50% rename from slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.4 rename to slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.5 index 9eaa0aef8..9fdf4f404 100755 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.4 and b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.2.0.16.5 differ diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/hv9m_blackfin_server b/slsDetectorSoftware/eigerDetectorServer/bin/hv9m_blackfin_server new file mode 100755 index 000000000..a23826d2f Binary files /dev/null and b/slsDetectorSoftware/eigerDetectorServer/bin/hv9m_blackfin_server differ diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c index cb541697b..b675703c6 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c @@ -144,6 +144,11 @@ int initDetector(){ Feb_Interface_FebInterface(); Feb_Control_FebControl(); Feb_Control_Init(master,top,normal, getDetectorNumber()); + //master of 9M, check high voltage serial communication to blackfin + if(master && !normal){ + if(Feb_Control_OpenSerialCommunication()) + ;// Feb_Control_CloseSerialCommunication(); + } printf("FEB Initialization done\n"); Beb_Beb(); printf("BEB Initialization done\n"); @@ -162,7 +167,6 @@ int initDetector(){ eiger_photonenergy = -1; setReadOutFlags(NONPARALLEL); setSpeed(0,1);//clk_devider,half speed - setHighVoltage(0,0); setIODelay(650,0); setTiming(AUTO_TIMING); //SetPhotonEnergyCalibrationParameters(-5.8381e-5,1.838515,5.09948e-7,-4.32390e-11,1.32527e-15); @@ -170,6 +174,7 @@ int initDetector(){ int enable[2] = {0,1}; setExternalGating(enable);//disable external gating Feb_Control_SetInTestModeVariable(0); + setHighVoltage(0,0); Feb_Control_CheckSetup(); //print detector mac and ip @@ -436,13 +441,18 @@ void setDAC(enum detDacIndex ind, int val, int imod, int mV, int retval[]){ int setHighVoltage(int val, int imod){ if(val!=-1){ eiger_highvoltage = val; - if(master) - Feb_Control_SetHighVoltage(val); + if(master){ + int ret = Feb_Control_SetHighVoltage(val); + if(!ret) //could not set + return -2; + else if (ret == -1) //outside range + return -1; + } } if(master && !Feb_Control_GetHighVoltage(&eiger_highvoltage)){ cprintf(RED,"Warning: Could not read high voltage\n"); - return 0; + return -3; } return eiger_highvoltage; } diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h index f4dfdc073..9ddfea71b 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h @@ -44,6 +44,11 @@ enum detAdcIndex{TEMP_FPGAEXT, TEMP_10GE, TEMP_DCDC, TEMP_SODL, TEMP_SODR, TEMP_ enum detNetworkParameter{TXN_LEFT, TXN_RIGHT, TXN_FRAME,FLOWCTRL_10G}; +#define NORMAL_HIGHVOLTAGE_INPUTPORT "/sys/class/hwmon/hwmon5/device/in0_input" +#define NORMAL_HIGHVOLTAGE_OUTPUTPORT "/sys/class/hwmon/hwmon5/device/out0_output" +#define SPECIAL9M_HIGHVOLTAGE_PORT "/dev/ttyS1" +#define SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE 16 + #endif /* SLSDETECTORSERVER_DEFS_H_ */ diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index ea9b12256..b41c65a73 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -1259,16 +1259,30 @@ int set_dac(int file_des) { #endif //takes time to set high voltage, so no check for it - if(ret == OK && ind != HV_POT && ind != HV_NEW){ - if(mV) - temp = retval[1]; - else - temp = retval[0]; - if ((abs(temp-val)<=5) || val==-1) { - ret=OK; - } else { - ret=FAIL; - printf("Setting dac %d of module %d: wrote %d but read %d\n", idac, imod, val, temp); + if(ret == OK){ + if(ind != HV_POT && ind != HV_NEW){ + + if(mV) + temp = retval[1]; + else + temp = retval[0]; + if ((abs(temp-val)<=5) || val==-1) { + ret=OK; + } else { + ret=FAIL; + printf("Setting dac %d of module %d: wrote %d but read %d\n", idac, imod, val, temp); + } + }else { + if(retval[0] < 0){ + if(retval[0] == -1) + sprintf(mess, "Setting high voltage failed.Bad value %d. The range is from 0 to 200 V.\n",val); + else if(retval[0] == -2) + strcpy(mess, "Setting high voltage failed. Serial/i2c communication failed.\n"); + else if(retval[0] == -3) + strcpy(mess, "Getting high voltage failed. Serial/i2c communication failed.\n"); + ret = FAIL; + } + } }