Rev 326 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
326 | f9daq | 1 | //#include "tabela.h" |
2 | //#include "proba.h" |
||
3 | |||
4 | |||
5 | #include "vme.h" |
||
6 | |||
7 | //#define PTS_ADDR 0x025F0000 |
||
8 | //#define PTS_ADDR 0x26000000 |
||
9 | |||
10 | #include "PtsModule.h" |
||
11 | #define PTS_ADDR 0x61000000 |
||
12 | #include <windows.h> |
||
13 | #include <formatio.h> |
||
14 | #include <analysis.h> |
||
15 | #include "toolbox.h" |
||
16 | #include <cvirte.h> |
||
17 | #include <stdlib.h> |
||
18 | #include <stdio.h> |
||
19 | |||
20 | #include <string.h> |
||
21 | #include <ctype.h> |
||
22 | #include <stdint.h> |
||
23 | |||
24 | #include <signal.h> |
||
25 | #include <utility.h> |
||
26 | #include <ansi_c.h> |
||
27 | #include <userint.h> |
||
28 | #include "toolbox.h" |
||
29 | |||
30 | #include "sa02lib.h" |
||
31 | #include "CAEN_V729.h" |
||
32 | #include "CAEN_V729_CVI.h" |
||
33 | #include "icfa.h" |
||
34 | |||
35 | #include "MIKRO.h" |
||
36 | const int dsize = 144*4; |
||
37 | |||
38 | #include "H1D.h" |
||
39 | #include "H2D.h" |
||
40 | #include "H3D.h" |
||
41 | #include "HDraw.h" |
||
42 | #include "dataio.h" |
||
43 | #include "sa02lib.h" |
||
44 | #include "sa02_CVI.h" |
||
45 | |||
46 | int ProcessUserEvent(int pID, int rID,int mode); |
||
47 | |||
48 | const char palaser[0xFF]="\"C:\\home\\software\\daq\\LaserDriver-Ver2.0\\Particulars LASER control.exe\""; |
||
49 | |||
50 | #define MAX_THREADS 10 |
||
51 | const char slowcname[20][20]= {"TMON0","TMON1","VDD","V2P","V2N","VSS","VTH1","VTH2", "VCC12", "VCC15" ,"VCC25", "V38P" }; |
||
52 | const int chart_control[4]= {P1_CHART_1,P1_CHART_2,P1_CHART_3,P1_CHART_4}; |
||
53 | const int hapd_serials [4]= { P1_SERIAL_1, P1_SERIAL_2, P1_SERIAL_3, P1_SERIAL_4 }; |
||
54 | const int fpga_serials [4]= { P1_SERIAL_FPGA_1, P1_SERIAL_FPGA_2, P1_SERIAL_FPGA_3, P1_SERIAL_FPGA_4 }; |
||
55 | const int hapd_onoff [4]= { P1_ONOFF_1, P1_ONOFF_2, P1_ONOFF_3, P1_ONOFF_4 }; |
||
56 | const int p2graph [4]= { P2_GRAPH_1, P2_GRAPH_2, P2_GRAPH_3, P2_GRAPH_4 }; |
||
57 | |||
58 | #define PTS_ADDR 0x61000000 |
||
59 | |||
60 | #define MIKRO_COM 4 |
||
61 | #define MIKRO_X 1 |
||
62 | #define MIKRO_Y 2 |
||
63 | #define MIKRO_Z 3 |
||
64 | |||
65 | #define TRUE 1 |
||
66 | #define FALSE 0 |
||
67 | #define TIMEOUT 3 |
||
68 | |||
69 | #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) |
||
70 | uint32_t gVME_CONTROLLER=WIENER_VMEMM; |
||
71 | uint32_t gCAEN_V288=0; |
||
72 | uint32_t gBELLEPTS=PTS_ADDR; |
||
73 | uint32_t gMIKRO_PORT=MIKRO_COM; |
||
74 | uint32_t gMIKRO_X=MIKRO_X, gMIKRO_Y=MIKRO_Y, gMIKRO_Z=MIKRO_Y; |
||
75 | uint32_t gCENTER_X=176000, gCENTER_Y=170000; |
||
76 | double gCENTER_KX=6./300, gCENTER_KY=3./300; |
||
77 | uint32_t gCAEN_V729=0; |
||
78 | uint32_t gCAEN_V1495=0; |
||
79 | uint32_t gFEBParamRead=0; |
||
80 | uint32_t gFEBMask=0xF; |
||
81 | uint32_t gTriggerType=2; |
||
82 | char gFEBParam[0xFF]=""; |
||
83 | |||
84 | uint32_t uInterf = 0; |
||
85 | |||
86 | RUNINFO runinfo; |
||
87 | RUNREC runrec; |
||
88 | ENDREC endrec; |
||
89 | POSREC posrec; |
||
90 | EVTREC evtrec; |
||
91 | EVTREC evtrec1; |
||
92 | DATREC datrec; |
||
93 | MONREC monrec; |
||
94 | ITERATORREC iteratorrec; |
||
95 | |||
96 | |||
97 | typedef struct { |
||
98 | int chip; |
||
99 | int ch; |
||
100 | int chx; |
||
101 | int chy; |
||
102 | } EID2HAPDY; |
||
103 | |||
104 | EID2HAPDY eid2hapdxy[144]; |
||
105 | |||
106 | // Variables |
||
107 | static int p1h, pID, rID, tfID; |
||
108 | static int p2h; |
||
109 | static int p3h; |
||
110 | static int p4h; |
||
111 | static int p5h; |
||
112 | static int pm1; |
||
113 | static int daq_on,loop_on; |
||
114 | static CmtThreadPoolHandle poolHandle = 0; |
||
115 | static CmtTSQHandle pTSQ = 0; |
||
116 | static int pTSQData[2]; |
||
117 | |||
118 | double datay[10000]; |
||
119 | double datax[10000]; |
||
120 | double datayfit[10000]; |
||
121 | |||
122 | //const int mux_map[4]={ 1,3,0,2}; |
||
123 | |||
124 | int ctrl_c=0; |
||
125 | int integer_val=0; |
||
126 | FILE *gFp=NULL; |
||
127 | |||
128 | //***********************VARIABLE ZA BRANJE NAPETOSTI***********************// |
||
129 | |||
130 | #include "CAENV288.h" |
||
131 | |||
132 | #define ReadOperationalParam 0x02 //N470 |
||
133 | #define TurnChanelOn 0x0a //N470 |
||
134 | #define TurnChanelOff 0x0b //N470 |
||
135 | #define ReadStatus 0x01 //SYS403 |
||
136 | #define ReadParameters 0x02 //SYS403 |
||
137 | |||
138 | int hvmon=0; |
||
139 | int hvmonFirst=0; |
||
140 | int32_t vset[24], iset[24]; |
||
141 | |||
142 | |||
143 | // reads the run number from the first line in the file |
||
144 | int GetRunNumberFromFile(char *fname) { |
||
145 | char line[MAX_PATHNAME_LEN]; |
||
146 | int ndim= MAX_PATHNAME_LEN; |
||
147 | int current_run = -1; |
||
148 | FILE *fp = NULL; |
||
149 | ssize_t size; |
||
150 | |||
151 | if ( GetFileInfo(fname,&size) ) fp = fopen(fname,"r"); |
||
152 | |||
153 | if (fp) { |
||
154 | if (fgets(line,ndim,fp)!= NULL) current_run = atoi(line); |
||
155 | fclose(fp); |
||
156 | } |
||
157 | return current_run; |
||
158 | |||
159 | } |
||
160 | |||
161 | int IncreaseRunNumberInFile(char *fname) { |
||
162 | |||
163 | int current_run = GetRunNumberFromFile(fname); |
||
164 | FILE *fp = fopen(fname,"w"); |
||
165 | |||
166 | if (fp) { |
||
167 | fprintf(fp,"%d", current_run+1 ); |
||
168 | fclose(fp); |
||
169 | } |
||
170 | return current_run+1; |
||
171 | } |
||
172 | |||
173 | |||
174 | //**************************** get station parameters from ini file |
||
175 | int readIni(char *fname) { |
||
176 | |||
177 | FILE *fp = NULL; |
||
178 | char cmd[0xFF],val[0xFF]; |
||
179 | int ndim=400; |
||
180 | char line[ndim]; |
||
181 | ssize_t size; |
||
182 | |||
183 | if ( GetFileInfo(fname,&size) ) fp = fopen(fname,"r"); |
||
184 | if (!fp) { |
||
185 | sprintf(line, "%s not found. Using default values.\n",fname); |
||
186 | MessagePopup ("Info", line); |
||
187 | return -1; |
||
188 | } |
||
189 | while (fgets(line,ndim,fp)!=NULL) { |
||
190 | sscanf(line,"%s%s",cmd, val); |
||
191 | if (cmd[0]=='#') continue; |
||
192 | if ( strstr(cmd,"VME_CONTROLLER")!= NULL ) { |
||
193 | if ( strstr(val,"WIENER_VMUSB")!= NULL ) gVME_CONTROLLER=WIENER_VMUSB; |
||
194 | if ( strstr(val,"WIENER_VMEMM")!= NULL ) gVME_CONTROLLER=WIENER_VMEMM; |
||
195 | if ( strstr(val,"CAEN_V1718") != NULL ) gVME_CONTROLLER=CAEN_V1718; |
||
196 | if ( strstr(val,"SIS3153_USB") != NULL ) gVME_CONTROLLER=SIS3153_USB; |
||
197 | } |
||
198 | if ( strstr(cmd,"CAEN_V288" )!= NULL ) gCAEN_V288 =strtoul(val,NULL,0); |
||
199 | if ( strstr(cmd,"BELLEPTS") != NULL ) gBELLEPTS =strtoul(val,NULL,0); |
||
200 | if ( strstr(cmd,"CAEN_V1495") != NULL ) gCAEN_V1495 =strtoul(val,NULL,0); |
||
201 | if ( strstr(cmd,"MIKRO_PORT")!= NULL ) gMIKRO_PORT=strtoul(val,NULL,0); |
||
202 | if ( strstr(cmd,"MIKRO_X") != NULL ) gMIKRO_X =strtoul(val,NULL,0); |
||
203 | if ( strstr(cmd,"MIKRO_Y") != NULL ) gMIKRO_Y =strtoul(val,NULL,0); |
||
204 | if ( strstr(cmd,"MIKRO_Z") != NULL ) gMIKRO_Z =strtoul(val,NULL,0); |
||
205 | if ( strstr(cmd,"CENTER_X") != NULL ) gCENTER_X =strtoul(val,NULL,0); |
||
206 | if ( strstr(cmd,"CENTER_Y") != NULL ) gCENTER_Y =strtoul(val,NULL,0); |
||
207 | if ( strstr(cmd,"CENTER_KX") != NULL ) gCENTER_KX =strtod(val,NULL); |
||
208 | if ( strstr(cmd,"CENTER_KY") != NULL ) gCENTER_KY =strtod(val,NULL); |
||
209 | if ( strstr(cmd,"CAEN_V729") != NULL ) gCAEN_V729 =strtoul(val,NULL,0); |
||
210 | if ( strstr(cmd,"FEBParam") != NULL ) sprintf(gFEBParam,"%s", val); |
||
211 | if ( strstr(cmd,"UI") != NULL ) uInterf =strtoul(val,NULL,0); |
||
212 | if ( strstr(cmd,"FEBMask") != NULL ) gFEBMask =strtoul(val,NULL,0); |
||
213 | if ( strstr(cmd,"TriggerType") != NULL ) gTriggerType =strtoul(val,NULL,0); |
||
214 | } |
||
215 | fclose(fp); |
||
216 | return 0; |
||
217 | } |
||
218 | //**************************** missing declarations in the library |
||
219 | char strbuf[0xFF]; |
||
220 | |||
221 | int gLog=0; |
||
222 | int sa02Printf(const char *format, ...) { |
||
223 | va_list aptr; |
||
224 | int ret; |
||
225 | FILE *flog; |
||
226 | |||
227 | va_start(aptr, format); |
||
228 | ret = vsprintf(strbuf, format, aptr); |
||
229 | va_end(aptr); |
||
230 | SetCtrlVal(p1h,P1_STDIO,strbuf); |
||
231 | |||
232 | if (gLog) { |
||
233 | flog = fopen ("stdio.log", "a"); |
||
234 | fprintf (flog, "%s", strbuf); |
||
235 | fclose (flog); |
||
236 | } |
||
237 | return(ret); |
||
238 | } |
||
239 | |||
240 | |||
241 | int CVICALLBACK sa02timeout (int panel, int control, int event, |
||
242 | void *callbackData, int eventData1, int eventData2) { |
||
243 | switch (event) { |
||
244 | case EVENT_TIMER_TICK: |
||
245 | sa02TimerOut = TRUE; |
||
246 | sa02Printf("sa02timeout\n"); |
||
247 | //sa02Printf("TIMEOUT %s in line %d\n", __FILE__ , __LINE__); |
||
248 | break; |
||
249 | } |
||
250 | return 0; |
||
251 | } |
||
252 | void sa02Timerast (int signumber) { |
||
253 | sa02TimerOut = TRUE; |
||
254 | sa02Printf("TIMEOUT !!!\n"); |
||
255 | SetCtrlAttribute (p1h, P1_DAQ_TIMEOUT, ATTR_ENABLED, 0); |
||
256 | } |
||
257 | |||
258 | void sa02Tmlnk (int tout) { |
||
259 | sa02TimerOut = FALSE; |
||
260 | SetCtrlAttribute (p1h, P1_DAQ_TIMEOUT, ATTR_INTERVAL, |
||
261 | (float)tout/100.); |
||
262 | SetCtrlAttribute (p1h, P1_DAQ_TIMEOUT, ATTR_ENABLED, 1); |
||
263 | // ResetTimer (p1h, P1_DAQ_TIMEOUT); |
||
264 | } |
||
265 | |||
266 | void sa02Tmulk ( void ) { |
||
267 | SetCtrlAttribute (p1h, P1_DAQ_TIMEOUT, ATTR_ENABLED, 0); |
||
268 | } |
||
269 | //**************************** |
||
270 | |||
271 | |||
272 | int EscapeString(const char *i, char *o) { |
||
273 | unsigned int iptr=0, optr = 0; |
||
274 | // walk though the input string |
||
275 | for (iptr = 0; iptr < strlen(i); iptr++, optr++) { |
||
276 | // search for |
||
277 | if ( (i[iptr]=='\\') ) { |
||
278 | sa02Printf("Escape String %d %d \n",i[iptr] , i[iptr]==92 ) ; |
||
279 | //sa02Printf("Escape String %d %d \n",i[iptr] , ( (i[iptr] == 92) || (i[iptr] == 42) )) ; |
||
280 | o[optr] = i[iptr]; |
||
281 | optr++; |
||
282 | } |
||
283 | |||
284 | o[optr] = i[iptr]; |
||
285 | } |
||
286 | |||
287 | o[optr] = '\0'; |
||
288 | |||
289 | |||
290 | return 0; |
||
291 | } |
||
292 | |||
293 | |||
294 | |||
295 | int p1plothandle=0; |
||
296 | int p2plothandle[4]= {0,0,0,0}; |
||
297 | int p3plothandle=0; |
||
298 | |||
299 | int plothandle=0; |
||
300 | |||
301 | int phandle[4]= {0,0,0,0}; |
||
302 | |||
303 | |||
304 | int plothandle2dfit=0; |
||
305 | int plothandleslix=0; |
||
306 | int plothandlesliy=0; |
||
307 | int plothandlefit=0; |
||
308 | |||
309 | void SigInt (int sig) { |
||
310 | ctrl_c = 1; |
||
311 | sa02TimerOut=1; |
||
312 | } |
||
313 | |||
314 | //int sa02Verbose=0; |
||
315 | int module_header(int recid,uint32_t *data,int len) { |
||
316 | data[0] = recid; |
||
317 | data[1] = (len >0)? len : 0 ; |
||
318 | return data[1]+2; |
||
319 | } |
||
320 | |||
321 | int PrintData(uint32_t *rdata, int count) { |
||
322 | int j; |
||
323 | uint32_t i; |
||
324 | for (j=0; j<count; j++) { |
||
325 | uint32_t recid = rdata[j++]; |
||
326 | uint32_t len = rdata[j++]; |
||
327 | sa02Printf(" recid=0x%0x len=%d pos=%d(maxpos %d) val=",recid, len, j, count); |
||
328 | if (len>2) { |
||
329 | sa02Printf("\n"); |
||
330 | } |
||
331 | for (i=0; i<len; i++) { |
||
332 | if (j< count) { |
||
333 | sa02Printf("0x%0x\t", rdata[j]); |
||
334 | } |
||
335 | if (i%4==3) { |
||
336 | sa02Printf("\n"); |
||
337 | } |
||
338 | j++; |
||
339 | } |
||
340 | sa02Printf("\n"); |
||
341 | if (len) { |
||
342 | j--; |
||
343 | } |
||
344 | } |
||
345 | return 0; |
||
346 | } |
||
347 | |||
348 | //------------------------------------------------------------------------- |
||
349 | int CVICALLBACK PlotSliceY (int panel, int control, int event, |
||
350 | void *callbackData, int eventData1, int eventData2) { |
||
351 | int nslice,i; |
||
352 | int h2=(int) callbackData; |
||
353 | |||
354 | switch (event) { |
||
355 | case EVENT_COMMIT: { |
||
356 | int ny = H2DGetNbinsY(h2); |
||
357 | double miny = H2DGetMinY(h2); |
||
358 | double stepy = H2DGetStepY(h2); |
||
359 | GetCtrlVal(panel,P1_NSLIX,&nslice); |
||
360 | |||
361 | for (i=0; i < ny; i++ ) { |
||
362 | datax[i]=H2DGetBinContent(h2,nslice,i); |
||
363 | } |
||
364 | if (ny>0) { |
||
365 | if (plothandleslix) { |
||
366 | DeleteGraphPlot (p1h, P1_GRAPHY, plothandleslix, VAL_IMMEDIATE_DRAW); |
||
367 | } |
||
368 | |||
369 | plothandleslix = PlotWaveform (p1h, P1_GRAPHY, datax, ny, |
||
370 | VAL_DOUBLE, 1.0, 0.0, miny, |
||
371 | stepy, VAL_FAT_LINE, |
||
372 | VAL_EMPTY_SQUARE, VAL_SOLID, 1, |
||
373 | VAL_BLUE); |
||
374 | } |
||
375 | |||
376 | } |
||
377 | break; |
||
378 | } |
||
379 | return 0; |
||
380 | } |
||
381 | |||
382 | |||
383 | int CVICALLBACK PlotSliceX (int panel, int control, int event, |
||
384 | void *callbackData, int eventData1, int eventData2) { |
||
385 | int nslice,i; |
||
386 | int h2=(int) callbackData; |
||
387 | |||
388 | switch (event) { |
||
389 | case EVENT_COMMIT: { |
||
390 | int nx = H2DGetNbinsX(h2); |
||
391 | double minx = H2DGetMinX(h2); |
||
392 | double stepx = H2DGetStepX(h2); |
||
393 | GetCtrlVal(panel,P1_NSLIY,&nslice); |
||
394 | for (i=0; i < nx; i++ ) { |
||
395 | datax[i]=H2DGetBinContent(h2,i,nslice); |
||
396 | } |
||
397 | if (nx>0) { |
||
398 | if (plothandlesliy) { |
||
399 | DeleteGraphPlot (p1h, P1_GRAPHX, plothandlesliy, VAL_IMMEDIATE_DRAW); |
||
400 | } |
||
401 | |||
402 | plothandlesliy = PlotWaveform (p1h, P1_GRAPHX, datax, nx, |
||
403 | VAL_DOUBLE, 1.0, 0.0, minx, |
||
404 | stepx, VAL_FAT_LINE, |
||
405 | VAL_EMPTY_SQUARE, VAL_SOLID, 1, |
||
406 | VAL_BLUE); |
||
407 | } |
||
408 | |||
409 | } |
||
410 | break; |
||
411 | } |
||
412 | return 0; |
||
413 | } |
||
414 | |||
415 | |||
416 | |||
417 | void plot1d(int npoints, double x0, double dx) { |
||
418 | sa02Printf("TEST %d\n", npoints); |
||
419 | if (npoints>0) { |
||
420 | if (plothandle) { |
||
421 | DeleteGraphPlot (p1h, P1_GRAPH, plothandle, VAL_IMMEDIATE_DRAW); |
||
422 | } |
||
423 | plothandle = PlotWaveform (p1h, P1_GRAPH, datay, npoints, VAL_DOUBLE, |
||
424 | 1.0, 0.0, x0, dx, VAL_CONNECTED_POINTS, |
||
425 | VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE); |
||
426 | } |
||
427 | } |
||
428 | |||
429 | /* |
||
430 | void plotxy(int h2d){ |
||
431 | if (plothandlexy > 0 ) DeleteGraphPlot (p2h, P2_GRAPHXY, plothandlexy, VAL_IMMEDIATE_DRAW); |
||
432 | RangeColors(H2DGetMin(h2d),H2DGetMax(h2d)); |
||
433 | plothandlexy = PlotScaledIntensity (p2h, P2_GRAPHXY, H2DGetData(h2d), |
||
434 | H2DGetNbinsX(h2d), H2DGetNbinsY(h2d), VAL_DOUBLE, |
||
435 | H2DGetStepY(h2d),H2DGetMinY(h2d),H2DGetStepX(h2d),H2DGetMinX(h2d), |
||
436 | colormap->array, |
||
437 | colormap->HiColor, |
||
438 | colormap->numberofColors, 1, 0); |
||
439 | ProcessSystemEvents (); |
||
440 | } |
||
441 | */ |
||
442 | |||
443 | int CVICALLBACK ZoomToFebCB (int panel, int control, int event, |
||
444 | void *callbackData, int eventData1, int eventData2) { |
||
445 | int feb=-1; |
||
446 | float xmin=0, xmax=0; |
||
447 | switch (event) { |
||
448 | case EVENT_COMMIT: |
||
449 | GetCtrlVal(panel,control,&feb); |
||
450 | switch (feb) { |
||
451 | case -1: |
||
452 | xmin=0; |
||
453 | xmax=144*4-1; |
||
454 | break; |
||
455 | default: |
||
456 | xmin = feb *144; |
||
457 | xmax =xmin+144 -1; |
||
458 | break; |
||
459 | } |
||
460 | SetAxisRange (p1h, P1_GRAPH2D, VAL_MANUAL, xmin, xmax, VAL_NO_CHANGE, 0.0, 1.0); |
||
461 | break; |
||
462 | } |
||
463 | return 0; |
||
464 | } |
||
465 | |||
466 | |||
467 | |||
468 | |||
469 | void plot2d(int h2d, int nslice) { |
||
470 | if (nslice < 0 ) { |
||
471 | nslice=0; |
||
472 | } |
||
473 | if (plothandle2dfit > 0 ) { |
||
474 | DeleteGraphPlot (p1h, P1_GRAPH2D, plothandle2dfit, VAL_IMMEDIATE_DRAW); |
||
475 | plothandle2dfit=0; |
||
476 | } |
||
477 | H2DDraw(h2d,p1h, P1_GRAPH2D, &p1plothandle); |
||
478 | |||
479 | if (sa02Verbose > 2) { |
||
480 | sa02Printf("min %f max %f x:min %f step%f y:min %f step%f\n", |
||
481 | H2DGetMin(h2d),H2DGetMax(h2d), H2DGetMinX(h2d), |
||
482 | H2DGetStepX(h2d),H2DGetMinY(h2d), H2DGetStepY(h2d)); |
||
483 | } |
||
484 | SetCtrlVal(p1h, P1_NSLIY, nslice); |
||
485 | PlotSliceX(p1h,P1_GRAPHY,EVENT_COMMIT, NULL,0,0); |
||
486 | PlotSliceY(p1h,P1_GRAPHY,EVENT_COMMIT, NULL,0,0); |
||
487 | ProcessSystemEvents (); |
||
488 | } |
||
489 | |||
490 | void SetDimming(int state) { |
||
491 | SetCtrlAttribute (p1h, P1_MULTIFPGAWRITE, ATTR_DIMMED, state); |
||
492 | SetCtrlAttribute (p1h, P1_DAQ, ATTR_DIMMED, state); |
||
493 | SetCtrlAttribute (p1h, P1_READOUT, ATTR_DIMMED, state); |
||
494 | SetCtrlAttribute (p1h, P1_FPGAWRITE, ATTR_DIMMED, state); |
||
495 | SetCtrlVal (p1h, P1_LED, state); |
||
496 | SetCtrlAttribute (p2h, P2_DAQ, ATTR_DIMMED, state); |
||
497 | SetCtrlAttribute (p2h, P2_RUNSCRIPT, ATTR_DIMMED, state); |
||
498 | SetCtrlAttribute (p3h, P3_DAQ, ATTR_DIMMED, state); |
||
499 | SetCtrlAttribute (p4h, P4_DAQ, ATTR_DIMMED, state); |
||
500 | SetCtrlAttribute (p1h, P1_STOP, ATTR_DIMMED, !state); |
||
501 | SetCtrlAttribute (p2h, P2_STOP, ATTR_DIMMED, !state); |
||
502 | SetCtrlAttribute (p3h, P3_STOP, ATTR_DIMMED, !state); |
||
503 | SetCtrlAttribute (p4h, P4_STOP, ATTR_DIMMED, !state); |
||
504 | } |
||
505 | |||
506 | |||
507 | uint16_t GetConnectedFebMask(void) { |
||
508 | |||
509 | uint16_t mask=0; |
||
510 | int ison; |
||
511 | for (int i=0; i<4; i++) { |
||
512 | GetCtrlVal(p1h,hapd_onoff[i], &ison); |
||
513 | mask |= (ison << i); |
||
514 | } |
||
515 | sa02Printf("Connected FEBs mask, 0x%0x\n",mask); |
||
516 | return mask; |
||
517 | } |
||
518 | |||
519 | int CVICALLBACK daq(void *functionData) { |
||
520 | |||
521 | char title[256], serial[64]; |
||
522 | int daqmode=1; |
||
523 | #define MAXSIZE 10000 |
||
524 | int h2=0; |
||
525 | int maxsize = MAXSIZE; |
||
526 | uint32_t *rdata; |
||
527 | uint32_t response[2]= {0,0}; |
||
528 | |||
529 | uint32_t fixeddata =0; |
||
530 | int testfixeddata =0; |
||
531 | uint32_t data =0; |
||
532 | uint32_t data0 =0; |
||
533 | uint32_t dataoff =0; |
||
534 | uint32_t dataon =0; |
||
535 | |||
536 | uint32_t cmd =0; |
||
537 | uint32_t chip =0; |
||
538 | uint32_t asicpar =0; |
||
539 | uint32_t asicshft=0; |
||
540 | uint32_t dstep =0; |
||
541 | uint32_t sendswtrg =0; |
||
542 | uint32_t tpenb =0; |
||
543 | |||
544 | uint32_t trglen; |
||
545 | uint16_t mask; |
||
546 | //uint32_t boardnumber_current=0; |
||
547 | // uint32_t hdr[10]; |
||
548 | |||
549 | unsigned int aborttimeout =0; |
||
550 | int append =0; |
||
551 | int remap =0; |
||
552 | int neve =0; |
||
553 | int towrite =0; |
||
554 | int toread =0; |
||
555 | int ch =0; |
||
556 | int output =0; |
||
557 | int externalcmd =0; |
||
558 | int i=0,j=0, ir; |
||
559 | int ich; |
||
560 | //int ison; |
||
561 | |||
562 | char sfixeddata[0xFF]=""; |
||
563 | char scmd[0xFF]=""; |
||
564 | |||
565 | char filename[0xFF]=""; |
||
566 | |||
567 | char externalcommand[0xFF]=""; |
||
568 | |||
569 | FILE *fp=NULL; |
||
570 | int nbtotal=0; |
||
571 | time_t t,told, tstart; |
||
572 | int ncount=0; |
||
573 | int nerrors=0; |
||
574 | int readerror=0; |
||
575 | //int writeevents=0; |
||
576 | double fraction=0; |
||
577 | int board; |
||
578 | double t0; |
||
579 | |||
580 | rdata = malloc(sizeof(uint32_t)*maxsize); |
||
581 | |||
582 | // intercept routine |
||
583 | if (signal (SIGINT, SigInt) == SIG_ERR) { |
||
584 | perror ("sigignore"); |
||
585 | } |
||
586 | |||
587 | |||
588 | mask=GetConnectedFebMask(); |
||
589 | GetCtrlVal(p1h,P1_OUTPUTFILE, filename); |
||
590 | GetCtrlVal(p1h,P1_APPEND,&append); // append the data to the file filename |
||
591 | GetCtrlVal(p1h,P1_FRACTION, &fraction); |
||
592 | |||
593 | GetCtrlVal(p1h,P1_ABORTTOUT, &aborttimeout); |
||
594 | |||
595 | GetCtrlVal( p1h,P1_EXTERNALCMD, externalcommand); |
||
596 | GetCtrlVal( p1h,P1_EXTCMD, &externalcmd); |
||
597 | |||
598 | GetCtrlVal(p1h,P1_FIXEDDATA, sfixeddata); |
||
599 | fixeddata = strtoul (sfixeddata,NULL,0); |
||
600 | GetCtrlVal(p1h,P1_TESTFIXEDDATA, &testfixeddata); |
||
601 | |||
602 | |||
603 | GetCtrlVal(p1h,P1_TOREAD, &toread); |
||
604 | |||
605 | |||
606 | GetCtrlVal(p1h,P1_NEVE, &neve); |
||
607 | GetCtrlVal(p1h,P1_DSTEP, &dstep ); |
||
608 | |||
609 | |||
610 | GetCtrlVal(p1h,P1_SENDSWTRIG,&sendswtrg); |
||
611 | GetCtrlVal(p1h,P1_INTTRGLEN, &trglen); |
||
612 | GetCtrlVal(p1h,P1_DAQMODE, &daqmode); |
||
613 | Sa02DaqMode (daqmode); |
||
614 | Sa02SelectTriggerWithMaskAndLength (sendswtrg, mask, trglen); |
||
615 | |||
616 | |||
617 | GetCtrlVal(p1h,P1_CHIP,&chip); |
||
618 | GetCtrlVal(p1h,P1_CHANNEL,&ch); |
||
619 | GetCtrlVal(p1h,P1_DATA,&data); |
||
620 | data0=data; |
||
621 | GetCtrlVal(p1h,P1_SCANTYPE,&towrite); |
||
622 | switch (towrite) { |
||
623 | case 1: |
||
624 | GetCtrlVal(p1h,P1_WRITECMD,scmd); |
||
625 | if (strcmp(scmd,"MUXASIC")==0) { |
||
626 | remap=1; |
||
627 | } |
||
628 | cmd =sa02GetCmdCode(scmd); |
||
629 | break; |
||
630 | case 3: |
||
631 | GetCtrlVal(p1h,P1_CHANNELOFF,scmd); |
||
632 | dataoff = strtoul (scmd,NULL,0); |
||
633 | GetCtrlVal(p1h,P1_CHANNELON,scmd); |
||
634 | dataon = strtoul (scmd,NULL,0); |
||
635 | chip =data/36; |
||
636 | ch =data%36; |
||
637 | sprintf(scmd,"channel"); |
||
638 | case 2: |
||
639 | GetCtrlVal(p1h,P1_ASICPAR,scmd); |
||
640 | if (strlen(scmd)) cmd = sa02GetAsicCode(scmd,&asicpar, &asicshft); |
||
641 | |||
642 | break; |
||
643 | } |
||
644 | |||
645 | |||
646 | if (remap) { |
||
647 | data = sa02MuxMap(data); |
||
648 | sa02Printf("MUX %d\n",data); |
||
649 | } |
||
650 | |||
651 | GetCtrlVal(p1h,P1_TPENB,&tpenb); |
||
652 | //ReplaceAxisItem (p1h, P1_GRAPH2D, VAL_LEFT_YAXIS, 0, scmd, data0); |
||
653 | |||
654 | if (strlen(filename)>0) { |
||
655 | if (sa02Verbose) { |
||
656 | sa02Printf("Data in the file:%s\n", filename); |
||
657 | } |
||
658 | if (gFp) { |
||
659 | fp=gFp; |
||
357 | f9daq | 660 | } |
661 | else { |
||
326 | f9daq | 662 | if (append) { |
663 | fp=fopen(filename,"ab"); |
||
357 | f9daq | 664 | } |
665 | else { |
||
326 | f9daq | 666 | fp=fopen(filename,"wb"); |
667 | } |
||
668 | } |
||
669 | output=1; |
||
670 | // run header |
||
671 | runinfo.id= RUNINFO_ID; // run record ID |
||
672 | runinfo.len= sizeof(runinfo); |
||
673 | runinfo.cmd= cmd; |
||
674 | runinfo.x0 = data; |
||
675 | runinfo.dx = dstep; |
||
676 | runinfo.nx = neve; |
||
677 | runinfo.chip= chip; |
||
678 | runinfo.ch = ch; |
||
679 | runinfo.neve= toread; |
||
680 | runinfo.writemode= towrite; |
||
681 | sa02Printf("RUNINFO x0=%d nx=%d dx=%d\n", runinfo.x0,runinfo.dx,runinfo.nx); |
||
682 | nbtotal+=fwrite(&runinfo, 1,sizeof(runinfo),fp); //gzip |
||
357 | f9daq | 683 | } |
684 | else { |
||
326 | f9daq | 685 | if (sa02Verbose) { |
686 | sa02Printf("Data are not written to the file!\n"); |
||
687 | } |
||
688 | } |
||
689 | |||
690 | if (!neve & (towrite || toread) ) { |
||
691 | neve=1; |
||
692 | } |
||
693 | |||
694 | |||
695 | time(&t); |
||
696 | tstart=t; |
||
697 | told=t; |
||
698 | t0 = Timer(); |
||
699 | |||
700 | |||
701 | title[0] = 0; |
||
702 | for (i=0; i<4; i++) { |
||
703 | int febon=0; |
||
704 | Sa02TestPulseEnable(i, tpenb); // Enable/disable test pulse |
||
705 | sa02GetSerial(i, serial); |
||
706 | GetCtrlVal(p1h,hapd_onoff[i], &febon); |
||
707 | if (strstr(serial,"0x00000000000000")!=NULL && febon) { |
||
708 | char txt[0xFF]; |
||
709 | sprintf(txt, "FEB %d not connected or firmware not loaded? Serial number error! Switch Off FEB!",i); |
||
710 | MessagePopup ("Error", txt); |
||
711 | return -1; |
||
712 | } |
||
713 | sprintf(title,"%s FEB%d=%s", title, i, serial); |
||
714 | } |
||
715 | |||
716 | /////////////////////////////////////////////////////////////// |
||
717 | int icfa_visible=0; |
||
718 | int icfa_add=0; |
||
719 | GetPanelAttribute (p6h, ATTR_VISIBLE, &icfa_visible); |
||
720 | GetCtrlVal (p6h, MINIRICH_ADD, &icfa_add); |
||
721 | if (icfa_visible) { |
||
357 | f9daq | 722 | icfa_Init(); |
326 | f9daq | 723 | icfa_Histo(); |
357 | f9daq | 724 | } |
326 | f9daq | 725 | /////////////////////////////////////////////////////////////// |
726 | SetCtrlAttribute (p1h, P1_GRAPH2D, ATTR_LABEL_TEXT , title); |
||
727 | H2DInit(h2, "h2d",title, 144*4, 0,1,neve,data0, dstep); |
||
728 | H2DSetTitleY(h2,scmd); |
||
729 | |||
730 | sa02Printf("H2D nx=%d ny=%d i=%d neve=%d\n", H2DGetNbinsX(h2),H2DGetNbinsY(h2), i, neve); |
||
731 | |||
732 | |||
733 | plot2d(h2,1); |
||
734 | for (i=0; i<neve; i++) { |
||
735 | int nb = sizeof(uint32_t); |
||
736 | int count=0; |
||
737 | |||
738 | |||
739 | for (board=0; board<4; board++) { |
||
740 | |||
741 | switch (towrite) { |
||
742 | case 1: { |
||
743 | rdata[count+2]= data; |
||
744 | rdata[count+3]= sa02Cmd(board, cmd, data, chip, ch,1,response); |
||
745 | count+=module_header(cmd,&rdata[count],2 ); |
||
746 | break; |
||
747 | } |
||
748 | case 2: { |
||
749 | uint32_t datal = asicpar & (data << asicshft); |
||
750 | rdata[count+2] = data; |
||
751 | rdata[count+3] = sa02AsicWrite(board, cmd, datal, chip, ch, asicpar,asicshft); |
||
752 | count+=module_header(cmd ,&rdata[count],2); // recid cmd |
||
753 | break; |
||
754 | } |
||
755 | case 3: { |
||
756 | rdata[count+2] = chip*36+ch; |
||
757 | rdata[count+3] = sa02AsicWrite(board, cmd, dataon, chip, ch, asicpar,asicshft); // switch on the channel |
||
758 | count+=module_header(cmd ,&rdata[count],2); // recid cmd |
||
759 | break; |
||
760 | } |
||
761 | } |
||
762 | if (towrite==3) { |
||
763 | SetCtrlVal(p1h,P1_SETVALUE, chip*36+ch ); |
||
357 | f9daq | 764 | } |
765 | else { |
||
326 | f9daq | 766 | SetCtrlVal(p1h,P1_SETVALUE, data); |
767 | } |
||
768 | |||
769 | |||
770 | |||
771 | } |
||
772 | |||
773 | Sa02SetNeve(toread); |
||
774 | sa02Reset(); |
||
775 | |||
776 | // for ( j=0; j< toread; j++) |
||
777 | { |
||
778 | int eventerror = 0; |
||
779 | |||
780 | if ( (count +2 +dsize) >= maxsize) { |
||
781 | |||
782 | maxsize*=2; |
||
783 | sa02Printf("Increasing data buffer to %d elements\n", maxsize); |
||
784 | rdata=realloc(rdata ,sizeof(uint32_t)*maxsize); |
||
785 | } |
||
786 | |||
787 | do { |
||
788 | if (sendswtrg == 1) Sa02SoftwareTrigger(); |
||
789 | nb = sa02Read(mask, &rdata[count+2] ); |
||
357 | f9daq | 790 | } |
791 | while ( nb==0 && !ctrl_c); |
||
326 | f9daq | 792 | if (nb==0) sa02Printf("nb==0 LINE=%d\n",__LINE__); |
793 | |||
794 | if (testfixeddata && nb>0) { |
||
795 | int len = nb / sizeof(uint32_t); |
||
796 | for (ir=0; ir<len; ir++) { |
||
797 | if ( rdata[count+2+ir]!=fixeddata ) { |
||
798 | time(&t); |
||
799 | sa02Printf("INSERT INTO fixederror VALUES ( '%d', '%d','%d','%d','0x%08x','0x%08x' ) \n", t, t-tstart, i*toread+j, ir, rdata[count+2+ir], fixeddata ); |
||
800 | eventerror++; |
||
801 | } |
||
802 | } |
||
803 | } |
||
804 | if (eventerror) { |
||
805 | readerror++; |
||
806 | if (readerror==3) { |
||
807 | ctrl_c = 1; |
||
808 | system("date >> firmware.lock"); |
||
809 | } |
||
357 | f9daq | 810 | } |
811 | else { |
||
326 | f9daq | 812 | readerror= 0; |
813 | } |
||
814 | |||
815 | for (ich=0; ich<144*4; ich++) { |
||
816 | int xch = (143 - ich%144) + ich/144*144; |
||
817 | H2DFillBin(h2, xch,i,rdata[count+2+ich]); |
||
818 | } |
||
357 | f9daq | 819 | |
326 | f9daq | 820 | if (icfa_visible) icfa_Event(&rdata[count+2], icfa_add ); |
357 | f9daq | 821 | |
326 | f9daq | 822 | /* |
823 | for (ich=0; ich<144; ich++) { |
||
824 | // id=(35-ich/4)+gBoardNumber*36; |
||
825 | // shft=(ich%4)*8; |
||
826 | id=(17-ich/8)+sa02BoardNumber*18; |
||
827 | shft=(ich%8)*4; |
||
828 | |||
829 | // if ( rdata[count+2+id] & (0xFF <<shft) ) { |
||
830 | if ( rdata[count+2+id] & (0xF <<shft) ) { |
||
831 | H2DFillBin(h2, ich,i,1); |
||
832 | } |
||
833 | if (sa02Verbose>2) { |
||
834 | sa02Printf("%02X ",(rdata[count+2+id]>> shft)& 0xF ); |
||
835 | // sa02Printf("%02X ",(rdata[count+2+id]>> shft)& 0xFF ); |
||
836 | } |
||
837 | } |
||
838 | */ |
||
839 | |||
840 | if (sa02Verbose>2) sa02Printf("\n" ); |
||
841 | if (nb>=0) count+=module_header(0x3,&rdata[count],nb/sizeof(uint32_t)); // recid 0x3 |
||
842 | |||
843 | if (ctrl_c) { |
||
844 | sa02Printf("ctrl_c detected ....\n"); |
||
845 | break; |
||
846 | } |
||
847 | |||
848 | time(&t); |
||
849 | if (t!=told ) { |
||
850 | double done= (double) (i)/neve; |
||
851 | EstimatedFinish(p1h, P1_PROGRESS, P1_ETA, tstart, done); |
||
852 | plot2d(h2,i-1); |
||
853 | GetPanelAttribute (p6h, ATTR_VISIBLE, &icfa_visible); |
||
854 | if (icfa_visible) icfa_Draw(); |
||
855 | SetCtrlVal(p1h,P1_CUREVE, j); |
||
856 | sa02Printf("%d events in %2.2f min (%d s) TIMEOUTS=%d %s",ncount, (double)(t-tstart)/60.,t-tstart, nerrors, ctime(&t)); |
||
857 | } |
||
858 | if (aborttimeout && (t-tstart)>aborttimeout) { |
||
859 | sa02Printf("Abort timeout reached ....\n"); |
||
860 | ctrl_c=1; |
||
861 | break; |
||
862 | } |
||
863 | told=t; |
||
864 | if (nb==0) { |
||
865 | nerrors++; |
||
866 | //j--; /// kako potem pride cez zeljeno stevil ozadetkov? |
||
357 | f9daq | 867 | } |
868 | else { |
||
326 | f9daq | 869 | ncount++; |
870 | } |
||
871 | } |
||
872 | if (externalcmd) { |
||
873 | char ecmd[256]; |
||
874 | sprintf(ecmd,"%s %u %u %u %u",externalcommand,(unsigned int) tstart,data, rdata[2], rdata[3]); |
||
875 | if (sa02Verbose) { |
||
876 | sa02Printf("Executing external command %s\n",ecmd); |
||
877 | } |
||
878 | system(ecmd); |
||
879 | } |
||
880 | |||
881 | if (output && Random(0,1)<fraction) { |
||
882 | evtrec.id = EVTREC_ID; |
||
883 | evtrec.len=count*sizeof(uint32_t)+ sizeof(evtrec); |
||
884 | evtrec.time= (uint32_t) time(NULL); |
||
885 | evtrec.nev=i; |
||
886 | nb = (int) fwrite( &evtrec, 1, sizeof(evtrec),fp); //gzip |
||
887 | if (count) { |
||
888 | nb+= (int) fwrite(&rdata[0],1,count*sizeof(uint32_t),fp); //gzip |
||
889 | } |
||
890 | if (nb!= (int) evtrec.len) { |
||
891 | sa02Printf("Error writing! %d!=%d\n",nb,evtrec.len); |
||
892 | } |
||
893 | nbtotal+= nb; |
||
894 | } |
||
895 | |||
896 | if (sa02Verbose==1) { |
||
897 | sa02Printf("[%d/%d] %u \t", i,count, (unsigned int) time(NULL)); |
||
898 | PrintData(rdata,count); |
||
899 | } |
||
900 | if (towrite ==3) { |
||
901 | sa02AsicWrite(board, cmd, dataoff, chip, ch, asicpar, asicshft); |
||
902 | ch += dstep; |
||
903 | if (ch>35) { |
||
904 | ch-=36; |
||
905 | chip++; |
||
906 | } |
||
357 | f9daq | 907 | } |
908 | else { |
||
326 | f9daq | 909 | data += dstep; |
910 | } |
||
911 | if (ctrl_c ) { |
||
912 | if (!testfixeddata) { |
||
913 | sa02Printf("Ctrl+C Program interrupted ....\n"); |
||
914 | } |
||
915 | break; |
||
916 | } |
||
917 | } |
||
918 | plot2d(h2, i-1); |
||
357 | f9daq | 919 | if (icfa_visible) icfa_Draw(); |
326 | f9daq | 920 | |
921 | if (output) { |
||
922 | sprintf(scmd,"channel;daqtime=%f", Timer()-t0 ); |
||
923 | H2DSetTitleX(h2,scmd); |
||
924 | H2DWrite2File(h2,fp); |
||
925 | if (!gFp) { |
||
926 | fclose(fp); |
||
927 | } |
||
928 | } |
||
929 | if (sa02Verbose>1) sa02Printf("%d bytes written to file %s\n", nbtotal, filename); |
||
930 | time(&t); |
||
931 | if (toread && !testfixeddata) sa02Printf("%d events in %2.2f min (%f s) TIMEOUTS=%d %s",ncount, (double)(Timer()-t0)/60.,Timer()-t0, nerrors, ctime(&t)); |
||
932 | free(rdata); |
||
933 | |||
934 | return 0; |
||
935 | } |
||
936 | |||
937 | int CVICALLBACK quit (int panel, int event, void *callbackData, |
||
938 | int eventData1, int eventData2) { |
||
939 | switch (event) { |
||
940 | case EVENT_CLOSE: |
||
941 | // Stop timer callbacks |
||
942 | SuspendTimerCallbacks(); |
||
943 | QuitUserInterface (0); |
||
944 | break; |
||
945 | } |
||
946 | return 0; |
||
947 | } |
||
948 | |||
949 | int CVICALLBACK Exit (int panel, int control, int event, |
||
950 | void *callbackData, int eventData1, int eventData2) { |
||
951 | switch (event) { |
||
952 | case EVENT_COMMIT: |
||
953 | quit(0,0,NULL,0,0); |
||
954 | exit(0); |
||
955 | } |
||
956 | return 0; |
||
957 | } |
||
958 | |||
959 | int SetParametersFromFile( const char *fname) { |
||
960 | uint32_t gdata; |
||
961 | uint32_t cdata; |
||
962 | |||
963 | sa02AsicGlobalRegister *greg = (sa02AsicGlobalRegister *) &gdata ; |
||
964 | sa02AsicChannelRegister *creg = (sa02AsicChannelRegister *) &cdata ; |
||
965 | unsigned short cregdata[8*144*4]; |
||
966 | unsigned short gregdata[7*4*4]; |
||
967 | #define NDIM 400 |
||
968 | int ndim=NDIM; |
||
969 | char line[NDIM]; |
||
970 | char cmd[NDIM]; |
||
971 | char sasic[NDIM]; |
||
972 | char v0[NDIM]; |
||
973 | char v1[NDIM]; |
||
974 | int asic=0, ch=0; |
||
975 | int gval=0, cval=0; |
||
976 | int board=0; |
||
977 | int row=0; |
||
978 | uint32_t sa02code; |
||
979 | int i; |
||
980 | ssize_t size; |
||
981 | FILE *fp = NULL; |
||
982 | if ( GetFileInfo(fname,&size) ) fp = fopen(fname,"r"); |
||
983 | if (!fp) { |
||
984 | sa02Printf("Error! Cannot open file %s\n",fname); |
||
985 | return -1; |
||
986 | } |
||
987 | for (i=0; i<8*144*4; i++) { |
||
988 | cregdata[i]=0; |
||
989 | } |
||
990 | for (i=0; i<7*4*4; i++) { |
||
991 | gregdata[i]=0; |
||
992 | } |
||
993 | gdata=0; |
||
994 | cdata=0; |
||
995 | ResetTextBox(p3h,P3_FPGAPAR,""); |
||
996 | while (fgets(line,ndim,fp)!=NULL) { |
||
997 | int nb = sscanf(line,"%s%s%s%s",cmd,sasic,v0,v1); |
||
998 | if (nb<1 || cmd[0]=='#') { |
||
999 | continue; |
||
1000 | } |
||
1001 | asic = strtoul (sasic,NULL,0); |
||
1002 | ch = strtoul (v0,NULL,0); |
||
1003 | gval = strtoul (v0,NULL,0); |
||
1004 | cval = strtoul (v1,NULL,0); |
||
1005 | if (sa02Verbose>2) { |
||
1006 | sa02Printf("%d %s",nb,line); |
||
1007 | } |
||
1008 | sa02code = sa02GetCmdCode(cmd); |
||
1009 | if (strcmp(cmd,"MUXASIC")==0) { |
||
1010 | asic = sa02MuxMap(asic); |
||
1011 | } |
||
1012 | switch (nb) { |
||
1013 | case 1: { |
||
1014 | if ( sa02code ) { |
||
1015 | SetCtrlVal(p3h,P3_FPGAPAR,line); |
||
1016 | |||
1017 | break; |
||
1018 | } |
||
1019 | break; |
||
1020 | } |
||
1021 | case 2: { |
||
1022 | if ( sa02code ) { |
||
1023 | SetCtrlVal(p3h,P3_FPGAPAR,line); |
||
1024 | |||
1025 | break; |
||
1026 | } |
||
1027 | if (strcmp(cmd,"param_board")==0) { |
||
1028 | board= asic; |
||
1029 | } |
||
1030 | if (strcmp(cmd,"load_global")==0) { |
||
1031 | row= asic+1; |
||
1032 | greg->id=13; |
||
1033 | /* |
||
1034 | SetTableCellVal (p3h, P3_GREG, MakePoint (1,row), greg->phasecmps); |
||
1035 | SetTableCellVal (p3h, P3_GREG, MakePoint (2,row), greg->gain); |
||
1036 | SetTableCellVal (p3h, P3_GREG, MakePoint (3,row), greg->shapingtime); |
||
1037 | SetTableCellVal (p3h, P3_GREG, MakePoint (4,row), greg->comparator); |
||
1038 | SetTableCellVal (p3h, P3_GREG, MakePoint (5,row), greg->vrdrive); |
||
1039 | SetTableCellVal (p3h, P3_GREG, MakePoint (6,row), greg->monitor); |
||
1040 | SetTableCellVal (p3h, P3_GREG, MakePoint (7,row), greg->id); |
||
1041 | */ |
||
1042 | gregdata[(board*4+asic)*7] = greg->phasecmps; |
||
1043 | gregdata[(board*4+asic)*7+1] = greg->gain; |
||
1044 | gregdata[(board*4+asic)*7+2] = greg->shapingtime; |
||
1045 | gregdata[(board*4+asic)*7+3] = greg->comparator; |
||
1046 | gregdata[(board*4+asic)*7+4] = greg->vrdrive; |
||
1047 | gregdata[(board*4+asic)*7+5] = greg->monitor; |
||
1048 | gregdata[(board*4+asic)*7+6] = greg->id; |
||
1049 | |||
1050 | break; |
||
1051 | } |
||
1052 | break; |
||
1053 | } |
||
1054 | case 3: { |
||
1055 | if ( sa02code) { |
||
1056 | SetCtrlVal(p3h,P3_FPGAPAR,line); |
||
1057 | break; |
||
1058 | } |
||
1059 | if (strcmp(cmd,"param_global")==0) { |
||
1060 | gdata = 0; |
||
1061 | break; |
||
1062 | } |
||
1063 | if (strcmp(cmd,"phasecmps")==0) { |
||
1064 | greg->phasecmps = gval; |
||
1065 | break; |
||
1066 | } |
||
1067 | if (strcmp(cmd,"gain") ==0) { |
||
1068 | greg->gain = gval; |
||
1069 | break; |
||
1070 | } |
||
1071 | if (strcmp(cmd,"shapingtime")==0) { |
||
1072 | greg->shapingtime = gval; |
||
1073 | break; |
||
1074 | } |
||
1075 | if (strcmp(cmd,"comparator")==0) { |
||
1076 | greg->comparator = gval; |
||
1077 | break; |
||
1078 | } |
||
1079 | if (strcmp(cmd,"vrdrive")==0) { |
||
1080 | greg->vrdrive = gval; |
||
1081 | break; |
||
1082 | } |
||
1083 | if (strcmp(cmd,"monitor")==0) { |
||
1084 | greg->monitor = gval; |
||
1085 | break; |
||
1086 | } |
||
1087 | if (strcmp(cmd,"load_ch")==0) { |
||
1088 | row = board*144+asic*36+ch+1; |
||
1089 | /* |
||
1090 | SetTableCellVal (p3h, P3_CREG, MakePoint (1,row), asic); |
||
1091 | SetTableCellVal (p3h, P3_CREG, MakePoint (2,row), ch); |
||
1092 | SetTableCellVal (p3h, P3_CREG, MakePoint (3,row), creg->decaytime); |
||
1093 | SetTableCellVal (p3h, P3_CREG, MakePoint (4,row), creg->offset); |
||
1094 | SetTableCellVal (p3h, P3_CREG, MakePoint (5,row), creg->fineadj_unipol); |
||
1095 | SetTableCellVal (p3h, P3_CREG, MakePoint (6,row), creg->fineadj_diff); |
||
1096 | SetTableCellVal (p3h, P3_CREG, MakePoint (7,row), creg->tpenb); |
||
1097 | SetTableCellVal (p3h, P3_CREG, MakePoint (8,row), creg->kill); |
||
1098 | */ |
||
1099 | |||
1100 | cregdata[(row -1)*8] = (unsigned short) asic; |
||
1101 | cregdata[(row -1)*8+1] = (unsigned short) ch; |
||
1102 | cregdata[(row -1)*8+2] = creg->decaytime; |
||
1103 | cregdata[(row -1)*8+3] = creg->offset; |
||
1104 | cregdata[(row -1)*8+4] = creg->fineadj_unipol; |
||
1105 | cregdata[(row -1)*8+5] = creg->fineadj_diff; |
||
1106 | cregdata[(row -1)*8+6] = creg->tpenb; |
||
1107 | cregdata[(row -1)*8+7] = creg->kill; |
||
1108 | cdata=0; |
||
1109 | break; |
||
1110 | } |
||
1111 | if (strcmp(cmd,"select")==0) { |
||
1112 | sa02Printf ("%s not implemeted yet\n", cmd); |
||
1113 | break; |
||
1114 | } |
||
1115 | break; |
||
1116 | } |
||
1117 | case 4: { |
||
1118 | if (strcmp(cmd,"param_ch")==0) { |
||
1119 | cdata = 0; |
||
1120 | break; |
||
1121 | } |
||
1122 | if (strcmp(cmd,"decaytime")==0) { |
||
1123 | creg->decaytime = cval; |
||
1124 | break; |
||
1125 | } |
||
1126 | if (strcmp(cmd,"offset")==0) { |
||
1127 | creg->offset = cval; |
||
1128 | break; |
||
1129 | } |
||
1130 | if (strcmp(cmd,"fineadj_unipol")==0) { |
||
1131 | creg->fineadj_unipol = cval; |
||
1132 | break; |
||
1133 | } |
||
1134 | if (strcmp(cmd,"fineadj_diff")==0) { |
||
1135 | creg->fineadj_diff = cval; |
||
1136 | break; |
||
1137 | } |
||
1138 | if (strcmp(cmd,"tpenb")==0) { |
||
1139 | creg->tpenb = cval; |
||
1140 | break; |
||
1141 | } |
||
1142 | if (strcmp(cmd,"kill")==0) { |
||
1143 | creg->kill = cval; |
||
1144 | break; |
||
1145 | } |
||
1146 | break; |
||
1147 | } |
||
1148 | } |
||
1149 | |||
1150 | } |
||
1151 | fclose(fp); |
||
1152 | SetTableCellRangeVals (p3h, P3_CREG, MakeRect (1, 1, 144*4, 8), cregdata, VAL_ROW_MAJOR); |
||
1153 | SetTableCellRangeVals (p3h, P3_GREG, MakeRect (1, 1, 4*4, 7) , gregdata, VAL_ROW_MAJOR); |
||
1154 | |||
1155 | sa02Printf("Parameters loaded from file %s to Parameter Panel \n", fname); |
||
1156 | return 0; |
||
1157 | } |
||
1158 | |||
1159 | void CVICALLBACK MenuCB(int menubar, int menuItem, void *callbackData, int panel) { |
||
1160 | switch (menuItem) { |
||
1161 | case MENU_OPERATIO_CAEN_V729: |
||
1162 | DisplayPanel(p4h); |
||
1163 | break; |
||
1164 | case MENU_OPERATIO_SA02CFG : |
||
1165 | DisplayPanel(p3h); |
||
1166 | break; |
||
1167 | case MENU_OPERATIO_2DSCAN: |
||
1168 | DisplayPanel(p2h); |
||
1169 | break; |
||
1170 | case MENU_OPERATIO_LASER: |
||
1171 | DisplayPanel(p5h); |
||
1172 | break; |
||
1173 | case MENU_MINIRICH: |
||
1174 | DisplayPanel(p6h); |
||
357 | f9daq | 1175 | break; |
326 | f9daq | 1176 | case MENU_OPERATIO_EXIT : |
1177 | quit(0,0,NULL,0,0); |
||
1178 | exit(0); |
||
1179 | //loop_on=0; |
||
1180 | break; |
||
1181 | case MENU_HELP : |
||
1182 | sa02Help(); |
||
1183 | break; |
||
1184 | } |
||
1185 | } |
||
1186 | |||
1187 | int CVICALLBACK daq_readonly(void *functionData) { |
||
1188 | int h2=0; |
||
1189 | uint32_t trglen; |
||
1190 | uint32_t data[10000]; |
||
1191 | uint16_t mask; |
||
1192 | //int ison; |
||
1193 | //int *fdata= (int *) functionData; |
||
1194 | int nbit,neve,nb,ch,i,j,sendswtrg; |
||
1195 | |||
1196 | time_t t,told, tstart; |
||
1197 | //int gBoardNumber=0; |
||
1198 | int ploteachevent =0; |
||
1199 | |||
1200 | GetCtrlVal(p1h,P1_PLOTEACHEVENT, &ploteachevent); |
||
1201 | GetCtrlVal(p1h,P1_TOREAD , &neve); |
||
1202 | GetCtrlVal(p1h,P1_NSLIX , &nbit); |
||
1203 | if (nbit>7) { |
||
1204 | nbit=7; |
||
1205 | } |
||
1206 | GetCtrlVal(p1h,P1_SENDSWTRIG,&sendswtrg); |
||
1207 | GetCtrlVal(p1h,P1_INTTRGLEN, &trglen); |
||
1208 | |||
1209 | mask=GetConnectedFebMask(); |
||
1210 | Sa02SelectTriggerWithMaskAndLength (sendswtrg, mask, trglen); |
||
1211 | Sa02SetNeve(2); |
||
1212 | |||
1213 | H2DInit(h2,"hbit","Bit Occupancy", 144*4, 0,1,8,0, 1); |
||
1214 | H2DSetTitleX(h2,"channel"); |
||
1215 | H2DSetTitleY(h2,"Data bit"); |
||
1216 | time(&t); |
||
1217 | tstart=t; |
||
1218 | told=t; |
||
1219 | for ( j=0; j< neve; j++) { |
||
1220 | do { |
||
1221 | if (sendswtrg==1) Sa02SoftwareTrigger(); |
||
1222 | nb = sa02Read(mask, data ); |
||
357 | f9daq | 1223 | } |
1224 | while ( nb==0 && !ctrl_c); |
||
326 | f9daq | 1225 | if (nb==0) sa02Printf("nb==0 LINE=%d\n",__LINE__); |
1226 | |||
1227 | if (ctrl_c==1) break; |
||
1228 | |||
1229 | for (ch=0; ch<144*4; ch++) { |
||
1230 | int board = ch/144; |
||
1231 | int xch = (143 - ch%144) + board *144; |
||
1232 | for (i=0; i<8; i++) if (data[ch] & (1<<i) ) H2DFillBin(h2,xch,i,1); |
||
1233 | } |
||
1234 | /* |
||
1235 | for (ch=0; ch<144*4; ch++) |
||
1236 | { |
||
1237 | id=(35-ch/4)+gBoardNumber*36; |
||
1238 | shft=(ch%4)*8; |
||
1239 | for (i=0; i<8; i++) |
||
1240 | { |
||
1241 | if (data[id] & (1<<(i+shft)) ) |
||
1242 | { |
||
1243 | H2DFillBin(h2,ch,i,1); |
||
1244 | } |
||
1245 | } |
||
1246 | if (sa02Verbose>2) |
||
1247 | { |
||
1248 | sa02Printf("%02X ",(data[id]>> shft)& 0xFF ); |
||
1249 | } |
||
1250 | } |
||
1251 | */ |
||
1252 | |||
1253 | if (sa02Verbose>2) { |
||
1254 | sa02Printf("\n" ); |
||
1255 | } |
||
1256 | |||
1257 | time(&t); |
||
1258 | if (t!=told || ploteachevent) { |
||
1259 | sa02Printf("%d events in %2.2f min (%d s) %s",j, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
||
1260 | GetCtrlVal(p1h,P1_NSLIY,&nbit); |
||
1261 | plot2d(h2, nbit); |
||
1262 | GetCtrlVal(p1h,P1_PLOTEACHEVENT, &ploteachevent); |
||
1263 | SetCtrlVal(p1h,P1_CUREVE, j); |
||
1264 | ProcessSystemEvents (); |
||
1265 | ProcessSystemEvents (); |
||
1266 | } |
||
1267 | |||
1268 | told=t; |
||
1269 | |||
1270 | } |
||
1271 | |||
1272 | plot2d(h2, nbit); |
||
1273 | SetCtrlVal(p1h,P1_CUREVE, j); |
||
1274 | |||
1275 | return 0; |
||
1276 | } |
||
1277 | |||
1278 | int CVICALLBACK LoadParameters (int panel, int control, int event, |
||
1279 | void *callbackData, int eventData1, int eventData2) { |
||
1280 | char fname[0xFF]; |
||
1281 | uint16_t mask; |
||
1282 | switch (event) { |
||
1283 | case EVENT_COMMIT: |
||
1284 | mask=GetConnectedFebMask(); |
||
1285 | sa02Printf("LoadParameters 0x%0x\n", mask); |
||
1286 | GetCtrlVal(p3h, P3_INPUTFILE, fname); |
||
1287 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
||
1288 | SetCtrlAttribute (panel, control, ATTR_DIMMED, 1); |
||
1289 | sa02LoadParametersFromFile(fname, mask); |
||
1290 | SetCtrlAttribute (panel, control, ATTR_DIMMED, 0); |
||
1291 | |||
1292 | break; |
||
1293 | } |
||
1294 | return 0; |
||
1295 | } |
||
1296 | |||
1297 | int SlowControl(uint32_t board, FILE *fp) { |
||
1298 | uint32_t data;//,step,cmd;//,response[2]= {0,0}; |
||
1299 | int chip,channel,i; |
||
1300 | //double doubleval; |
||
1301 | char saddress[0xFF]; |
||
1302 | double sdata[20]; |
||
1303 | |||
1304 | chip=0; |
||
1305 | channel=0; |
||
1306 | data=0; |
||
1307 | |||
1308 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
||
1309 | sa02Status(board,saddress,sdata); |
||
1310 | SetCtrlVal(p1h,fpga_serials[board],saddress); |
||
1311 | if (fp) { |
||
1312 | fprintf(fp,"<slowc>\n<id>%d</id>\n", board ); |
||
1313 | fprintf(fp,"<dna>%s</dna>\n",saddress ); |
||
1314 | for (i=0; i<12; i++) fprintf(fp,"<%s>%f</%s>\n",slowcname[i],sdata[i],slowcname[i] ); |
||
1315 | fprintf(fp,"</slowc>\n" ); |
||
1316 | } |
||
1317 | PlotStripChart (p1h, chart_control[board], sdata, 12, 0, 0, VAL_DOUBLE); |
||
1318 | return 0; |
||
1319 | } |
||
1320 | |||
1321 | |||
1322 | int WriteChannelParameters ( int offset, int fine_offset, int tpenb) { |
||
1323 | |||
1324 | uint32_t response[2]= {0,0}; |
||
1325 | uint32_t cdata; |
||
1326 | |||
1327 | sa02AsicChannelRegister *creg = (sa02AsicChannelRegister *) &cdata ; |
||
1328 | unsigned int i=0, j=0; |
||
1329 | int row=0; |
||
1330 | unsigned short val,asic,ch, board; |
||
1331 | uint16_t mask=GetConnectedFebMask(); |
||
1332 | for (j=0; j<144*4; j++) { |
||
1333 | i = j%144; |
||
1334 | board = (unsigned short) j/144; |
||
1335 | asic=(unsigned short )(i/36); |
||
1336 | ch=(unsigned short )(i%36); |
||
1337 | row=j+1; |
||
1338 | GetTableCellVal (p3h, P3_CREG, MakePoint (1,row), &asic); |
||
1339 | GetTableCellVal (p3h, P3_CREG, MakePoint (2,row), &ch); |
||
1340 | GetTableCellVal (p3h, P3_CREG, MakePoint (3,row), &val); |
||
1341 | creg->decaytime=val; |
||
1342 | creg->offset = offset; |
||
1343 | creg->fineadj_unipol = fine_offset; |
||
1344 | GetTableCellVal (p3h, P3_CREG, MakePoint (6,row), &val); |
||
1345 | creg->fineadj_diff = val; |
||
1346 | creg->tpenb = tpenb; |
||
1347 | //sa02Printf("===%d %d\n",i, tpenb); |
||
1348 | GetTableCellVal (p3h, P3_CREG, MakePoint (8,row), &val); |
||
1349 | creg->kill = val; |
||
1350 | creg->unused=0; |
||
1351 | if ( mask &(1<<board)) sa02Cmd(board,SA0x_ASIC0_CREG, cdata, asic, ch,1,response); |
||
1352 | |||
1353 | if (ctrl_c) { |
||
1354 | break; |
||
1355 | } |
||
1356 | } |
||
1357 | return 0; |
||
1358 | } |
||
1359 | |||
1360 | int FebTestAna(void) { |
||
1361 | int current_run; |
||
1362 | char cmdCommand[0xFF]; |
||
1363 | current_run = GetRunNumberFromFile("current_run.txt"); |
||
1364 | sprintf(cmdCommand ,"C:/root/bin/root.exe \"../macros/febreport.cxx(\\\"data\\\", %d )\"", current_run); |
||
1365 | sa02Printf("%s\n",cmdCommand); |
||
1366 | LaunchExecutable(cmdCommand); |
||
1367 | return 0; |
||
1368 | } |
||
1369 | |||
1370 | int FebTest(void) { |
||
1371 | int board=0, j=0, value, step; |
||
1372 | |||
1373 | FILE *fp; |
||
1374 | int ndim=400; |
||
1375 | char line[ndim]; |
||
1376 | int current_run=1; |
||
1377 | time_t t; |
||
1378 | int start; |
||
1379 | int addheader=1; |
||
1380 | char filename[0xFF]; |
||
1381 | char cmdCommand[0xFF]; |
||
1382 | |||
1383 | uint32_t mask=GetConnectedFebMask(); |
||
1384 | |||
1385 | LoadParameters(p3h, P3_LOADPAR,EVENT_COMMIT,NULL,0,0); |
||
1386 | |||
1387 | |||
1388 | fp = fopen ("current_run.txt","r"); |
||
1389 | if (fp) { |
||
1390 | if (fgets(line,ndim,fp)!=NULL) current_run=atoi(line)+1; |
||
1391 | fclose(fp); |
||
1392 | fp= NULL; |
||
1393 | } |
||
1394 | |||
1395 | sprintf(line,"data\\febtest_%04d.dat",current_run ); |
||
1396 | SetCtrlVal(p1h,P1_OUTPUTFILE, line); |
||
1397 | |||
1398 | SetCtrlVal(p1h,P1_SENDSWTRIG,3 ); // set internal trigger |
||
1399 | SendTriggerTypeCB(p1h,P1_TEST, EVENT_COMMIT,NULL, 0,0); |
||
1400 | |||
1401 | ThresholdLinearityCB (p1h, P1_THRVSADC, EVENT_COMMIT, NULL, 0, 0 ); |
||
1402 | |||
1403 | GetCtrlVal(p1h,P1_OUTPUTFILE, filename); |
||
1404 | fp = fopen(line, "ab"); |
||
1405 | if(fp) { |
||
1406 | for (board=0; board<4; board++) if ( mask &(1<<board)) H1DWrite2File(board,fp); |
||
1407 | fclose(fp); |
||
1408 | } |
||
1409 | |||
1410 | |||
1411 | sprintf(line,"data/febslowc_%04d.xml",current_run ); |
||
1412 | // SetCtrlVal(p1h, P1_RUNID, current_run); |
||
1413 | fp = fopen (line,"w"); |
||
1414 | fprintf(fp,"<febtest>\n"); |
||
1415 | time(&t); |
||
1416 | fprintf(fp,"<time>%s</time>\n", ctime(&t)); |
||
1417 | |||
1418 | |||
1419 | |||
1420 | if (!ctrl_c) for (board=0; board<4; board++) { |
||
1421 | if ( mask &(1<<board)) { |
||
1422 | for (j=0; j<10; j++) { |
||
1423 | SlowControl(board,fp); |
||
1424 | ProcessSystemEvents (); |
||
1425 | if (ctrl_c) break; |
||
1426 | } |
||
1427 | } |
||
1428 | if (ctrl_c) break; |
||
1429 | } |
||
1430 | |||
1431 | |||
1432 | fprintf(fp,"</febtest>\n"); |
||
1433 | fclose(fp); |
||
1434 | |||
1435 | |||
1436 | fp = fopen ("current_run.txt","w"); |
||
1437 | fprintf(fp,"%d\n", current_run); |
||
1438 | fclose(fp); |
||
1439 | |||
1440 | |||
1441 | |||
1442 | |||
1443 | |||
1444 | WriteChannelParameters ( 0,0,0); // Test pulse on all channels |
||
1445 | for (board=0; board<4; board++) if ( mask &(1<<board)) SlowControl(board,fp); |
||
1446 | SetCtrlVal(p1h,P1_TPENB,1); // enable test pulse |
||
1447 | |||
1448 | SetCtrlVal(p1h,P1_DATA, 350); |
||
1449 | SetCtrlVal(p1h,P1_NEVE, 150); |
||
1450 | |||
1451 | GetCtrlVal(p1h,P1_DATA, &start); |
||
1452 | |||
1453 | daq(NULL); |
||
1454 | SetCtrlVal(p1h,P1_TPENB,0); // disable test pulse |
||
1455 | |||
1456 | |||
1457 | // coarse offset |
||
1458 | step=1; |
||
1459 | if (!ctrl_c) for (value=0; value<16; value+=step) { |
||
1460 | if (addheader) { |
||
1461 | iteratorrec.id = ITERATORREC_ID; |
||
1462 | iteratorrec.len = sizeof(iteratorrec); |
||
1463 | iteratorrec.value = value; |
||
1464 | iteratorrec.n = 16; |
||
1465 | iteratorrec.step = step; |
||
1466 | iteratorrec.level = 1; |
||
1467 | GetCtrlVal(p1h,P1_OUTPUTFILE, filename); |
||
1468 | fp = fopen(filename, "ab"); |
||
1469 | if(fp) { |
||
1470 | fwrite (&iteratorrec, 1, iteratorrec.len, fp); |
||
1471 | fclose(fp); |
||
1472 | } |
||
1473 | } |
||
1474 | |||
1475 | WriteChannelParameters ( value,0,1); |
||
1476 | |||
1477 | SetCtrlVal(p1h,P1_DATA,start - (value%8) * 13 + (value/8)*13*8 ); |
||
1478 | sa02Printf("offset=>%d\n", value); |
||
1479 | daq(NULL); |
||
1480 | if (ctrl_c) break; |
||
1481 | } |
||
1482 | |||
1483 | // fine offset |
||
1484 | if (!ctrl_c) for (value=0; value<16; value+=step) { |
||
1485 | if (addheader) { |
||
1486 | iteratorrec.id = ITERATORREC_ID; |
||
1487 | iteratorrec.len = sizeof(iteratorrec); |
||
1488 | iteratorrec.value = value; |
||
1489 | iteratorrec.n = 16; |
||
1490 | iteratorrec.step = step; |
||
1491 | iteratorrec.level = 1; |
||
1492 | GetCtrlVal(p1h,P1_OUTPUTFILE, filename); |
||
1493 | fp = fopen(filename, "ab"); |
||
1494 | if(fp) { |
||
1495 | fwrite (&iteratorrec, 1, iteratorrec.len, fp); |
||
1496 | fclose(fp); |
||
1497 | } |
||
1498 | } |
||
1499 | |||
1500 | |||
1501 | WriteChannelParameters (0, value,1); |
||
1502 | |||
1503 | SetCtrlVal(p1h,P1_DATA, start - (value%8) + (value/8)*8 ); |
||
1504 | sa02Printf("offset=>%d\n", value); |
||
1505 | daq(NULL); |
||
1506 | if (ctrl_c) break; |
||
1507 | } |
||
1508 | |||
1509 | SetCtrlVal(p1h,P1_DATA, start); |
||
1510 | |||
1511 | GetCtrlVal(p1h,P1_OUTPUTFILE, filename); |
||
1512 | |||
1513 | sprintf(cmdCommand,"..\\sa02read -i %s -o data\\febtest_%04d.root", filename, current_run); |
||
1514 | sa02Printf("%s\n",cmdCommand); |
||
1515 | LaunchExecutable(cmdCommand); |
||
1516 | |||
1517 | //sprintf(cmdCommand ,"C:/root/bin/root.exe ../macros/febreport.cxx(\\\"data/febtest_%04d.root\\\")", current_run); |
||
1518 | sprintf(cmdCommand ,"C:/root/bin/root.exe \"../macros/febreport.cxx(\\\"data\\\", %d )\"", current_run); |
||
1519 | sa02Printf("%s\n",cmdCommand); |
||
1520 | LaunchExecutable(cmdCommand); |
||
1521 | |||
1522 | sprintf(line,"%s", "test.dat"); |
||
1523 | SetCtrlVal(p1h,P1_OUTPUTFILE, line); |
||
1524 | //daq(NULL); |
||
1525 | return 0; |
||
1526 | } |
||
1527 | |||
1528 | |||
1529 | int CVICALLBACK ThresholdLinearityCB (int panel, int control, int event, |
||
1530 | void *callbackData, int eventData1, int eventData2) { |
||
1531 | const int kmax= 1024; |
||
1532 | const int boardmax= 4; |
||
1533 | |||
1534 | switch (event) { |
||
1535 | case EVENT_COMMIT: { |
||
1536 | uint32_t val,retval, board,data,response[2]= {0,0}; |
||
1537 | int k; |
||
1538 | int chip,channel; |
||
1539 | double doubleval; |
||
1540 | time_t t,told; |
||
1541 | char title[0xFF]; |
||
1542 | char name[0xFF]; |
||
1543 | int h1=0; |
||
1544 | uint16_t mask=GetConnectedFebMask(); |
||
1545 | chip=0; |
||
1546 | channel=0; |
||
1547 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
||
1548 | |||
1549 | for (board=0; board<boardmax; board++) if ( mask &(1<<board)) { |
||
1550 | char serial[0xFF]; |
||
1551 | GetCtrlVal(p1h,hapd_serials[board],serial ); |
||
1552 | sprintf(title,"VTH1 linearity, position %d sn=%s", board, serial); |
||
1553 | sprintf(name,"vth1_%d", board); |
||
1554 | H1DInit(h1+board, name,title, kmax, 0 ,1); |
||
1555 | H1DSetTitleX(h1+board,"VTH1"); |
||
1556 | H1DSetTitleY(h1+board,"ADC(VTH1)"); |
||
1557 | SetCtrlAttribute (p1h, P1_GRAPH, ATTR_XNAME, H1DGetTitleX(h1+board) ); |
||
1558 | SetCtrlAttribute (p1h, P1_GRAPH, ATTR_YNAME, H1DGetTitleY(h1+board) ); |
||
1559 | //SetCtrlAttribute (p1h, P1_GRAPH, ATTR_LABEL_TEXT , H1DGetTitle(h1+board) ); |
||
1560 | if (phandle[board]> 0 ) DeleteGraphPlot (p1h, P1_GRAPH, phandle[board], VAL_IMMEDIATE_DRAW); |
||
1561 | phandle[board] = 0; |
||
1562 | } |
||
1563 | for (board=0; board<boardmax; board++) if ( mask &(1<<board)) { |
||
1564 | val=sa02Cmd(board, FEB_MUX, data=0x20, chip, channel ,1,response); // set mux to VTH1 |
||
1565 | time(&t); |
||
1566 | told=t; |
||
1567 | if (ctrl_c) break; |
||
1568 | for (k=0; k<kmax; k++) { |
||
1569 | if (ctrl_c) break; |
||
1570 | SetCtrlVal(p1h,P1_SETSINGLEVALUE,k); |
||
1571 | SetCtrlVal(p1h,P1_CUREVE,k); |
||
1572 | retval=sa02Cmd(board, FEB_VTH1 , k , chip, channel ,1, response); |
||
1573 | val=sa02Cmd(board, FEB_ADC_READ, data, chip, channel ,1,response); |
||
1574 | if (sa02BoardType>2) |
||
357 | f9daq | 1575 | doubleval = sa02adc2Vm(val); |
326 | f9daq | 1576 | else |
357 | f9daq | 1577 | doubleval = sa02adc2V(val); |
1578 | // doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3; |
||
1579 | // else |
||
1580 | // doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3; |
||
326 | f9daq | 1581 | H1DFillBin(h1+board, k, doubleval); |
1582 | if (t!=told || k==kmax-1 ||k==0 ) { |
||
1583 | H1DDraw(h1+board,p1h, P1_GRAPH, &phandle[board]); |
||
1584 | sa02Printf("[%d] set VTH1=%d ADC(VTH1)= %6.3f V\n",board, k, doubleval); |
||
1585 | SetCtrlVal(p1h,P1_CUREVE, k); |
||
1586 | ProcessSystemEvents (); |
||
1587 | } |
||
1588 | told=t; |
||
1589 | time(&t); |
||
1590 | } |
||
1591 | } |
||
1592 | break; |
||
1593 | } |
||
1594 | } |
||
1595 | return 0; |
||
1596 | } |
||
1597 | |||
1598 | |||
1599 | int CVICALLBACK MultiFpgaWrite (void *functionData) { |
||
1600 | uint32_t val, board,data,step,cmd,response[2]= {0,0}; |
||
1601 | char scmd[0xFF],sdata[0xFF]; |
||
1602 | int chip, channel; |
||
1603 | char filename[0xFF]; |
||
1604 | double delay, doubleval=0, x0, dx; |
||
1605 | int neve,i,daqexe,addheader; |
||
1606 | time_t t,told, tstart; |
||
1607 | FILE *fp; |
||
1608 | //int h2=0; |
||
1609 | int *fdata= (int *) functionData; |
||
1610 | |||
1611 | datrec.id = DATREC_ID; |
||
1612 | datrec.len = sizeof(datrec); |
||
1613 | GetCtrlVal(p1h,P1_MULTINEVE , &neve); |
||
1614 | GetCtrlVal(p1h,P1_WAIT , &delay); |
||
1615 | GetCtrlVal(p1h, P1_SINGLEWRITECMD, scmd); |
||
1616 | cmd=sa02GetCmdCode(scmd); |
||
1617 | GetCtrlVal(p1h,P1_BOARDNUMBER, &board); |
||
1618 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
||
1619 | GetCtrlVal(p1h, P1_SINGLEDATA, sdata); |
||
1620 | data = strtoul (sdata,NULL,0); |
||
1621 | // if (strcmp(scmd,"MUXASIC")==0) { |
||
1622 | // data = sa02MuxMap(data); |
||
1623 | // sa02Printf("MUX %d\n",data); |
||
1624 | // } |
||
1625 | GetCtrlVal(p1h, P1_SINGLEDATA, sdata); |
||
1626 | data = strtoul (sdata,NULL,0); |
||
1627 | x0=(double)data; |
||
1628 | GetCtrlVal(p1h, P1_DSTEP0, &step); |
||
1629 | dx=(double)step; |
||
1630 | GetCtrlVal(p1h,P1_SINGLECHIP,&chip); |
||
1631 | GetCtrlVal(p1h,P1_SINGLECHANNEL,&channel); |
||
1632 | if (fdata[0]==P1_FPGAWRITE) { |
||
1633 | neve=1; |
||
1634 | } |
||
1635 | GetCtrlVal(p1h,P1_DAQEXE,&daqexe); |
||
1636 | GetCtrlVal(p1h,P1_ADDHEADER,&addheader); |
||
1637 | time(&t); |
||
1638 | tstart=t; |
||
1639 | told=t; |
||
1640 | if (addheader) { |
||
1641 | iteratorrec.id = ITERATORREC_ID; |
||
1642 | iteratorrec.len = sizeof(iteratorrec); |
||
1643 | iteratorrec.value = data; |
||
1644 | iteratorrec.n = neve; |
||
1645 | iteratorrec.step = step; |
||
1646 | iteratorrec.level = 2; |
||
1647 | GetCtrlVal(p1h,P1_OUTPUTFILE, filename); |
||
1648 | fp = fopen(filename, "ab"); |
||
1649 | if(fp) { |
||
1650 | fwrite (&iteratorrec, 1, iteratorrec.len, fp); |
||
1651 | fclose(fp); |
||
1652 | } |
||
1653 | } |
||
1654 | for (i=0; i<neve; i++) { |
||
1655 | SetCtrlVal(p1h,P1_SETSINGLEVALUE,data); |
||
1656 | SetCtrlVal(p1h,P1_CUREVE,i); |
||
1657 | val=sa02Cmd(board, cmd, data, chip, channel ,1, response); |
||
1658 | if (addheader) { |
||
1659 | datrec.cmd =cmd; |
||
1660 | datrec.data =data; |
||
1661 | datrec.chip =chip; |
||
1662 | datrec.channel=channel; |
||
1663 | datrec.retval =val; |
||
1664 | GetCtrlVal(p1h,P1_OUTPUTFILE, filename); |
||
1665 | fp = fopen(filename, "ab"); |
||
1666 | if(fp) { |
||
1667 | fwrite (&datrec, 1, datrec.len, fp); |
||
1668 | fclose(fp); |
||
1669 | } |
||
1670 | } |
||
1671 | switch (cmd & (~ FEB_RO)) { |
||
1672 | case FEB_ADC_READ: |
||
1673 | case FEB_ADC_RESET: |
||
357 | f9daq | 1674 | doubleval = sa02adc2V(val); |
1675 | // doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3; |
||
326 | f9daq | 1676 | sa02Printf("ADC %f, 0x%08x\n", doubleval, val ) ; |
1677 | break; |
||
1678 | case FEB_TMON1: |
||
1679 | case FEB_TMON0: |
||
1680 | doubleval = ( (val >>2 ) & 0xFFF ) * 0.0625; |
||
1681 | if (val&0x4000) { |
||
1682 | doubleval=-doubleval; |
||
1683 | } |
||
1684 | sa02Printf("TMON %f 0x%x\n",doubleval, val ) ; |
||
1685 | break; |
||
1686 | case FEB_VTH1: |
||
1687 | case FEB_VTH2: |
||
1688 | doubleval = (val & 0xFFFF ); |
||
1689 | if (cmd & 1) |
||
1690 | val=0x20; |
||
1691 | else |
||
1692 | val=0x30; |
||
1693 | val=sa02Cmd(board, FEB_MUX, val, 0, 0 ,1,response); |
||
1694 | val=sa02Cmd(board, FEB_ADC_READ, 0, 0, 0, 1,response); |
||
1695 | if (sa02BoardType>2) |
||
357 | f9daq | 1696 | doubleval = sa02adc2Vm(val); |
1697 | // doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3; |
||
326 | f9daq | 1698 | else |
357 | f9daq | 1699 | doubleval = sa02adc2V(val); |
1700 | // doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3; |
||
326 | f9daq | 1701 | sa02Printf("%5d %6.3f\n",data, doubleval); |
1702 | break; |
||
1703 | case SA0x_ASIC0_GREG: |
||
1704 | if (cmd & FEB_RO) { |
||
1705 | sa02PrintGREG(&val,"Returned GREG data->"); |
||
1706 | } |
||
1707 | break; |
||
1708 | case SA0x_ASIC0_CREG: |
||
1709 | if (cmd & FEB_RO) { |
||
1710 | sa02PrintCREG(&val,"Returned CREG data->"); |
||
1711 | } |
||
1712 | break; |
||
1713 | default: |
||
1714 | sa02Printf("0x%08X\n",val); |
||
1715 | // break; |
||
1716 | } |
||
1717 | datay[i]=doubleval; |
||
1718 | if (delay>0 && fdata[0]==P1_MULTIFPGAWRITE) { |
||
1719 | Delay(delay); |
||
1720 | } |
||
1721 | if (daqexe) { |
||
1722 | daq(NULL); |
||
1723 | } |
||
1724 | if (ctrl_c) { |
||
1725 | break; |
||
1726 | } |
||
1727 | if (t!=told ) { |
||
1728 | plot1d(i,x0,dx); |
||
1729 | SetCtrlVal(p1h,P1_CUREVE, i); |
||
1730 | ProcessSystemEvents (); |
||
1731 | } |
||
1732 | data+=step; |
||
1733 | told=t; |
||
1734 | time(&t); |
||
1735 | } |
||
1736 | plot1d(i,x0,dx); |
||
1737 | SetCtrlVal(p1h,P1_CUREVE, i); |
||
1738 | return 0; |
||
1739 | } |
||
1740 | |||
1741 | int CVICALLBACK SendSEUTRigger (int panel, int control, int event, |
||
1742 | void *callbackData, int eventData1, int eventData2) { |
||
1743 | |||
1744 | switch (event) { |
||
1745 | case EVENT_COMMIT: |
||
1746 | Sa02SEUTrigger(); |
||
1747 | break; |
||
1748 | } |
||
1749 | return 0; |
||
1750 | } |
||
1751 | |||
1752 | int CVICALLBACK FSelect (int panel, int control, int event, |
||
1753 | void *callbackData, int eventData1, int eventData2) { |
||
1754 | int status,fcontrol = 0; |
||
1755 | char pathName[MAX_PATHNAME_LEN]; |
||
1756 | char defName[MAX_PATHNAME_LEN]; |
||
1757 | char fileMessage[100] = ""; |
||
1758 | switch (event) { |
||
1759 | case EVENT_COMMIT: |
||
1760 | switch (control) { |
||
1761 | case P3_FSELECT: |
||
1762 | fcontrol=P3_INPUTFILE; |
||
1763 | strcpy(fileMessage,"Select Parameter file"); |
||
1764 | break; |
||
1765 | case P3_PTSFSELECT: |
||
1766 | fcontrol=P3_PTSFIRMWARE; |
||
1767 | strcpy(fileMessage,"Select PTS Firmware file"); |
||
1768 | break; |
||
1769 | } |
||
1770 | sa02Printf("MAX_PATHNAME_LEN %d\n",MAX_PATHNAME_LEN); |
||
1771 | GetCtrlVal(panel,fcontrol,defName); |
||
1772 | status = FileSelectPopup ("",defName,"", |
||
1773 | fileMessage, VAL_LOAD_BUTTON, 0, |
||
1774 | 0, 1, 0, pathName); |
||
1775 | if (status>0) |
||
1776 | SetCtrlVal(panel,fcontrol,pathName); |
||
1777 | break; |
||
1778 | } |
||
1779 | return 0; |
||
1780 | } |
||
1781 | |||
1782 | int CVICALLBACK Verbose (int panel, int control, int event, |
||
1783 | void *callbackData, int eventData1, int eventData2) { |
||
1784 | //int * data; |
||
1785 | switch (event) { |
||
1786 | case EVENT_COMMIT: |
||
1787 | GetCtrlVal(panel,control,&sa02Verbose); |
||
1788 | break; |
||
1789 | } |
||
1790 | return 0; |
||
1791 | } |
||
1792 | |||
1793 | int CVICALLBACK Print (int panel, int control, int event, |
||
1794 | void *callbackData, int eventData1, int eventData2) { |
||
1795 | char dfile[MAX_PATHNAME_LEN]; |
||
1796 | char name[MAX_PATHNAME_LEN]; |
||
1797 | int h2=0; |
||
1798 | switch (event) { |
||
1799 | case EVENT_COMMIT: { |
||
1800 | int hours, minutes, seconds; |
||
1801 | int month, day, year; |
||
1802 | int id=-1; |
||
1803 | //int bitmap = 0; |
||
1804 | if (panel == p1h) { |
||
1805 | switch (control) { |
||
1806 | case P1_PRINT: |
||
1807 | id= P1_GRAPH; |
||
1808 | sprintf(name,"G"); |
||
1809 | break; |
||
1810 | case P1_PRINT2D: |
||
1811 | id= P1_GRAPH2D; |
||
1812 | sprintf(name,"2D"); |
||
1813 | break; |
||
1814 | case P1_PRINTX: |
||
1815 | id= P1_GRAPHX; |
||
1816 | sprintf(name,"X"); |
||
1817 | break; |
||
1818 | case P1_PRINTY: |
||
1819 | id= P1_GRAPHY; |
||
1820 | sprintf(name,"Y"); |
||
1821 | break; |
||
1822 | } |
||
1823 | h2=0; |
||
357 | f9daq | 1824 | } |
1825 | else { |
||
326 | f9daq | 1826 | switch (control) { |
1827 | case P2_PRINTXY: |
||
1828 | id= P2_GRAPH_1; |
||
1829 | sprintf(name,"XY"); |
||
1830 | break; |
||
1831 | } |
||
1832 | h2=1; |
||
1833 | } |
||
1834 | GetSystemDate (&month,&day ,&year ); |
||
1835 | GetSystemTime(&hours, &minutes, &seconds); |
||
1836 | if (id>=0) { |
||
1837 | if( ( (panel == p1h)&&(control == P1_PRINT2D) ) || ((panel == p2h)&&(control == P2_GRAPH_1))) { |
||
1838 | sprintf(dfile ,"data/%d_%d_%d_%d_%d_%s.th2d",year,month,day,hours,minutes, name ); |
||
1839 | H2DWrite(h2,dfile,"wb"); |
||
1840 | sa02Printf("sizeof H2D %d \n",sizeof(H2D)); |
||
1841 | sa02Printf("H2D image saved as %s\n", dfile); |
||
1842 | sprintf(name ,"C:\\root\\bin\\root.exe ..\\macros\\H2Dload.cxx(\\\"%s\\\")", dfile); |
||
1843 | LaunchExecutable(name); |
||
357 | f9daq | 1844 | } |
1845 | else { |
||
326 | f9daq | 1846 | sprintf(dfile ,"data/%d_%d_%d_%d_%d_%s.bmp",year,month,day,hours,minutes, name ); |
1847 | SaveCtrlDisplayToFile (panel,id, 0, -1, -1, dfile); |
||
1848 | sa02Printf("bmp image saved as %s\n", dfile); |
||
1849 | } |
||
1850 | } |
||
1851 | //PrintCtrl (p1h, P1_GRAPH2D, "sa02_CVI", 1, 1); |
||
1852 | } |
||
1853 | break; |
||
1854 | } |
||
1855 | return 0; |
||
1856 | } |
||
1857 | |||
1858 | int CVICALLBACK CursorCB (int panel, int control, int event, |
||
1859 | void *callbackData, int eventData1, int eventData2) { |
||
1860 | double x=0,y=0; |
||
1861 | int ix=0,iy=0; |
||
1862 | int h2=(int) callbackData; |
||
1863 | |||
1864 | switch (event) { |
||
1865 | case EVENT_COMMIT: |
||
1866 | GetGraphCursor (p1h, P1_GRAPH2D, 1, &x, &y); |
||
1867 | if(H2DGetStepX(h2)>0) { |
||
1868 | ix=(int)((x-H2DGetMinX(h2))/H2DGetStepX(h2)); |
||
1869 | } |
||
1870 | if(H2DGetStepY(h2)>0) { |
||
1871 | iy=(int)((y-H2DGetMinY(h2))/H2DGetStepY(h2)); |
||
1872 | } |
||
1873 | SetCtrlVal(panel,P1_NSLIX,ix); |
||
1874 | SetCtrlVal(panel,P1_NSLIY,iy); |
||
1875 | sa02Printf("Cursor %f %f h2=%d val=%f min=%f max=%f\n", |
||
1876 | x,y,h2,H2DGetBinContent(h2,ix,iy),H2DGetMin(h2), |
||
1877 | H2DGetMax(h2) ); |
||
1878 | break; |
||
1879 | } |
||
1880 | return 0; |
||
1881 | } |
||
1882 | |||
1883 | |||
1884 | int CVICALLBACK HistoInfoCB (int panel, int control, int event, |
||
1885 | void *callbackData, int eventData1, int eventData2) { |
||
1886 | double x=0,y=0; |
||
1887 | int ix=0,iy=0; |
||
1888 | int h2=(int) callbackData; |
||
1889 | int b=0; |
||
1890 | switch (event) { |
||
1891 | case EVENT_COMMIT: |
||
1892 | |||
1893 | GetGraphCursor (panel, control, 1, &x, &y); |
||
1894 | if (panel == p2h ) { |
||
1895 | for (b=0; b<4; b++) { |
||
1896 | if (control==p2graph[b]) break; |
||
1897 | } |
||
1898 | h2=100+b; |
||
1899 | if(H2DGetStepX(h2)>0) { |
||
1900 | ix=(int)((x-H2DGetMinX(h2))/H2DGetStepX(h2)); |
||
1901 | } |
||
1902 | if(H2DGetStepY(h2)>0) { |
||
1903 | iy=(int)((y-H2DGetMinY(h2))/H2DGetStepY(h2)); |
||
1904 | } |
||
1905 | |||
1906 | sa02Printf("Cursor %f %f h2=%d val=%f min=%f max=%f\n", |
||
1907 | x,y,h2,H2DGetBinContent(h2,ix,iy),H2DGetMin(h2), |
||
1908 | H2DGetMax(h2) ); |
||
1909 | } |
||
1910 | break; |
||
1911 | } |
||
1912 | return 0; |
||
1913 | } |
||
1914 | |||
1915 | |||
1916 | int GetElectronicChannel(int x, int y, int *chip, int *ch) { |
||
1917 | int i=0; |
||
1918 | for (i=0; i<144; i++) { |
||
1919 | if (eid2hapdxy[i].chx == x && eid2hapdxy[i].chy == y) { |
||
1920 | *chip = eid2hapdxy[i].chip; |
||
1921 | *ch = eid2hapdxy[i].ch ; |
||
1922 | return 0; |
||
1923 | } |
||
1924 | } |
||
1925 | return -1; |
||
1926 | } |
||
1927 | |||
1928 | int SetCMon(int chx,int chy) { |
||
1929 | int chip,ch,asic; |
||
1930 | uint32_t response[2]= {0,0}; |
||
1931 | uint32_t board; |
||
1932 | uint16_t mask=GetConnectedFebMask(); |
||
1933 | |||
1934 | // GetCtrlVal(p1h,P1_BOARDNUMBER, &board); |
||
1935 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
||
1936 | GetElectronicChannel(chx,chy,&chip,&ch); |
||
1937 | asic = sa02MuxMap(chip); |
||
1938 | sa02Printf("CHX %d CHY %d ",chx, chy); |
||
1939 | sa02Printf("MUX %d ",asic); |
||
1940 | sa02Printf("CMON ASIC: %d ch: %d\n",chip, ch); |
||
1941 | for (board=0; board<4; board++) { |
||
1942 | if (mask & (1<<board)) { |
||
1943 | sa02Cmd(board,FEB_MUX , asic, 0, 0 ,2,response); |
||
1944 | sa02Cmd(board,SA0x_ASIC0_CMON,0,chip,ch,2,response); |
||
1945 | } |
||
1946 | } |
||
1947 | |||
1948 | return 0; |
||
1949 | } |
||
1950 | |||
1951 | int CVICALLBACK HDraw2DCB (int panel, int control, int event, |
||
1952 | void *callbackData, int eventData1, int eventData2) { |
||
1953 | int ch=0; |
||
1954 | int ctrlID=0; |
||
1955 | int *plot=0; |
||
1956 | int graph=0; |
||
1957 | int board=0; |
||
1958 | switch (event) { |
||
1959 | |||
1960 | case EVENT_COMMIT: |
||
1961 | for (board=0; board<4; board++) { |
||
1962 | // if (panel == p1h){ rID = P1_CH; graph = P1_GRAPH; plot =&p1plothandle;} |
||
1963 | if (panel == p2h) { |
||
1964 | ctrlID = P2_CH; |
||
1965 | graph = p2graph[board]; |
||
1966 | plot =&p2plothandle[board]; |
||
1967 | } |
||
1968 | // if (panel == p3h){ rID = P3_CH; graph = P3_GRAPH; plot =&p3plothandle;} |
||
1969 | // if (panel == p4h){ rID = P4_CH; graph = P4_GRAPH; plot =&p4plothandle;} |
||
1970 | |||
1971 | |||
1972 | GetCtrlVal(panel,ctrlID, &ch); |
||
1973 | if (ch) { |
||
1974 | H3DDrawSliceXY(100+board,ch-1,panel,graph, plot); |
||
357 | f9daq | 1975 | } |
1976 | else { |
||
326 | f9daq | 1977 | H2DDraw(100+board,panel,graph, plot); |
1978 | } |
||
1979 | } |
||
1980 | break; |
||
1981 | } |
||
1982 | return 0; |
||
1983 | } |
||
1984 | |||
1985 | int GetHvMonitor( void ) { |
||
1986 | int N470mid = 4; |
||
1987 | int SYS403mid = 2; |
||
1988 | unsigned short buf[256]= {0}; |
||
1989 | int retval; |
||
1990 | int ii; |
||
1991 | // G0,A0,B0,C0,D0,H0,G1,A1,B1,C1,D1,H1,G2,A2,B2,C2,D2,H2,G3,A3,B3,C3,D3,H3 |
||
1992 | int channels[]= {24, 0, 1, 2, 3, 0,25, 4, 5, 6, 7, 1,26, 8, 9,10,11, 2,27,12,13,14,15, 3}; //channel for SYS403 , then for N470 |
||
1993 | // int channels[]= {0,1,2,3,4,0,5,6,7,8,9,1,10,11,12,13,14,2,15,16,17,18,19,3}; //channel for SYS403 , then for N470 |
||
1994 | |||
1995 | for (ii=0; ii<256; ii++) buf[ii]=0; |
||
1996 | monrec.time = (uint32_t) time(NULL); |
||
1997 | for (ii=0; ii<=23; ii++) { |
||
1998 | if ((ii+1)%6==0 && ii!=0) { |
||
1999 | buf[0]=(unsigned short) (channels[ii]<<8) | ReadOperationalParam; |
||
2000 | if (gCAEN_V288) { |
||
2001 | V288_Send(0,N470mid,1,buf); |
||
2002 | retval=V288_Receive(0,255, buf); |
||
2003 | } |
||
2004 | monrec.status[ii] = buf[0]; //status |
||
2005 | monrec.vmon[ii] = buf[1]*1000;//zapisano v mV |
||
2006 | monrec.imon[ii] = buf[2]*1000;//zapisano v nA |
||
2007 | monrec.vset[ii] = buf[3]*1000;//zapisano v mV |
||
2008 | monrec.iset[ii] = buf[4]*1000;//zapisano v nA |
||
357 | f9daq | 2009 | } |
2010 | else { |
||
326 | f9daq | 2011 | buf[0]=(unsigned short) (channels[ii]<<8) | ReadStatus; |
2012 | if (gCAEN_V288) { |
||
2013 | V288_Send(0,SYS403mid,1,buf); |
||
2014 | retval=V288_Receive(0,255,buf); |
||
2015 | } |
||
2016 | monrec.vmon[ii] = buf[1]*10;//zapisano v mV |
||
2017 | monrec.imon[ii] = buf[2]*10;//zapisano v nA |
||
2018 | monrec.status[ii] = buf[3]; //status |
||
2019 | |||
2020 | if (!hvmonFirst) { |
||
2021 | buf[0]=(unsigned short) (channels[ii]<<8) | ReadParameters; |
||
2022 | if (gCAEN_V288) { |
||
2023 | V288_Send(0,SYS403mid,1,buf); |
||
2024 | retval=V288_Receive(0,255,buf); |
||
2025 | } |
||
2026 | vset[ii] = monrec.vset[ii] = buf[7]*10;//zapisano v mV |
||
2027 | iset[ii] = monrec.iset[ii] = buf[10]*10;//zapisano v nA |
||
2028 | } |
||
2029 | monrec.vset[ii] = vset[ii];//zapisano v mV |
||
2030 | monrec.iset[ii] = iset[ii];//zapisano v nA |
||
2031 | } |
||
2032 | //sa02Printf("%04x \t %d \t %d \t %d \t %d *\n",monrec.status[ii],monrec.vmon[ii],monrec.vset[ii],monrec.imon[ii],monrec.iset[ii]); |
||
2033 | } |
||
2034 | hvmonFirst=1; |
||
2035 | return 0; |
||
2036 | } |
||
2037 | |||
2038 | int CVICALLBACK daq_scan(void *functionData) { |
||
2039 | int ich,count=0, xyval[4]= {0,0,0,0}; |
||
2040 | //int c[4]= {0,0,0,0}; |
||
2041 | //int e[4]= {0,0,0,0}; |
||
2042 | uint32_t daqmode=1; |
||
2043 | uint32_t trglen; |
||
2044 | int nb,dsave,fcount=0,fmax=0,status,ch; |
||
2045 | unsigned int i; |
||
2046 | int hxy=100; |
||
2047 | //int h2=0; |
||
2048 | time_t t,told, tstart, t0; |
||
2049 | |||
2050 | uint32_t board; |
||
2051 | uint32_t tpenb =0; |
||
2052 | uint32_t response[2]= {0,0}; |
||
2053 | char title[0xFF]; |
||
2054 | char dfile[MAX_PATHNAME_LEN],dfile0[MAX_PATHNAME_LEN]; |
||
2055 | #define MAXSIZE 10000 |
||
2056 | int maxsize = MAXSIZE; |
||
2057 | uint32_t sendswtrg=0; |
||
2058 | int ncount=0; |
||
2059 | uint32_t *rdata; |
||
2060 | float dx,dy,gapx,gapy,addgap; |
||
2061 | int ix,iy,nx,ny; |
||
2062 | int scanunitsx=0,scanunitsy=0; |
||
2063 | int x0,y0; |
||
2064 | const float fx= (float)(1000 / 0.3595); // 4M scaling factor steps/mm |
||
2065 | int daqexe; |
||
2066 | int writeevents=0; |
||
2067 | double fraction=0; |
||
2068 | uint32_t *data; |
||
2069 | char serial[4][0xFF]; |
||
2070 | char hname[0xFF]; |
||
2071 | time_t cas; |
||
2072 | |||
2073 | uint16_t mask=GetConnectedFebMask(); |
||
2074 | runrec.id = RUNREC_ID; |
||
2075 | runrec.len = sizeof(runrec); |
||
2076 | endrec.id = ENDREC_ID; |
||
2077 | endrec.len = sizeof(endrec); |
||
2078 | posrec.id = POSREC_ID; |
||
2079 | posrec.len = sizeof(posrec); |
||
2080 | evtrec.id = EVTREC_ID; |
||
2081 | evtrec.len = sizeof(evtrec); |
||
2082 | datrec.id = DATREC_ID; |
||
2083 | datrec.len = sizeof(datrec); |
||
2084 | monrec.id = MONREC_ID; |
||
2085 | monrec.len = sizeof(monrec); |
||
2086 | |||
2087 | SetCtrlAttribute (p2h, P2_DAQ, ATTR_DIMMED, 1); |
||
2088 | ctrl_c=0; |
||
2089 | |||
2090 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
||
2091 | |||
2092 | GetCtrlVal (p1h, P1_SERIAL_1, serial[0]); |
||
2093 | GetCtrlVal (p1h, P1_SERIAL_2, serial[1]); |
||
2094 | GetCtrlVal (p1h, P1_SERIAL_3, serial[2]); |
||
2095 | GetCtrlVal (p1h, P1_SERIAL_4, serial[3]); |
||
2096 | |||
2097 | sprintf(runrec.serial,"HAPD=%s,%s,%s,%s", serial[0],serial[1],serial[2],serial[3]); |
||
2098 | |||
2099 | GetCtrlVal (p2h, P2_NEVE, &runrec.nev); |
||
2100 | GetCtrlVal (p2h, P2_PEDESTAL, &runrec.ped); |
||
2101 | GetCtrlVal (p2h, P2_NX, &runrec.nx); |
||
2102 | GetCtrlVal (p2h, P2_XSTEP, &runrec.dx); |
||
2103 | GetCtrlVal (p2h, P2_XMIN, &runrec.x0); |
||
2104 | GetCtrlVal (p2h, P2_NY, &runrec.ny); |
||
2105 | GetCtrlVal (p2h, P2_YSTEP, &runrec.dy); |
||
2106 | GetCtrlVal (p2h, P2_YMIN, &runrec.y0); |
||
2107 | GetCtrlVal ( p1h, P2_TPENB,&tpenb); |
||
2108 | GetCtrlVal ( p2h,P2_DAQEXE,&daqexe); |
||
2109 | GetCtrlVal(p2h,P2_FRACTION, &fraction); |
||
2110 | GetCtrlVal (p2h, P2_SCANUNITSX, &scanunitsx); |
||
2111 | GetCtrlVal (p2h, P2_SCANUNITSY, &scanunitsy); |
||
2112 | GetCtrlVal (p2h, P2_GAPX, &gapx); |
||
2113 | GetCtrlVal (p2h, P2_GAPX, &gapy); |
||
2114 | GetCtrlVal (p2h, P2_DX, &dx); |
||
2115 | GetCtrlVal (p2h, P2_DX, &dy); |
||
2116 | |||
2117 | GetCtrlVal (p2h, P2_XC, &x0); |
||
2118 | GetCtrlVal (p2h, P2_YC, &y0); |
||
2119 | |||
2120 | GetCtrlVal (p2h, P2_DIRECTION, &runrec.direction); |
||
2121 | |||
2122 | |||
2123 | SetCtrlAttribute(p1h,P1_TRGHVMON,ATTR_ENABLED,1); |
||
2124 | hvmonFirst = 0; |
||
2125 | |||
2126 | |||
2127 | GetCtrlVal(p1h,P1_SENDSWTRIG,&sendswtrg); |
||
2128 | GetCtrlVal(p1h,P1_INTTRGLEN, &trglen); |
||
2129 | GetCtrlVal(p1h,P1_DAQMODE, &daqmode); |
||
2130 | |||
2131 | |||
2132 | |||
2133 | |||
2134 | runrec.fver = scanunitsx + scanunitsy*2 ; |
||
2135 | if (scanunitsx) { |
||
2136 | x0 = (int)(x0 - 5.5 * fx * dx - gapx * fx * 0.5); |
||
2137 | } |
||
2138 | if (scanunitsy) { |
||
2139 | y0 = (int)(y0 - 5.5 * fx * dy - gapy * fx * 0.5); |
||
2140 | } |
||
2141 | |||
2142 | GetCtrlVal(p2h, P2_DSAVE, &dsave); |
||
2143 | if (dsave) { |
||
2144 | GetCtrlVal (p2h, P2_DFILE, dfile0); |
||
2145 | fcount=1; |
||
2146 | GetCtrlVal (p2h, P2_NEWF, &fmax); |
||
2147 | fmax*=1000000;//fmax in Mega Bytes |
||
2148 | } |
||
2149 | time (&t0); |
||
2150 | sa02Printf("---->daq_scan\n"); |
||
357 | f9daq | 2151 | |
326 | f9daq | 2152 | if (dsave) { |
2153 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
||
2154 | //gFp = fopen (dfile, "ab"); |
||
2155 | gFp = fopen (dfile, "ab"); |
||
2156 | if (gFp==NULL) sa02Printf("----> !!! gFp==NULL !!!\n"); |
||
357 | f9daq | 2157 | if (ferror (gFp)) sa02Printf("----> !!! ferror (gFp) after fopen !!!\n"); |
326 | f9daq | 2158 | //time ((time_t *) &runrec.time); |
2159 | time (&cas); |
||
2160 | runrec.time = (uint32_t) cas; |
||
2161 | status = (int) fwrite (&runrec, 1, runrec.len, gFp); |
||
357 | f9daq | 2162 | if(status != runrec.len) sa02Printf("----> !!! status != runrec.len (= %d) !!!\n", status); |
2163 | if (ferror (gFp)) sa02Printf("----> !!! ferror (gFp) = %d !!!\n", ferror (gFp)); |
||
2164 | |||
326 | f9daq | 2165 | } |
2166 | |||
2167 | |||
2168 | for (i=0; i<4; i++) { |
||
2169 | sprintf(title,"HAPD%d Surface Scan single channels", i); |
||
2170 | sprintf(hname,"hxy%d", i); |
||
2171 | H3DInit(hxy+i,hname,title, runrec.nx,runrec.x0, runrec.dx,runrec.ny,runrec.y0, runrec.dy, 144, -0.5, 1); |
||
2172 | H3DSetTitleZ(hxy+i,"channel"); |
||
2173 | sprintf(hname,"hxy%d_sum", i); |
||
2174 | H2DInit(hxy+i,hname,runrec.serial, runrec.nx,runrec.x0, runrec.dx,runrec.ny,runrec.y0, runrec.dy); |
||
2175 | if (scanunitsx) { |
||
2176 | H2DSetTitleX(hxy+i,"x (channels)"); |
||
2177 | H3DSetTitleX(hxy+i,"x (channels)"); |
||
357 | f9daq | 2178 | } |
2179 | else { |
||
326 | f9daq | 2180 | H2DSetTitleX(hxy+i,"x (stage steps)"); |
2181 | H3DSetTitleX(hxy+i,"x (stage steps)"); |
||
2182 | } |
||
2183 | if (scanunitsy) { |
||
2184 | H2DSetTitleY(hxy+i,"y (channels)"); |
||
2185 | H3DSetTitleY(hxy+i,"y (channels)"); |
||
357 | f9daq | 2186 | } |
2187 | else { |
||
326 | f9daq | 2188 | H2DSetTitleY(hxy+i,"y (stage steps)"); |
2189 | H3DSetTitleY(hxy+i,"y (stage steps)"); |
||
2190 | } |
||
2191 | |||
2192 | } |
||
2193 | if (runrec.direction) { |
||
2194 | ny = runrec.ny; |
||
2195 | nx = runrec.nx; |
||
357 | f9daq | 2196 | } |
2197 | else { |
||
326 | f9daq | 2198 | ny = runrec.nx; |
2199 | nx = runrec.ny; |
||
2200 | } |
||
2201 | rdata = malloc(sizeof(uint32_t)*maxsize); |
||
2202 | |||
2203 | time(&t); |
||
2204 | tstart=t; |
||
2205 | told=t-1; |
||
2206 | |||
2207 | for (iy=0; iy<ny; iy++) { |
||
2208 | |||
2209 | if (ctrl_c) break; |
||
2210 | |||
2211 | if (runrec.direction) { |
||
2212 | posrec.iy = iy; |
||
2213 | posrec.yset=runrec.y0+posrec.iy*runrec.dy; |
||
2214 | if (scanunitsy) { |
||
2215 | if (posrec.yset>5) { |
||
2216 | addgap=gapy * fx; |
||
357 | f9daq | 2217 | } |
2218 | else { |
||
326 | f9daq | 2219 | addgap=0; |
2220 | } |
||
2221 | posrec.yset = (int32_t)(y0+dy *fx * posrec.yset + addgap); |
||
2222 | } |
||
2223 | if (gMIKRO_Y) { |
||
2224 | //sa02Printf("MIKRO_MoveTo (2, y);%d\n",y); |
||
2225 | MIKRO_MoveTo (MIKRO_Y, posrec.yset); |
||
2226 | sa02Printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
||
2227 | } |
||
2228 | |||
2229 | SetCtrlVal (p2h, P2_Y, posrec.yset); |
||
2230 | SetCtrlVal (p2h, P2_IY, posrec.iy); |
||
357 | f9daq | 2231 | } |
2232 | else { |
||
326 | f9daq | 2233 | posrec.ix = iy; |
2234 | posrec.xset=runrec.x0+posrec.ix*runrec.dx; |
||
2235 | if (scanunitsx) { |
||
2236 | if (posrec.xset>5) { |
||
2237 | addgap=gapx * fx; |
||
357 | f9daq | 2238 | } |
2239 | else { |
||
326 | f9daq | 2240 | addgap=0; |
2241 | } |
||
2242 | posrec.xset = (int32_t)(x0+dx *fx * posrec.xset + addgap); |
||
2243 | } |
||
2244 | if (gMIKRO_Y) { |
||
2245 | //sa02Printf("MIKRO_MoveTo (2, y);%d\n",y); |
||
2246 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
||
2247 | sa02Printf("->MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
||
2248 | } |
||
2249 | SetCtrlVal (p2h, P2_X, posrec.xset); |
||
2250 | SetCtrlVal (p2h, P2_IX, posrec.ix); |
||
2251 | } |
||
2252 | for (ix=0; ix<nx; ix++) { |
||
2253 | if (ctrl_c) break; |
||
2254 | |||
2255 | if (runrec.direction) { |
||
2256 | posrec.ix = ix; |
||
2257 | posrec.xset=runrec.x0+posrec.ix*runrec.dx; |
||
2258 | if (scanunitsx) { |
||
2259 | if (posrec.xset>5) { |
||
2260 | addgap=gapx * fx; |
||
357 | f9daq | 2261 | } |
2262 | else { |
||
326 | f9daq | 2263 | addgap=0; |
2264 | } |
||
2265 | posrec.xset = (int32_t)(x0+dx *fx * posrec.xset + addgap); |
||
2266 | } |
||
2267 | if (gMIKRO_X) { |
||
2268 | //sa02Printf("MIKRO_MoveTo (1, x);%d\n",posrec.x); |
||
2269 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
||
2270 | sa02Printf("->MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
||
2271 | } |
||
2272 | SetCtrlVal (p2h, P2_X, posrec.xset); |
||
2273 | SetCtrlVal (p2h, P2_IX, posrec.ix); |
||
357 | f9daq | 2274 | } |
2275 | else { |
||
326 | f9daq | 2276 | posrec.iy = ix; |
2277 | posrec.yset=runrec.y0+posrec.iy*runrec.dy; |
||
2278 | if (scanunitsy) { |
||
2279 | if (posrec.yset>5) { |
||
2280 | addgap=gapy * fx; |
||
357 | f9daq | 2281 | } |
2282 | else { |
||
326 | f9daq | 2283 | addgap=0; |
2284 | } |
||
2285 | posrec.yset = (int32_t)(y0+dy *fx * posrec.yset + addgap); |
||
2286 | } |
||
2287 | if (gMIKRO_X) { |
||
2288 | //sa02Printf("MIKRO_MoveTo (1, x);%d\n",posrec.y); |
||
2289 | MIKRO_MoveTo (MIKRO_Y, posrec.yset); |
||
2290 | sa02Printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
||
2291 | } |
||
2292 | SetCtrlVal (p2h, P2_Y, posrec.yset); |
||
2293 | SetCtrlVal (p2h, P2_IY, posrec.iy); |
||
2294 | } |
||
2295 | if (scanunitsx && scanunitsy) { |
||
2296 | SetCMon(runrec.x0+posrec.ix*runrec.dx,runrec.y0+posrec.iy*runrec.dy); |
||
2297 | } |
||
2298 | if (dsave) { |
||
2299 | if (fmax && (ftell(gFp) > fmax)) { |
||
2300 | fcount+=1; |
||
2301 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
||
2302 | fclose(gFp); |
||
2303 | gFp = fopen (dfile, "ab"); |
||
2304 | } |
||
2305 | time (&cas); |
||
2306 | posrec.time = (uint32_t) cas; |
||
2307 | status = (int) fwrite (&posrec, 1, posrec.len, gFp); |
||
2308 | } |
||
2309 | |||
2310 | Sa02DaqMode (daqmode); |
||
2311 | Sa02SelectTriggerWithMaskAndLength (sendswtrg, mask, trglen); |
||
2312 | |||
2313 | for (board=0; board<4; board++) { |
||
2314 | if (mask & (1<<board)) { |
||
2315 | sa02Cmd( board, FEB_VTH1, runrec.ped, 0,0,1,response); |
||
2316 | Sa02TestPulseEnable(board,tpenb); // Enable/disable test pulse |
||
2317 | } |
||
2318 | } |
||
2319 | |||
2320 | Sa02SetNeve(runrec.nev); |
||
2321 | |||
2322 | evtrec.nev=1; |
||
2323 | |||
2324 | |||
2325 | sa02Reset(); |
||
2326 | |||
2327 | if (ctrl_c) break; |
||
2328 | |||
2329 | if ( (count+2+dsize) >= maxsize) { |
||
2330 | maxsize*=2; |
||
2331 | sa02Printf("Increasing data buffer to %d elements\n", maxsize); |
||
2332 | rdata=realloc(rdata ,sizeof(uint32_t)*maxsize); |
||
2333 | } |
||
2334 | |||
2335 | data = &rdata[count+2]; |
||
2336 | do { |
||
2337 | //int k; |
||
2338 | //uint32_t inputtriggers; |
||
2339 | if (sendswtrg == 1) Sa02SoftwareTrigger(); |
||
2340 | nb = sa02Read(mask, &rdata[count+2] ); |
||
2341 | /* |
||
2342 | for (k=0; k<4; k++) c[k] = Sa02GetCounter ( k ,&e[k]); |
||
2343 | for (k=0; k<4; k++) sa02Printf(" CNTR%d=%d (ERR=%d)\t",k,c[k],e[k]); |
||
2344 | sa02Printf("\nsa02Read bytes = %d mask=%d neve=%d (%d # %d)\n", nb, mask, runrec.nev, Sa02GetNeve( &inputtriggers ) , inputtriggers); |
||
2345 | */ |
||
357 | f9daq | 2346 | } |
2347 | while ( nb==0 && !ctrl_c); |
||
326 | f9daq | 2348 | |
2349 | |||
2350 | |||
2351 | if (sa02TimerOut || nb==0) sa02Printf("sa02TimerOut || nb==0\n"); |
||
2352 | |||
2353 | for (ich=0; ich<144*4; ich++) { |
||
2354 | int brd = ich/144; |
||
2355 | int xch = 143 - ich%144; |
||
2356 | //sa02Printf("[%d] = %d \n", ich, data[ich]); |
||
2357 | if (data[ich]> xyval[brd]) xyval[brd] = data[ich]; |
||
2358 | if (mask & (1<<brd)) { |
||
2359 | H3DFillBin(hxy+ brd, posrec.ix,posrec.iy,xch,data[ich]); |
||
2360 | H2DFillBin(hxy+ brd, posrec.ix,posrec.iy,data[ich]); |
||
2361 | } |
||
2362 | } |
||
2363 | sa02Printf("max couts = %d %d %d %d\n", xyval[0],xyval[1],xyval[2],xyval[3]); |
||
2364 | if (nb>=0) { |
||
2365 | count+=module_header(0x3,&rdata[count],nb/sizeof(uint32_t)); |
||
2366 | } |
||
2367 | |||
2368 | |||
2369 | /* |
||
2370 | for (ich=0; ich<144; ich++) { |
||
2371 | |||
2372 | // uint32_t mask=0xFF; |
||
2373 | // id=(35-ich/4); |
||
2374 | // shft=(ich%4)*8; |
||
2375 | uint32_t mask=0xF; |
||
2376 | id=(17-ich/8)+board*18; |
||
2377 | shft=(ich%8)*4; |
||
2378 | if ( data[id] & (mask <<shft) ) { |
||
2379 | H3DFillBin(hxy, posrec.ix,posrec.iy,ich,1); |
||
2380 | H2DFillBin(hxy, posrec.ix,posrec.iy,1); |
||
2381 | } |
||
2382 | } |
||
2383 | */ |
||
2384 | if (dsave) { |
||
2385 | if (Random(0,1)<fraction) { |
||
2386 | writeevents=1; |
||
357 | f9daq | 2387 | } |
2388 | else { |
||
326 | f9daq | 2389 | writeevents=0; |
2390 | } |
||
2391 | if (writeevents) { |
||
2392 | evtrec.id = EVTREC_ID; |
||
2393 | evtrec.len=count*sizeof(uint32_t)+ sizeof(evtrec); |
||
2394 | |||
2395 | evtrec.time= (uint32_t) time(NULL); |
||
2396 | evtrec.nev=i; |
||
2397 | status = (int) fwrite( &evtrec, 1, sizeof(evtrec),gFp); |
||
2398 | if (count) { |
||
2399 | status = (int) fwrite(rdata,1,count*sizeof(uint32_t),gFp); //gzip |
||
2400 | } |
||
2401 | } |
||
2402 | if (hvmon) { |
||
2403 | time_t thv0,thv1; |
||
2404 | time(&thv0); |
||
2405 | GetHvMonitor(); |
||
2406 | time(&thv1); |
||
2407 | status = (int) fwrite( &monrec, 1, sizeof(monrec),gFp); |
||
2408 | sa02Printf("HvMonitor dt= %d s\n", thv1-thv0 ); |
||
2409 | hvmon =0; |
||
2410 | } |
||
2411 | |||
2412 | ncount++; |
||
2413 | } |
||
2414 | |||
2415 | time(&t); |
||
2416 | if (t!=told ) { |
||
2417 | double done= (double) (posrec.ix+posrec.iy*runrec.nx)/(runrec.nx*runrec.ny); |
||
2418 | EstimatedFinish(p2h, P2_PROGRESS, P2_ETA, t0, done); |
||
2419 | GetCtrlVal(p2h,P2_CH, &ch); |
||
2420 | for (board=0; board<4; board++) { |
||
2421 | if (ch) { |
||
2422 | H3DDrawSliceXY(hxy+board,ch,p2h, p2graph[board], &p2plothandle[board]); |
||
357 | f9daq | 2423 | } |
2424 | else { |
||
326 | f9daq | 2425 | H2DDraw(hxy+board,p2h, p2graph[board], &p2plothandle[board]); |
2426 | } |
||
2427 | } |
||
2428 | ProcessSystemEvents (); |
||
2429 | SetCtrlVal(p2h,P2_CEVE, i); |
||
2430 | sa02Printf("%d events in %2.2f min (%d s) %s",ncount, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
||
2431 | |||
2432 | } |
||
2433 | told=t; |
||
2434 | |||
2435 | |||
2436 | |||
2437 | if (ctrl_c) break; |
||
2438 | |||
2439 | if (daqexe &0x1) { |
||
2440 | daq(NULL); |
||
2441 | sa02Cmd( board, FEB_VTH1, runrec.ped, 0,0,1,response); |
||
2442 | } |
||
2443 | if (daqexe &0x2) { |
||
2444 | V729_SetFilePointer(gFp); |
||
2445 | V729_daq(NULL); |
||
2446 | } |
||
2447 | |||
2448 | } |
||
2449 | } |
||
2450 | |||
2451 | if (gFp) { |
||
2452 | int ii=0, ison=0; |
||
2453 | for (ii=0; ii<4; ii++) { |
||
2454 | GetCtrlVal(p1h,hapd_onoff[ii], &ison); |
||
2455 | if (ison ) { |
||
2456 | H3DWrite2File(hxy+ii, gFp); |
||
2457 | H2DWrite2File(hxy+ii, gFp); |
||
2458 | } |
||
2459 | } |
||
2460 | fclose(gFp); |
||
2461 | } |
||
2462 | gFp=NULL; |
||
2463 | free(rdata); |
||
2464 | |||
2465 | SetCtrlAttribute(p1h,P1_TRGHVMON,ATTR_ENABLED,0); |
||
2466 | |||
2467 | return 0; |
||
2468 | } |
||
2469 | |||
2470 | int CVICALLBACK Testing(void *functionData) { |
||
2471 | int i; |
||
2472 | int N470mid = 4; |
||
2473 | int SYS403mid = 2; |
||
2474 | unsigned short buf[256]= {0}; |
||
2475 | int odg; |
||
2476 | int channels[]= {0,1,2,3,4,0,5,6,7,8,9,1,10,11,12,13,14,2,15,16,17,18,19,3}; //channel for SYS403 , then for N470 |
||
2477 | time_t t0,t1; |
||
2478 | time(&t0); |
||
2479 | |||
2480 | hvmonFirst=0; |
||
2481 | |||
2482 | for (i=0; i<256; i++) buf[i]=0; |
||
2483 | for (i=0; i<=23; i++) { |
||
2484 | if (((i+1)%6)==0&&i!=0) { |
||
2485 | buf[0]=(unsigned short) (channels[i]<<8) | ReadOperationalParam; |
||
2486 | if (gCAEN_V288) { |
||
2487 | V288_Send(0,N470mid,1,buf); |
||
2488 | odg=V288_Receive(0,255,buf); |
||
2489 | } |
||
2490 | monrec.status[i] = buf[0]; //status |
||
2491 | monrec.vmon[i] = buf[1]*1000;//zapisano v mV |
||
2492 | monrec.imon[i] = buf[2]*1000;//zapisano v nA |
||
2493 | monrec.vset[i] = buf[3]*1000;//zapisano v mV |
||
2494 | monrec.iset[i] = buf[4]*1000;//zapisano v nA |
||
357 | f9daq | 2495 | } |
2496 | else { |
||
326 | f9daq | 2497 | buf[0]=(unsigned short) (channels[i]<<8) | ReadStatus; |
2498 | if (gCAEN_V288) { |
||
2499 | V288_Send(0,SYS403mid,1,buf); |
||
2500 | odg=V288_Receive(0,255,buf); |
||
2501 | } |
||
2502 | monrec.vmon[i] = buf[1]*10;//zapisano v mV |
||
2503 | monrec.imon[i] = buf[2]*10;//zapisano v nA |
||
2504 | monrec.status[i] = buf[3]; //status |
||
2505 | if(!hvmonFirst) { |
||
2506 | buf[0]=(unsigned short) (channels[i]<<8) | ReadParameters; |
||
2507 | if (gCAEN_V288) { |
||
2508 | V288_Send(0,SYS403mid,1,buf); |
||
2509 | odg=V288_Receive(0,255,buf); |
||
2510 | } |
||
2511 | vset[i] = monrec.vset[i] = buf[7]*10;//zapisano v mV |
||
2512 | iset[i] = monrec.iset[i] = buf[10]*10;//zapisano v nA |
||
2513 | } |
||
2514 | monrec.vset[i] = vset[i];//zapisano v mV |
||
2515 | monrec.iset[i] = iset[i];//zapisano v nA |
||
2516 | } |
||
2517 | sa02Printf("%04x \t %.02f V \t %d V \t\t %.02f muA \t %d muA *\n",monrec.status[i],(float)monrec.vmon[i]/1000,monrec.vset[i]/1000,(float)monrec.imon[i]/1000,monrec.iset[i]/1000); |
||
2518 | } |
||
2519 | time (&t1); |
||
2520 | sa02Printf("Cas izvedbe:%g s.\n",difftime(t1,t0)); |
||
2521 | |||
2522 | return 0; |
||
2523 | } |
||
2524 | |||
2525 | int CVICALLBACK set_dac(int OnOff) { |
||
2526 | int val; |
||
2527 | char name[MAX_PATHNAME_LEN]; |
||
2528 | if (OnOff) { |
||
2529 | GetCtrlVal (p5h, P5_DAC_ON, &val); |
||
2530 | sprintf(name ,"%s -p %d",palaser, val); |
||
2531 | sa02Printf("%s\n", name); |
||
2532 | system(name); |
||
2533 | GetCtrlVal (p5h, P5_FREQUENCY_ON, &val); |
||
2534 | sprintf(name ,"%s -f %d",palaser, val); |
||