Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 356 → Rev 357

/cvi/apps/sa02_daq/cvi/febdaq.ini
File deleted
\ No newline at end of file
/cvi/apps/sa02_daq/cvi/_febdaq.ini
1,16 → 1,25
#VME_CONTROLLER WIENER_VMUSB
#VME_CONTROLLER WIENER_VMEMM
VME_CONTROLLER CAEN_V1718
CAEN_V288 0x100500
BELLEPTS 0x02505000
#VME_CONTROLLER SIS3153_USB
#CAEN_V288 0x100500
#BELLEPTS 0x025F0000
BELLEPTS 0x61000000
#BELLEPTS 0x51000000
#CAEN_V1495
MIKRO_PORT 3
MIKRO_X 0x1
MIKRO_Y 0x2
MIKRO_Z 0x3
CAEN_V729 0x880000
#MIKRO_PORT 4
#MIKRO_X 0x1
#MIKRO_Y 0x2
#MIKRO_Z 0x3
#CAEN_V729 0x880000
FEBParam ..\parameters\feb1_0-default.param
#FEBParam ..\parameters\icfa.param
#FEBParam ..\parameters\pmtrich.param
#USER INTERFACE
# BIT 0 --> Test pulz = 0(Off)/1(On)
# BIT 1 --> Trigger = 0(Software)/1(Hardware)
UI 0x2
# BIT 1 -->
UI 0x0
#FEBMask 0xF
FEBMask 0x1
# 1-soft, 2-ext., 3-int.
TriggerType 3
/cvi/apps/sa02_daq/cvi/sa02_CVI.c
657,10 → 657,12
}
if (gFp) {
fp=gFp;
} else {
}
else {
if (append) {
fp=fopen(filename,"ab");
} else {
}
else {
fp=fopen(filename,"wb");
}
}
678,7 → 680,8
runinfo.writemode= towrite;
sa02Printf("RUNINFO x0=%d nx=%d dx=%d\n", runinfo.x0,runinfo.dx,runinfo.nx);
nbtotal+=fwrite(&runinfo, 1,sizeof(runinfo),fp); //gzip
} else {
}
else {
if (sa02Verbose) {
sa02Printf("Data are not written to the file!\n");
}
716,9 → 719,9
GetPanelAttribute (p6h, ATTR_VISIBLE, &icfa_visible);
GetCtrlVal (p6h, MINIRICH_ADD, &icfa_add);
if (icfa_visible) {
icfa_Init();
icfa_Init();
icfa_Histo();
}
}
///////////////////////////////////////////////////////////////
SetCtrlAttribute (p1h, P1_GRAPH2D, ATTR_LABEL_TEXT , title);
H2DInit(h2, "h2d",title, 144*4, 0,1,neve,data0, dstep);
758,7 → 761,8
}
if (towrite==3) {
SetCtrlVal(p1h,P1_SETVALUE, chip*36+ch );
} else {
}
else {
SetCtrlVal(p1h,P1_SETVALUE, data);
}
 
783,7 → 787,8
do {
if (sendswtrg == 1) Sa02SoftwareTrigger();
nb = sa02Read(mask, &rdata[count+2] );
} while ( nb==0 && !ctrl_c);
}
while ( nb==0 && !ctrl_c);
if (nb==0) sa02Printf("nb==0 LINE=%d\n",__LINE__);
 
if (testfixeddata && nb>0) {
802,7 → 807,8
ctrl_c = 1;
system("date >> firmware.lock");
}
} else {
}
else {
readerror= 0;
}
 
810,9 → 816,9
int xch = (143 - ich%144) + ich/144*144;
H2DFillBin(h2, xch,i,rdata[count+2+ich]);
}
 
if (icfa_visible) icfa_Event(&rdata[count+2], icfa_add );
 
/*
for (ich=0; ich<144; ich++) {
// id=(35-ich/4)+gBoardNumber*36;
858,7 → 864,8
if (nb==0) {
nerrors++;
//j--; /// kako potem pride cez zeljeno stevil ozadetkov?
} else {
}
else {
ncount++;
}
}
897,7 → 904,8
ch-=36;
chip++;
}
} else {
}
else {
data += dstep;
}
if (ctrl_c ) {
908,7 → 916,7
}
}
plot2d(h2, i-1);
if (icfa_visible) icfa_Draw();
if (icfa_visible) icfa_Draw();
 
if (output) {
sprintf(scmd,"channel;daqtime=%f", Timer()-t0 );
1164,7 → 1172,7
break;
case MENU_MINIRICH:
DisplayPanel(p6h);
break;
break;
case MENU_OPERATIO_EXIT :
quit(0,0,NULL,0,0);
exit(0);
1212,7 → 1220,8
do {
if (sendswtrg==1) Sa02SoftwareTrigger();
nb = sa02Read(mask, data );
} while ( nb==0 && !ctrl_c);
}
while ( nb==0 && !ctrl_c);
if (nb==0) sa02Printf("nb==0 LINE=%d\n",__LINE__);
 
if (ctrl_c==1) break;
1563,11 → 1572,12
retval=sa02Cmd(board, FEB_VTH1 , k , chip, channel ,1, response);
val=sa02Cmd(board, FEB_ADC_READ, data, chip, channel ,1,response);
if (sa02BoardType>2)
doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3;
doubleval = sa02adc2Vm(val);
else
doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
 
 
doubleval = sa02adc2V(val);
// doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3;
// else
// doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
H1DFillBin(h1+board, k, doubleval);
if (t!=told || k==kmax-1 ||k==0 ) {
H1DDraw(h1+board,p1h, P1_GRAPH, &phandle[board]);
1661,7 → 1671,8
switch (cmd & (~ FEB_RO)) {
case FEB_ADC_READ:
case FEB_ADC_RESET:
doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
doubleval = sa02adc2V(val);
// doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
sa02Printf("ADC %f, 0x%08x\n", doubleval, val ) ;
break;
case FEB_TMON1:
1682,9 → 1693,11
val=sa02Cmd(board, FEB_MUX, val, 0, 0 ,1,response);
val=sa02Cmd(board, FEB_ADC_READ, 0, 0, 0, 1,response);
if (sa02BoardType>2)
doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3;
doubleval = sa02adc2Vm(val);
// doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3;
else
doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
doubleval = sa02adc2V(val);
// doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
sa02Printf("%5d %6.3f\n",data, doubleval);
break;
case SA0x_ASIC0_GREG:
1808,7 → 1821,8
break;
}
h2=0;
} else {
}
else {
switch (control) {
case P2_PRINTXY:
id= P2_GRAPH_1;
1827,7 → 1841,8
sa02Printf("H2D image saved as %s\n", dfile);
sprintf(name ,"C:\\root\\bin\\root.exe ..\\macros\\H2Dload.cxx(\\\"%s\\\")", dfile);
LaunchExecutable(name);
} else {
}
else {
sprintf(dfile ,"data/%d_%d_%d_%d_%d_%s.bmp",year,month,day,hours,minutes, name );
SaveCtrlDisplayToFile (panel,id, 0, -1, -1, dfile);
sa02Printf("bmp image saved as %s\n", dfile);
1957,7 → 1972,8
GetCtrlVal(panel,ctrlID, &ch);
if (ch) {
H3DDrawSliceXY(100+board,ch-1,panel,graph, plot);
} else {
}
else {
H2DDraw(100+board,panel,graph, plot);
}
}
1990,7 → 2006,8
monrec.imon[ii] = buf[2]*1000;//zapisano v nA
monrec.vset[ii] = buf[3]*1000;//zapisano v mV
monrec.iset[ii] = buf[4]*1000;//zapisano v nA
} else {
}
else {
buf[0]=(unsigned short) (channels[ii]<<8) | ReadStatus;
if (gCAEN_V288) {
V288_Send(0,SYS403mid,1,buf);
2131,20 → 2148,20
}
time (&t0);
sa02Printf("---->daq_scan\n");
 
if (dsave) {
sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);
//gFp = fopen (dfile, "ab");
gFp = fopen (dfile, "ab");
if (gFp==NULL) sa02Printf("----> !!! gFp==NULL !!!\n");
if (ferror (gFp)) sa02Printf("----> !!! ferror (gFp) after fopen !!!\n");
if (ferror (gFp)) sa02Printf("----> !!! ferror (gFp) after fopen !!!\n");
//time ((time_t *) &runrec.time);
time (&cas);
runrec.time = (uint32_t) cas;
status = (int) fwrite (&runrec, 1, runrec.len, gFp);
if(status != runrec.len) sa02Printf("----> !!! status != runrec.len (= %d) !!!\n", status);
if (ferror (gFp)) sa02Printf("----> !!! ferror (gFp) = %d !!!\n", ferror (gFp));
if(status != runrec.len) sa02Printf("----> !!! status != runrec.len (= %d) !!!\n", status);
if (ferror (gFp)) sa02Printf("----> !!! ferror (gFp) = %d !!!\n", ferror (gFp));
 
}
 
 
2158,7 → 2175,8
if (scanunitsx) {
H2DSetTitleX(hxy+i,"x (channels)");
H3DSetTitleX(hxy+i,"x (channels)");
} else {
}
else {
H2DSetTitleX(hxy+i,"x (stage steps)");
H3DSetTitleX(hxy+i,"x (stage steps)");
}
2165,7 → 2183,8
if (scanunitsy) {
H2DSetTitleY(hxy+i,"y (channels)");
H3DSetTitleY(hxy+i,"y (channels)");
} else {
}
else {
H2DSetTitleY(hxy+i,"y (stage steps)");
H3DSetTitleY(hxy+i,"y (stage steps)");
}
2174,7 → 2193,8
if (runrec.direction) {
ny = runrec.ny;
nx = runrec.nx;
} else {
}
else {
ny = runrec.nx;
nx = runrec.ny;
}
2194,7 → 2214,8
if (scanunitsy) {
if (posrec.yset>5) {
addgap=gapy * fx;
} else {
}
else {
addgap=0;
}
posrec.yset = (int32_t)(y0+dy *fx * posrec.yset + addgap);
2207,13 → 2228,15
 
SetCtrlVal (p2h, P2_Y, posrec.yset);
SetCtrlVal (p2h, P2_IY, posrec.iy);
} else {
}
else {
posrec.ix = iy;
posrec.xset=runrec.x0+posrec.ix*runrec.dx;
if (scanunitsx) {
if (posrec.xset>5) {
addgap=gapx * fx;
} else {
}
else {
addgap=0;
}
posrec.xset = (int32_t)(x0+dx *fx * posrec.xset + addgap);
2235,7 → 2258,8
if (scanunitsx) {
if (posrec.xset>5) {
addgap=gapx * fx;
} else {
}
else {
addgap=0;
}
posrec.xset = (int32_t)(x0+dx *fx * posrec.xset + addgap);
2247,13 → 2271,15
}
SetCtrlVal (p2h, P2_X, posrec.xset);
SetCtrlVal (p2h, P2_IX, posrec.ix);
} else {
}
else {
posrec.iy = ix;
posrec.yset=runrec.y0+posrec.iy*runrec.dy;
if (scanunitsy) {
if (posrec.yset>5) {
addgap=gapy * fx;
} else {
}
else {
addgap=0;
}
posrec.yset = (int32_t)(y0+dy *fx * posrec.yset + addgap);
2317,7 → 2343,8
for (k=0; k<4; k++) sa02Printf(" CNTR%d=%d (ERR=%d)\t",k,c[k],e[k]);
sa02Printf("\nsa02Read bytes = %d mask=%d neve=%d (%d # %d)\n", nb, mask, runrec.nev, Sa02GetNeve( &inputtriggers ) , inputtriggers);
*/
} while ( nb==0 && !ctrl_c);
}
while ( nb==0 && !ctrl_c);
 
 
 
2357,7 → 2384,8
if (dsave) {
if (Random(0,1)<fraction) {
writeevents=1;
} else {
}
else {
writeevents=0;
}
if (writeevents) {
2392,7 → 2420,8
for (board=0; board<4; board++) {
if (ch) {
H3DDrawSliceXY(hxy+board,ch,p2h, p2graph[board], &p2plothandle[board]);
} else {
}
else {
H2DDraw(hxy+board,p2h, p2graph[board], &p2plothandle[board]);
}
}
2463,7 → 2492,8
monrec.imon[i] = buf[2]*1000;//zapisano v nA
monrec.vset[i] = buf[3]*1000;//zapisano v mV
monrec.iset[i] = buf[4]*1000;//zapisano v nA
} else {
}
else {
buf[0]=(unsigned short) (channels[i]<<8) | ReadStatus;
if (gCAEN_V288) {
V288_Send(0,SYS403mid,1,buf);
2504,7 → 2534,8
sprintf(name ,"%s -f %d",palaser, val);
sa02Printf("%s\n", name);
system(name);
} else {
}
else {
GetCtrlVal (p5h, P5_DAC_OFF, &val);
sprintf(name ,"%s -p %d",palaser, val);
sa02Printf("%s\n", name);
2539,7 → 2570,8
else if(buf[0]&0x1E) {
sa02Printf("status: 0x%x\n",buf[0]);
return -1;
} else sa02Printf("status: 0x%x\n",buf[0]);
}
else sa02Printf("status: 0x%x\n",buf[0]);
Delay(2);
buf[0]=(unsigned short) (channel<<8) | ReadOperationalParam;
V288_Send(0,N470mid,1,buf);
2915,7 → 2947,7
LaunchExecutable(cmdCommand);
 
 
 
/****** 2D v X ******/
// Panel 2 settings
SetCtrlVal (p2h, P2_SCANUNITSX, 0); // Continuous scan over X (1 Ch, 0 Step)
2969,8 → 3001,8
daq_scan(NULL);
 
sprintf(cmdCommand,"cmd.exe /c mkdir ..\\modules\\%04d & ..\\sa02read -i %s_file01.dat -o ..\\modules\\%04d\\%s.root ", current_run, line, current_run, buf);
system(cmdCommand); // wait here to finish to proceed to next step
system(cmdCommand); // wait here to finish to proceed to next step
 
sprintf(cmdCommand,"cmd.exe /c ..\\thisroot.bat & cd analysis & root script.c(%d)",current_run);
LaunchExecutable(cmdCommand);
 
3042,7 → 3074,8
gUirCtrlMap[gNUirCtrlMap].id = ctrlid;
gUirCtrlMap[gNUirCtrlMap].handle = GetPanelHandle(ctrl);
gNUirCtrlMap++;
} else {
}
else {
sa02Printf("ERROR: Increase gNUirCtrlMap\n");
}
}
3099,7 → 3132,8
if (count > 0) {
newlen = strlen(new);
retlen = orglen + (newlen - oldlen) * count;
} else retlen = orglen;
}
else retlen = orglen;
ret = malloc(retlen + 1);
if (ret == NULL) {
goto end_repl_str;
3108,7 → 3142,8
if (count == 0) {
/* If no matches, then just duplicate the string. */
strcpy(ret, str);
} else {
}
else {
/* Otherwise, duplicate the string whilst performing
* the replacements using the position cache. */
pret = ret;
3137,7 → 3172,7
FILE *fp = NULL;
FILE *fpout =NULL;
 
 
char *line;
char buf[MAX_PATHNAME_LEN];
int status;
3163,45 → 3198,61
return -1;
}
while (fgets(buf,MAX_PATHNAME_LEN,fp)!=NULL ) {
 
if (buf[0]!='#' && strlen(buf)>2) {
if (strstr(buf, "%RUN%")!=NULL) {
char srun[16];
sprintf(srun,"%04d",runno);
line = str_replace(buf,"%RUN%", srun);
} else {
line = buf;
char srun[16];
sprintf(srun,"%04d",runno);
line = str_replace(buf,"%RUN%", srun);
}
sa02Printf("#[%d] %s",strlen(buf),buf);
else {
line = buf;
}
sa02Printf("#[%d] %s",strlen(buf),buf);
 
sscanf(line,"%s",type);
 
if (strstr(type,"SetCtrlVal")!=NULL) {
int pID;
int pID;
int rID;
int datatype;
sscanf(line,"%*s%s%s",param,paramValue);
pID= GetPanelHandle(param);
 
pID= GetPanelHandle(param);
rID= GetControlID(param);
if (rID>0 && pID>0) {
GetCtrlAttribute (pID, rID, ATTR_DATA_TYPE, &datatype);
switch (datatype){
case VAL_INTEGER: SetCtrlVal (pID, rID, atoi(paramValue)); break;
case VAL_UNSIGNED_INTEGER: SetCtrlVal (pID, rID, strtoul(paramValue,NULL,0)); break;
case VAL_SHORT_INTEGER: SetCtrlVal (pID, rID, atoi(paramValue)); break;
case VAL_UNSIGNED_SHORT_INTEGER: SetCtrlVal (pID, rID, strtoul(paramValue,NULL,0)); break;
case VAL_DOUBLE : SetCtrlVal (pID, rID, atof(paramValue)); break;
case VAL_STRING : SetCtrlVal (pID, rID, paramValue ); break;
default: sa02Printf("[%s] ATTR_DATA_TYPE of the %s not supported datatype %d p4h=%d\n\n", type, param, datatype, p4h);
 
switch (datatype) {
case VAL_INTEGER:
SetCtrlVal (pID, rID, atoi(paramValue));
break;
case VAL_UNSIGNED_INTEGER:
SetCtrlVal (pID, rID, strtoul(paramValue,NULL,0));
break;
case VAL_SHORT_INTEGER:
SetCtrlVal (pID, rID, atoi(paramValue));
break;
case VAL_UNSIGNED_SHORT_INTEGER:
SetCtrlVal (pID, rID, strtoul(paramValue,NULL,0));
break;
case VAL_DOUBLE :
SetCtrlVal (pID, rID, atof(paramValue));
break;
case VAL_STRING :
SetCtrlVal (pID, rID, paramValue );
break;
default:
sa02Printf("[%s] ATTR_DATA_TYPE of the %s not supported datatype %d p4h=%d\n\n", type, param, datatype, p4h);
}
//sa02Printf("[%s] SetCtrlVal %s %s panel=%d control=%d\n",type,param, paramValue,pID,rID);
} else {
sa02Printf("[%s] Invalid Ctrl %s %s panel=%d control=%d\n",type,param, paramValue,pID,rID);
}
} else if (strstr(type,"2D")!=NULL) {
//sa02Printf("[%s] SetCtrlVal %s %s panel=%d control=%d\n",type,param, paramValue,pID,rID);
}
else {
sa02Printf("[%s] Invalid Ctrl %s %s panel=%d control=%d\n",type,param, paramValue,pID,rID);
}
 
}
else if (strstr(type,"2D")!=NULL) {
sscanf(line,"%*s%d%d%d%d%d%d%d%d%d%d%d%s",&scx,&nx,&xstep,&xmin,&scy,&ny,&ystep,&ymin,&direction,&nevents,&tresh,outputFileSuffix);
sprintf(test,"%d %d %d %d %d %d %d %d %d %d %d %s *\n",scx,nx,xstep,xmin,scy,ny,ystep,ymin,direction,nevents,tresh,outputFileSuffix);
sa02Printf("%s *\n\n",test);
3225,7 → 3276,8
 
daq_scan(NULL);
 
} else if (strstr(type,"Delay")!=NULL) {
}
else if (strstr(type,"Delay")!=NULL) {
int idelay=0;
sscanf(line,"%*s%s",paramValue);
for (idelay=atoi(paramValue) ; idelay>0; idelay--) {
3234,14 → 3286,15
ProcessSystemEvents();
if (ctrl_c) break;
}
} else if (strstr(type,"ThresholdLinearity")!=NULL) {
}
else if (strstr(type,"ThresholdLinearity")!=NULL) {
char *fname;
uint16_t mask = GetConnectedFebMask();
 
sscanf(line,"%*s%s",paramValue);
fname = paramValue;
 
 
ThresholdLinearityCB (p1h, P1_THRVSADC, EVENT_COMMIT, NULL, 0, 0 );
fpout = fopen(fname,"ab");
if(fpout) {
3249,27 → 3302,30
fclose(fpout);
}
 
} else if (strstr(type,"LaunchExecutable")!=NULL) {
}
else if (strstr(type,"LaunchExecutable")!=NULL) {
int index = FindPattern (line, 0, -1, "LaunchExecutable", 0, 0) + 17;
 
char *cmd = &line[index];
sa02Printf("cmd %d=%s\n",index, cmd);
if (strlen(cmd)>0) LaunchExecutable( cmd );
} else if (strstr(type,"CAEN_V729")!=NULL) {
}
else if (strstr(type,"CAEN_V729")!=NULL) {
char *fname;
//FILE *fpmon=NULL;
 
sscanf(line,"%*s%s",paramValue);
fname=paramValue;
fname=paramValue;
 
fpout = fopen(fname,"ab");
if (fpout) {
 
V729_SetFilePointer(fpout);
V729_daq(NULL);
fclose(fpout);
}
} else if (strstr(type,"HvMonitor")!=NULL) {
}
else if (strstr(type,"HvMonitor")!=NULL) {
int nrepetitions;
int delaytime;
int k=0;
3276,7 → 3332,7
FILE *fpmon=NULL;
sscanf(line,"%*s%s%d%d",paramValue, &delaytime, &nrepetitions );
fpmon = fopen(paramValue,"ab");
 
if ( fpmon ) {
hvmonFirst = 0;
for (k=0; k<nrepetitions; k++) {
3283,17 → 3339,17
double thv0,thv1;
thv0 = Timer();
GetHvMonitor();
for (int board=0;board<4;board++){
for (int board=0; board<4; board++) {
double sdata[12];
for (int k=0;k<6;k++){
sdata[k] = monrec.imon[k+4*board];
sdata[k+6] = 0;
for (int k=0; k<6; k++) {
sdata[k] = monrec.imon[k+4*board];
sdata[k+6] = 0;
}
 
SetAxisScalingMode (p1h, chart_control[board], VAL_LEFT_YAXIS, VAL_AUTOSCALE, 0, 1);
SetAxisScalingMode (p1h, chart_control[board], VAL_RIGHT_YAXIS, VAL_AUTOSCALE, 0, 1);
PlotStripChart (p1h, chart_control[board], sdata, 12, 0, 0, VAL_DOUBLE);
}
}
monrec.id = MONREC_ID;
monrec.len = sizeof(monrec);
thv1=Timer();
3303,29 → 3359,34
Delay(1);
SetCtrlVal(p1h, P1_DELAY, idelay);
ProcessSystemEvents();
if (ctrl_c) break;
if (ctrl_c) break;
}
if (ctrl_c) break;
if (ctrl_c) break;
}
fclose(fpmon);
} else {
}
else {
sa02Printf("%s cannot open file %s\n",param, paramValue );
}
 
} else if (strstr(type,"GetRunNumberFromFile")!=NULL) {
}
else if (strstr(type,"GetRunNumberFromFile")!=NULL) {
sscanf(line,"%*s%s",paramValue);
runno = GetRunNumberFromFile(paramValue);
SetCtrlVal(p1h, P1_RUNNO, runno);
sa02Printf("%s %s run=>%d\n",type, paramValue, runno );
} else if (strstr(type,"IncreaseNumberInFile")!=NULL) {
}
else if (strstr(type,"IncreaseNumberInFile")!=NULL) {
sscanf(line,"%*s%s",paramValue);
runno = IncreaseRunNumberInFile(paramValue);
sa02Printf("%s %s run=>%d\n",type, paramValue, runno );
SetCtrlVal(p1h, P1_RUNNO, runno);
} else if (strstr(type,"LoadParameters")!=NULL) {
}
else if (strstr(type,"LoadParameters")!=NULL) {
LoadParameters(p3h, P3_LOADPAR,EVENT_COMMIT,NULL,0,0);
sa02Printf("Loading parameters *\n\n");
} else if (strstr(type,"QueueUserEvent")!=NULL || strstr(type,"ProcessUserEvent")!=NULL) {
}
else if (strstr(type,"QueueUserEvent")!=NULL || strstr(type,"ProcessUserEvent")!=NULL) {
char scontrol[0xFF];
int panelHandle=0;
int controlID;
3334,17 → 3395,19
controlID = GetControlID(scontrol);
sa02Printf("UserEvent %s panelHandle %d controlID %d\n",scontrol, panelHandle, controlID );
if (panelHandle>=0 && controlID >=0 ) {
if (strstr(type,"ProcessUserEvent")!=NULL) {
if (strstr(type,"ProcessUserEvent")!=NULL) {
ProcessUserEvent(panelHandle, controlID,0);
} else {
}
else {
data[1] = controlID;
data[0] = panelHandle;
 
status = CmtWriteTSQData (pTSQ, data, 1, TSQ_INFINITE_TIMEOUT, NULL);
}
}
}
 
} else if (strstr(type,"SetPositionAndMux")!=NULL) {
}
else if (strstr(type,"SetPositionAndMux")!=NULL) {
int ix,iy;
sscanf(line,"%*s%d%d",&ix,&iy);
sa02Printf("SetPositionAndMux %d %d \n", ix,iy);
3353,7 → 3416,8
SetCtrlVal (p2h, P2_CHY, iy);
SetPositionAndMux( p2h,0, EVENT_COMMIT , NULL,0,0);
 
} else if (strstr(type,"Treshold")!=NULL) {
}
else if (strstr(type,"Treshold")!=NULL) {
sscanf(line,"%*s%s",outputFileSuffix);
 
GetCtrlVal (p1h, P1_SERIAL_1, HAPDserialNumber);
3364,29 → 3428,36
sa02Printf("%s *\n\n", test);
 
daq(NULL);
} else if (strstr(type,"Fitanje")!=NULL) {
}
else if (strstr(type,"Fitanje")!=NULL) {
FitH2DCoarse(p3h, P3_CALIBRATION_2,EVENT_COMMIT,NULL,0,0);
sa02Printf("Coarse fit parameters *\n\n");
} else if (strstr(type,"UploadChannelParameters")!=NULL) {
}
else if (strstr(type,"UploadChannelParameters")!=NULL) {
UploadChannelParameters(p3h, P3_CPARLOAD,EVENT_COMMIT,NULL,0,0);
sa02Printf("Loading channel parameters *\n\n");
} else if (strstr(type,"KalibracijaMizice")!=NULL) {
}
else if (strstr(type,"KalibracijaMizice")!=NULL) {
SetHome(p2h, P2_HO,EVENT_COMMIT,NULL,0,0);
SetCtrlVal(p2h,P2_XC,gCENTER_X);
SetCtrlVal(p2h,P2_YC,gCENTER_Y);
sa02Printf("Calibration *\n\n");
} else if (strstr(type,"LaserHVOn")!=NULL) {
}
else if (strstr(type,"LaserHVOn")!=NULL) {
set_dac(1);
sa02Printf("Low intensity laser *\n\n");
} else if (strstr(type,"LaserHVOff")!=NULL) {
}
else if (strstr(type,"LaserHVOff")!=NULL) {
set_dac(0);
sa02Printf("High intensity laser *\n\n");
} else if (strstr(type,"Gain")!=NULL) {
}
else if (strstr(type,"Gain")!=NULL) {
sscanf(line,"%*s%d",paramValue);
sprintf(test," %d", atoi(paramValue));
sa02Printf("%s *\n\n", test);
changeGlobalParam(12, atoi(paramValue)); // Global parameter Gain has ID 12
} else if (strstr(type,"ShapingTime")!=NULL) {
}
else if (strstr(type,"ShapingTime")!=NULL) {
sscanf(line,"%*s%s",paramValue);
sprintf(test," %d", atoi(paramValue));
sa02Printf("%s *\n\n", test);
3625,13 → 3696,16
imin= trange.top - 1;
imax= imin + trange.height;
 
} else {
}
else {
if (!GetActiveTableCell(p3h, P3_GREG, &cell)) {
imin = cell.y-1;
imax = imin;
} else return 0;
}
else return 0;
}
} else {
}
else {
imin=0;
imax=4*4;
}
3699,16 → 3773,20
imin= trange.top-1;
imax= imin + trange.height;
 
} else {
}
else {
if (!GetActiveTableCell(p3h, P3_CREG, &cell)) {
imin = cell.y-1;
imax = imin+1;
} else return 0;
}
else return 0;
}
} else if ((panel==p1h)&&(control==P1_CHPARLOAD)) {
}
else if ((panel==p1h)&&(control==P1_CHPARLOAD)) {
GetCtrlVal(p1h,P1_NSLIX,&imin);
imax=imin+1;
} else {
}
else {
imin=0;
imax=144*4;
}
3920,13 → 3998,16
if (x>0) {
if (x - ix > 0.5 ) {
return ix+1;
} else {
}
else {
return ix;
}
} else {
}
else {
if (x - ix < -0.5 ) {
return ix-1;
} else {
}
else {
return ix;
}
}
4090,7 → 4171,7
}
FitGraph(fitmode, npt, datax , datay, fpar);
mean[ix]=fpar[0];
rms[ix] =fpar[1];
rms[ix]=fpar[1];
offset = offsets[ix*2];
fineadj_unipol = offsets[ix*2+1];
 
4173,7 → 4254,8
 
if (value==2) {
value=0x7600;
} else {
}
else {
value=0;
}
VME_A32D32_W(address+4,value); // enable outputs
4306,7 → 4388,8
spar=scanpar-10;
nch=4*4;
 
} else {
}
else {
cid=P3_CREG;
spar=scanpar;
nch=144*4;
4508,83 → 4591,84
 
 
 
int ProcessUserEvent(int pID, int rID,int mode){
ThreadFunctionPtr mythread = NULL;
if (pID ==p1h && rID == P1_DAQ ) mythread=daq;
if (pID ==p1h && rID == P1_READOUT ) mythread=daq_readonly;
if (pID ==p1h && rID == P1_FPGAWRITE ) mythread=MultiFpgaWrite;
if (pID ==p1h && rID == P1_MULTIFPGAWRITE ) mythread=MultiFpgaWrite;
if (pID ==p1h && rID == P1_TESTING ) mythread=Testing;
if (pID ==p2h && rID == P2_DAQ ) mythread=daq_scan;
if (pID ==p6h && rID == MINIRICH_START ) mythread=daq;
if (pID ==p2h && rID == P2_RUNSCRIPT ) {
char scriptname[MAX_PATHNAME_LEN] ;
int ProcessUserEvent(int pID, int rID,int mode) {
ThreadFunctionPtr mythread = NULL;
if (pID ==p1h && rID == P1_DAQ ) mythread=daq;
if (pID ==p1h && rID == P1_READOUT ) mythread=daq_readonly;
if (pID ==p1h && rID == P1_FPGAWRITE ) mythread=MultiFpgaWrite;
if (pID ==p1h && rID == P1_MULTIFPGAWRITE ) mythread=MultiFpgaWrite;
if (pID ==p1h && rID == P1_TESTING ) mythread=Testing;
if (pID ==p2h && rID == P2_DAQ ) mythread=daq_scan;
if (pID ==p6h && rID == MINIRICH_START ) mythread=daq;
if (pID ==p2h && rID == P2_RUNSCRIPT ) {
char scriptname[MAX_PATHNAME_LEN] ;
 
int status = FileSelectPopup ("./scripts/", "*.txt", "*.txt",
"Select Script file", VAL_LOAD_BUTTON, 0, 0,
1, 0, scriptname);
if (status) {
SetCtrlVal(p1h, P1_SCRIPTNAME, scriptname );
mythread=run_script;
}
int status = FileSelectPopup ("./scripts/", "*.txt", "*.txt",
"Select Script file", VAL_LOAD_BUTTON, 0, 0,
1, 0, scriptname);
if (status) {
SetCtrlVal(p1h, P1_SCRIPTNAME, scriptname );
mythread=run_script;
}
if (pID ==p1h && rID == P1_RUNSCRIPT ) mythread=run_script;
if (pID ==p3h && rID == P3_DAQ ) mythread=daq_scanpar;
if (pID ==p4h && rID == P4_DAQ ) mythread=V729_daq;
if (mythread!=NULL) {
sa02Printf("New Thread panel=%d button=%d\n", pID, rID);
ctrl_c=0;
daq_on = 1;
SetDimming(1);
if (mode){
CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID,
}
if (pID ==p1h && rID == P1_RUNSCRIPT ) mythread=run_script;
if (pID ==p3h && rID == P3_DAQ ) mythread=daq_scanpar;
if (pID ==p4h && rID == P4_DAQ ) mythread=V729_daq;
if (mythread!=NULL) {
sa02Printf("New Thread panel=%d button=%d\n", pID, rID);
ctrl_c=0;
daq_on = 1;
SetDimming(1);
if (mode) {
CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID,
DEFAULT_THREAD_PRIORITY,
EndOfThread,
EVENT_TP_THREAD_FUNCTION_END,
NULL, RUN_IN_SCHEDULED_THREAD,
&tfID);
} else {
mythread(NULL);
}
}
 
if ( pID==p1h && rID == P1_SLOWC ) {
uint32_t board;
GetCtrlVal(p1h,P1_BOARDNUMBER, &board);
SlowControl(board, NULL);
else {
mythread(NULL);
}
// if ( pID==p1h && rID == P1_STEPONE ) StepOne();
if ( pID==p1h && rID == P1_FEBTESTANA ) FebTestAna();
if ( pID==p1h && rID == P1_TEST ) FebTest();
if ( pID==p1h && rID == P1_MODULETEST ) ModuleTest();
}
 
if ( pID==p1h && rID == P1_GET_FPGA_SERIAL ) {
int ison=0;
GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType);
for (int board=0; board<4; board++) {
char saddress[0xff]="";
GetCtrlVal(p1h, hapd_onoff[board], &ison);
sa02GetSerial(board, saddress);
sa02Printf("SERIAL FPGA = %s \n", saddress);
SetCtrlVal(p1h,fpga_serials[board],saddress);
}
};
if ( pID==p1h && rID == P1_SLOWC ) {
uint32_t board;
GetCtrlVal(p1h,P1_BOARDNUMBER, &board);
SlowControl(board, NULL);
}
// if ( pID==p1h && rID == P1_STEPONE ) StepOne();
if ( pID==p1h && rID == P1_FEBTESTANA ) FebTestAna();
if ( pID==p1h && rID == P1_TEST ) FebTest();
if ( pID==p1h && rID == P1_MODULETEST ) ModuleTest();
 
if ( ( pID==p1h && rID == P1_STOP )
|| ( pID==p2h && rID == P2_STOP )
|| ( pID==p3h && rID == P3_STOP )
|| ( pID==p6h && rID == MINIRICH_STOP )
|| ( pID==p4h && rID == P4_STOP ) ) {
sa02Printf("Stopping the Thread %d\n", tfID);
ctrl_c=1;
if ( pID==p1h && rID == P1_GET_FPGA_SERIAL ) {
int ison=0;
GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType);
for (int board=0; board<4; board++) {
char saddress[0xff]="";
GetCtrlVal(p1h, hapd_onoff[board], &ison);
sa02GetSerial(board, saddress);
sa02Printf("SERIAL FPGA = %s \n", saddress);
SetCtrlVal(p1h,fpga_serials[board],saddress);
}
if (pID ==p5h) {
if (rID == P5_SET_DAC_HV_ON) set_dac(1);
if (rID == P5_SET_DAC_HV_OFF) set_dac(0);
if (rID == P5_SET_HV_ON) set_hv(1);
if (rID == P5_SET_HV_OFF) set_hv(0);
}
return 0;
};
 
if ( ( pID==p1h && rID == P1_STOP )
|| ( pID==p2h && rID == P2_STOP )
|| ( pID==p3h && rID == P3_STOP )
|| ( pID==p6h && rID == MINIRICH_STOP )
|| ( pID==p4h && rID == P4_STOP ) ) {
sa02Printf("Stopping the Thread %d\n", tfID);
ctrl_c=1;
}
if (pID ==p5h) {
if (rID == P5_SET_DAC_HV_ON) set_dac(1);
if (rID == P5_SET_DAC_HV_OFF) set_dac(0);
if (rID == P5_SET_HV_ON) set_hv(1);
if (rID == P5_SET_HV_OFF) set_hv(0);
}
return 0;
}
 
 
4605,7 → 4689,7
char title[0xFF];
char saddress[0xff]="";
//uint32_t board;
int i;
int i;
int status=0;
 
if (InitCVIRTE (hInstance, 0, 0) == 0) {
4618,7 → 4702,7
if ( (status = CmtNewTSQ (1, 2*sizeof(int), OPT_TSQ_AUTO_FLUSH_ALL, &pTSQ)) <0)
printf("CmtNewTSQ cannot be installed\n");
if ( (status = CmtInstallTSQCallback (pTSQ, EVENT_TSQ_ITEMS_IN_QUEUE, EVENT_TSQ_QUEUE_SIZE,
QueueUserEventCallback, pTSQData, CmtGetCurrentThreadID(), NULL)) <0)
QueueUserEventCallback, pTSQData, CmtGetCurrentThreadID(), NULL)) <0)
printf("CmtInstallTSQCallback cannot be installed\n"); ;
 
SetStdioPort (CVI_STDIO_WINDOW );
4643,7 → 4727,7
if ((p3h = LoadPanel (0, "sa02_CVI.uir", P3)) < 0) return -1;
if ((p4h = V729_LoadPanel (0, "CAEN_V729\\CAEN_V729_CVI.uir", P4)) < 0) return -1;
if ((p5h = LoadPanel (0, "sa02_CVI.uir", P5)) < 0) return -1;
if ((p6h = LoadPanel (0, "ICFA\\minirich.uir", MINIRICH)) < 0) return -1;
if ((p6h = LoadPanel (0, "ICFA\\minirich.uir", MINIRICH)) < 0) return -1;
if ((pm1 = LoadMenuBar (p1h, "sa02_CVI.uir", MENU)) < 0) return -1;
 
SetPanelMenuBar(p1h, pm1);
4672,6 → 4756,7
if (gVME_CONTROLLER == WIENER_VMEMM) sprintf( title, "%s + WIENER_VMEMM", title );
if (gVME_CONTROLLER == WIENER_VMUSB) sprintf( title, "%s + WIENER_VMUSB", title );
if (gVME_CONTROLLER == CAEN_V1718) sprintf( title, "%s + CAEN_V1718", title );
if (gVME_CONTROLLER == SIS3153_USB) sprintf( title, "%s + SIS3153_USB", title );
if (gCAEN_V1495) sprintf( title, "%s + CAEN_V1495", title );
if (gCAEN_V288 ) sprintf( title, "%s + CAEN_V288", title );
 
4703,13 → 4788,14
 
LoadElectronicMap("eid2hapdxy.map");
icfa_Init();
 
 
loop_on=1;
do {
GetUserEvent (1, &pID, &rID);
GetUserEvent (1, &pID, &rID);
ProcessUserEvent(pID,rID,1);
} while (loop_on);
}
while (loop_on);
 
CmtDiscardThreadPool (poolHandle);
DiscardPanel (p4h);
4821,7 → 4907,8
return -1;
}
(c == 0xff) ? dummyword++ : (dummyword=0);
} while( dummyword < 4 );
}
while( dummyword < 4 );
 
if( mode == SLAVESERIAL_MODE ) {
if(verbose) sa02Printf("slave serial mode");
4835,7 → 4922,8
sa02Printf( "#");
}
}
} else if( mode == SELECTMAP_MODE ) {
}
else if( mode == SELECTMAP_MODE ) {
if( verbose ) sa02Printf("select map mode\n");
Pts_write( addr + ADR_MODE, SELECTMAP_MODE );
Pts_erase( addr, verbose );
4857,7 → 4945,8
}
}
VME_MWEXEC();
} else {
}
else {
if(verbose) {
sa02Printf( "\nIllegal mode\n");
 
4880,7 → 4969,8
if(csr1_value&CSR1_DONE) {
if(verbose) sa02Printf("configure complete.\n");
return 1;
} else {
}
else {
if(verbose) sa02Printf("configure not complete.");
return -1;
}
4903,7 → 4993,8
GetCtrlVal(p3h,P3_PTSMODE,&mode);
if(VME_CONNECTED() >=0 ) {
Pts_configure_bit( addr , filename, mode, 1 );
} else {
}
else {
MessagePopup ("Warning", "Connect VME!!");
}
break;
/cvi/apps/sa02_daq/cvi/sa02_CVI.uir
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/cvi/apps/sa02_daq/cvi
Property changes:
Added: svn:ignore
## -0,0 +1 ##
+febdaq.ini
Index: apps/sa02_daq/sa02lib.c
===================================================================
--- apps/sa02_daq/sa02lib.c (revision 356)
+++ apps/sa02_daq/sa02lib.c (revision 357)
@@ -113,6 +113,43 @@
return i;
};
+#define ADC_VCC 3.3
+#define AMP_IB_min -1.15e-6
+#define ADC_IB_min 2355
+#define AMP_IB_max 0.2e-6
+#define ADC_IB_max 2665
+
+double sa02ampIb(int adc) {
+ if (adc <= ADC_IB_min) return AMP_IB_min;
+ if (adc > ADC_IB_max) return AMP_IB_max;
+ return AMP_IB_min + ((AMP_IB_max-AMP_IB_min)/(ADC_IB_max-ADC_IB_min)) * (adc - ADC_IB_min);
+}
+
+double sa02adc2V(int adc) {
+ adc &=0xFFF;
+ return ADC_VCC * (double)adc/4096;
+}
+
+double sa02adc2Vp(int adc) {
+ adc &=0xFFF;
+ return ADC_VCC * (double)adc/4096 + 1.0e+4 * sa02ampIb(adc);
+}
+
+double sa02adc2Vm(int adc) {
+ adc &=0xFFF;
+ return ADC_VCC * (2. * (double)adc/4096. - 1.) + 5.1e+4 * sa02ampIb(adc);
+}
+
+double sa02adc2V38(int adc) {
+ adc &=0xFFF;
+ return ADC_VCC * (2. * (double)adc/4096.) + 5.1e+4 * sa02ampIb(adc);
+}
+
+double sa02adc2Va(int adc) {
+ adc &=0xFFF;
+ return ADC_VCC * (double)adc/4096. - (ADC_VCC/2. + 0.06);
+}
+
//-------------------------------------------------------------------------
uint32_t sa02Write(uint32_t sa02BoardNumber, uint32_t regh, uint32_t regl, uint32_t *response)
@@ -199,7 +236,6 @@
return 0;
}
-
int Sa02SoftwareTrigger (void ) {
uint32_t rdy =1;
VME_MWRST();
@@ -208,8 +244,6 @@
return 0;
}
-
-
int Sa02TestPulseEnable (uint32_t board, uint32_t enable ) {
uint32_t response[2]= {0,0};
@@ -847,7 +881,7 @@
Delay(0.01);
cmd=FEB_ADC_READ;
val=sa02Cmd(board, cmd, data, chip, channel ,1,response);
- doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
+ doubleval = sa02adc2Vp(val);
sa02Printf("VDD = %6.3f V\n",doubleval);
sdata[i++]=doubleval;
@@ -857,7 +891,7 @@
Delay(0.01);
cmd=FEB_ADC_READ;
val=sa02Cmd(board, cmd, data, chip, channel ,1,response);
- doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
+ doubleval = sa02adc2Vp(val);
sa02Printf("V+2 = %6.3f V\n",doubleval);
sdata[i++]=doubleval;
@@ -867,7 +901,7 @@
Delay(0.01);
cmd=FEB_ADC_READ;
val=sa02Cmd(board, cmd, data, chip, channel ,1,response);
- doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3;
+ doubleval = sa02adc2Vm(val);
sa02Printf("V-2 = %6.3f V\n",doubleval);
sdata[i++]=doubleval;
@@ -878,7 +912,7 @@
Delay(0.01);
cmd=FEB_ADC_READ;
val=sa02Cmd(board, cmd, data, chip, channel ,1,response);
- doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3;
+ doubleval = sa02adc2Vm(val);
sa02Printf("VSS = %6.3f V\n",doubleval);
sdata[i++]=doubleval;
@@ -889,9 +923,9 @@
cmd=FEB_ADC_READ;
val=sa02Cmd(board, cmd, data, chip, channel ,1,response);
if (sa02BoardType>2)
- doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3;
+ doubleval = sa02adc2Vm(val);
else
- doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
+ doubleval = sa02adc2V(val);
sa02Printf("VTH1 = %6.3f V\n",doubleval);
sdata[i++]=doubleval;
@@ -902,9 +936,9 @@
cmd=FEB_ADC_READ;
val=sa02Cmd(board, cmd, data, chip, channel ,1,response);
if (sa02BoardType>2)
- doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3;
+ doubleval = sa02adc2Vm(val);
else
- doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
+ doubleval = sa02adc2V(val);
sa02Printf("VTH2 = %6.3f V\n",doubleval);
sdata[i++]=doubleval;
@@ -914,7 +948,7 @@
Delay(0.01);
cmd=FEB_ADC_READ;
val=sa02Cmd(board, cmd, data, chip, channel ,1,response);
- doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
+ doubleval = sa02adc2Vp(val);
sa02Printf("VCC12 = %6.3f V\n",doubleval);
sdata[i++]=doubleval;
@@ -924,7 +958,7 @@
Delay(0.01);
cmd=FEB_ADC_READ;
val=sa02Cmd(board, cmd, data, chip, channel ,1,response);
- doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
+ doubleval = sa02adc2Vp(val);
sa02Printf("VCC15 = %6.3f V\n",doubleval);
sdata[i++]=doubleval;
@@ -934,7 +968,7 @@
Delay(0.01);
cmd=FEB_ADC_READ;
val=sa02Cmd(board, cmd, data, chip, channel ,1,response);
- doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
+ doubleval = sa02adc2Vp(val);
sa02Printf("VCC25 = %6.3f V\n",doubleval);
sdata[i++]=doubleval;
@@ -944,7 +978,7 @@
Delay(0.01);
cmd=FEB_ADC_READ;
val=sa02Cmd(board, cmd, data, chip, channel ,1,response);
- doubleval = 2 * ((val & 0xFFF) + 0.5)/0x1000 * 3.3;
+ doubleval = sa02adc2V38(val);
sa02Printf("V+3.8 = %6.3f V\n",doubleval);
sdata[i++]=doubleval;
/cvi/apps/sa02_daq/sa02lib.h
66,6 → 66,13
#define sa02Printf printf
#endif
 
double sa02ampIb(int);
double sa02adc2V(int);
double sa02adc2Vp(int);
double sa02adc2Vm(int);
double sa02adc2V38(int);
double sa02adc2Va(int);
 
void sa02Tmlnk (int tout);
void sa02Tmulk (void );
void sa02Timerast (int signumber);