Rev 29 | Rev 37 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
29 | f9daq | 1 | #define USE_DAQ |
2 | #define USE_MIKRO |
||
3 | |||
4 | // Izberi ustrezni interface v meniju projektnega okna |
||
5 | // Options->CompilerDefines (dodaj /DSISVME ali /DWIENVME) |
||
6 | #ifdef USE_DAQ |
||
7 | # define USE_CAMAC |
||
32 | f9daq | 8 | #include "c:\HOME\dino\sipmScan\include\camac.h" |
29 | f9daq | 9 | # ifdef SISVME |
10 | # include "sisvme_dll.h" |
||
11 | # endif |
||
12 | # ifdef WIENVME |
||
13 | # include "wienvme_dll.h" |
||
14 | # endif |
||
15 | # include "CAENV673A.h" |
||
16 | # include "CAENV462.h" |
||
17 | #endif |
||
18 | |||
19 | #ifdef USE_MIKRO |
||
20 | # include "MIKRO.h" |
||
21 | #endif |
||
22 | |||
23 | #include <userint.h> |
||
24 | #include <ansi_c.h> |
||
25 | #include <utility.h> |
||
26 | #include <analysis.h> |
||
27 | |||
32 | f9daq | 28 | #include "c:\HOME\dino\sipmScan\include\sipmThreshold_ui.h" |
29 | f9daq | 29 | |
30 | #ifdef USE_DAQ |
||
31 | # define USE_CAMAC |
||
32 | # include "camac.h" |
||
33 | # define NDAC 1 |
||
34 | |||
35 | # define CAEN_V673A 0x22220000 // IJS |
||
36 | //#define CAEN_V673A 0x10110000 // FMF |
||
37 | # define CAEN_V462 0x100300 |
||
38 | #endif |
||
39 | |||
40 | #ifdef USE_MIKRO |
||
41 | # define MIKRO_COM 5 |
||
42 | # define MIKRO_X 1 |
||
43 | # define USE_MIKRO_Y |
||
44 | # define MIKRO_Y 2 |
||
45 | # define USE_MIKRO_Z |
||
46 | # define MIKRO_Z 3 |
||
47 | # define STEP_TOLERANCE 50 |
||
48 | #endif |
||
49 | |||
50 | #define MAXCH 512 |
||
51 | #define MAX_THREADS 10 |
||
52 | |||
53 | #define IWAIT 200 |
||
54 | |||
55 | #define NCH 64 |
||
56 | |||
57 | static int p1h, pID, rID, tfID; |
||
58 | static int ph_tdc, ph_adc; |
||
59 | static int dtdc[NCH][2][MAXCH]; |
||
60 | static int something[NCH][2][MAXCH]; |
||
61 | |||
62 | static int daq_on; |
||
63 | static int poolHandle = 0; |
||
64 | static int ntics,dummy; |
||
65 | |||
66 | /************************************************************/ |
||
67 | void wait_loop(unsigned long iloop) |
||
68 | |||
69 | { |
||
70 | int i; |
||
71 | |||
72 | for (i=0;i<iloop;i++); |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | int CVICALLBACK cb_timer (int panel, int control, int event, void *callbackData, |
||
77 | int eventData1, int eventData2) |
||
78 | { |
||
79 | QueueUserEvent (9000, p1h, P1_TIMER); |
||
80 | return (0); |
||
81 | } |
||
82 | |||
83 | int update_plots (void) |
||
84 | { |
||
85 | int irange, ch; |
||
86 | |||
87 | GetCtrlVal (p1h, P1_PLCH, &ch); |
||
88 | |||
89 | if (ph_tdc>0) DeleteGraphPlot (p1h, P1_TDC, ph_tdc, VAL_DELAYED_DRAW); |
||
90 | GetCtrlVal (p1h, P1_TDCHL, &irange); |
||
91 | ph_tdc = PlotY (p1h, P1_TDC, &dtdc[ch][irange], MAXCH, VAL_INTEGER, |
||
92 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
||
93 | |||
94 | if (ph_adc>0) DeleteGraphPlot (p1h, P1_ADC, ph_adc, VAL_DELAYED_DRAW); |
||
95 | GetCtrlVal (p1h, P1_ADCHL, &irange); |
||
96 | ph_adc = PlotY (p1h, P1_ADC, &something[ch][irange], MAXCH, VAL_INTEGER, |
||
97 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE); |
||
98 | return (0); |
||
99 | } |
||
100 | |||
101 | |||
102 | int module_header(int recid,unsigned long *data,int len){ |
||
103 | data[0] = recid; |
||
104 | data[1] = (len >0)? len : 0 ; |
||
105 | return data[1]+2; |
||
106 | } |
||
107 | |||
108 | int SetDac(int, double); |
||
109 | |||
110 | int CVICALLBACK daq_run(void *functionData) |
||
111 | { |
||
112 | // *** |
||
113 | // variable declarations |
||
114 | int i,j; |
||
115 | int dtype,ch,rg,adc,cres,bsr; |
||
116 | |||
117 | //unsigned short aa[NCH][4]; |
||
118 | unsigned long tdc[NCH]; |
||
119 | unsigned long step_minutes, end_time_s, cur_time_s; |
||
120 | int start_hours, start_minutes, start_seconds; |
||
121 | |||
122 | int status,fmax,fcount,fev; |
||
123 | int popupret; |
||
124 | int mikroX; // check the position |
||
125 | int mikroY; // check the position |
||
126 | |||
127 | char dfile[MAX_PATHNAME_LEN],dfile0[MAX_PATHNAME_LEN]; |
||
128 | int supr0,tdcmin,fseed; |
||
129 | float frac; |
||
130 | double fracg; |
||
131 | unsigned short dum16; |
||
132 | int count; |
||
133 | int print = 0; |
||
134 | int timer_out = 0; |
||
135 | //time_t t,told, tstart; |
||
136 | int ntrig; |
||
137 | int chip, len; |
||
138 | unsigned long *pdata; |
||
139 | |||
140 | FILE *fp; |
||
141 | #define RUNREC_ID 1 |
||
142 | #define ENDREC_ID 2 |
||
143 | #define POSREC_ID 3 |
||
144 | #define EVTREC_ID 4 |
||
145 | #define THRREC_ID 5 |
||
146 | |||
147 | typedef struct { |
||
148 | unsigned long id,len; |
||
149 | unsigned long fver,time; |
||
150 | unsigned long nev,nch,ped,xy; |
||
151 | unsigned long thLow, thUp, thStep; |
||
152 | long nx,x0,dx,ny,y0,dy; |
||
153 | } RUNREC; |
||
154 | RUNREC runrec; |
||
155 | |||
156 | typedef struct { |
||
157 | unsigned long id,len; |
||
158 | unsigned long time; |
||
159 | } ENDREC; |
||
160 | ENDREC endrec; |
||
161 | |||
162 | typedef struct { |
||
163 | unsigned long id,len; |
||
164 | unsigned long time; |
||
165 | long ix,x,xset,iy,y,yset; |
||
166 | } POSREC; |
||
167 | POSREC posrec; |
||
168 | |||
169 | typedef struct { |
||
170 | unsigned long id,len; |
||
171 | unsigned long nev; |
||
172 | //unsigned short data[NCH]; |
||
173 | } EVTREC; |
||
174 | EVTREC evtrec; |
||
175 | |||
176 | typedef struct { |
||
177 | unsigned long id; |
||
178 | unsigned long len; |
||
179 | unsigned long threshold; |
||
180 | } THRREC; |
||
181 | THRREC thrrec; |
||
182 | |||
183 | double thresholdLow; |
||
184 | double thresholdUp; |
||
185 | double thresholdStep; |
||
186 | |||
187 | #define BSIZE 20000 |
||
188 | |||
189 | int maxn = BSIZE-4; // 2 words x 2 headers |
||
190 | int tdcdata, edge_type, overflow, tdc_num, channel, ev_dat, last_dat, nval_dat; |
||
191 | // end of declarations |
||
192 | // *** |
||
193 | |||
194 | runrec.id = RUNREC_ID; |
||
195 | runrec.len = sizeof(runrec); |
||
196 | //runrec.fver = 0x10000; |
||
197 | runrec.nch = NCH; |
||
198 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);//runrec.xy = 1; |
||
199 | GetCtrlVal(p1h, P1_DEBUG, &print); |
||
200 | endrec.id = ENDREC_ID; |
||
201 | endrec.len = sizeof(endrec); |
||
202 | posrec.id = POSREC_ID; |
||
203 | posrec.len = sizeof(posrec); |
||
204 | evtrec.id = EVTREC_ID; |
||
205 | evtrec.len = sizeof(evtrec); |
||
206 | thrrec.id = THRREC_ID; |
||
207 | thrrec.len = sizeof(thrrec); |
||
208 | |||
209 | |||
210 | cres = 0; |
||
211 | |||
212 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev); |
||
213 | GetCtrlVal (p1h, P1_PEDESTAL, &runrec.ped); |
||
214 | |||
215 | GetCtrlVal (p1h, P1_NX, &runrec.nx); |
||
216 | GetCtrlVal (p1h, P1_XSTEP, &runrec.dx); |
||
217 | GetCtrlVal (p1h, P1_XMIN, &runrec.x0); |
||
218 | GetCtrlVal (p1h, P1_NY, &runrec.ny); |
||
219 | GetCtrlVal (p1h, P1_YSTEP, &runrec.dy); |
||
220 | GetCtrlVal (p1h, P1_YMIN, &runrec.y0); |
||
221 | |||
222 | GetCtrlVal (p1h, P1_NMIN, &step_minutes); |
||
223 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
||
224 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
||
225 | time(&cur_time_s); |
||
226 | end_time_s = cur_time_s + step_minutes*60; |
||
227 | printf("START:%2d-%2d-%2d (cur_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, cur_time_s, end_time_s); |
||
228 | |||
229 | //GetCtrlVal (p1h, P1_DSAVE, &dsave); |
||
230 | //if (dsave) { |
||
231 | GetCtrlVal (p1h, P1_DFILE, dfile0); |
||
232 | |||
233 | fev=0; |
||
234 | fcount=1; |
||
235 | GetCtrlVal (p1h, P1_NEWF, &fmax); |
||
236 | fmax*=1000000;//fmax in Mega Bytes |
||
237 | //} |
||
238 | GetCtrlVal (p1h, P1_SUPR, &supr0); |
||
239 | if (supr0) { |
||
240 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin); |
||
241 | GetCtrlVal (p1h, P1_FRAC, &frac); |
||
242 | } |
||
243 | |||
244 | GetCtrlVal (p1h, P1_STHRLOW, &thresholdLow); |
||
245 | runrec.thLow = thresholdLow*1000; // mV |
||
246 | GetCtrlVal (p1h, P1_STHRUP, &thresholdUp); |
||
247 | runrec.thUp = thresholdUp*1000; // mV |
||
248 | GetCtrlVal (p1h, P1_STEP, &thresholdStep); |
||
249 | runrec.thStep = thresholdStep*1000; // mV |
||
250 | |||
251 | |||
252 | #ifdef USE_DAQ |
||
253 | V673A_map(0,CAEN_V673A,0); |
||
254 | V673A_init(0); |
||
255 | |||
256 | V462_map(0,CAEN_V462,0); |
||
257 | V462_set0(0,1); |
||
258 | #endif |
||
259 | |||
260 | //if (dsave) { |
||
261 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
||
262 | |||
263 | fp = fopen (dfile, "wb"); |
||
264 | time (&runrec.time); |
||
265 | status = fwrite (&runrec, 1, runrec.len, fp); |
||
266 | //} |
||
267 | if (supr0) { |
||
268 | fseed = runrec.time & 0x7fffffff; |
||
269 | Uniform (1, fseed, &fracg); |
||
270 | } |
||
271 | |||
272 | thrrec.threshold = (unsigned long) ceil(thresholdLow*1000); // threshold in mV |
||
273 | while (thrrec.threshold <= thresholdUp*1000) { |
||
274 | SetDac(0, thrrec.threshold/1000.0); |
||
275 | SetCtrlVal(p1h, P1_STHRLOW, thrrec.threshold/1000.0); |
||
276 | //wait_loop(100000); |
||
277 | status = fwrite(&thrrec, 1, thrrec.len, fp); |
||
278 | if (print) printf("THRREC status %d len %d threshold %d\n", status, thrrec.len, thrrec.threshold); |
||
279 | |||
280 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
||
281 | posrec.xset = runrec.x0 + posrec.ix*runrec.dx; |
||
282 | #ifdef USE_MIKRO |
||
283 | //printf("MIKRO_MoveTo (1, x);%d\n",posrec.x); |
||
284 | do { |
||
285 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
||
286 | MIKRO_GetPosition(MIKRO_X, &mikroX); |
||
287 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE); |
||
288 | //printf("->MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
||
289 | #endif |
||
290 | //SetCtrlVal (p1h, P1_X, posrec.xset); |
||
291 | posrec.xset = mikroX; // set the true value |
||
292 | SetCtrlVal(p1h, P1_X, mikroX); |
||
293 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
||
294 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) { |
||
295 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy; |
||
296 | #ifdef USE_MIKRO_Y |
||
297 | //printf("MIKRO_MoveTo (2, y);%d\n",y); |
||
298 | do { |
||
299 | MIKRO_MoveTo (MIKRO_Y, posrec.yset); |
||
300 | MIKRO_GetPosition(MIKRO_Y, &mikroY); |
||
301 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE); |
||
302 | //printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
||
303 | #endif |
||
304 | //SetCtrlVal (p1h, P1_Y, posrec.yset); |
||
305 | posrec.yset = mikroY; // set the true value |
||
306 | SetCtrlVal (p1h, P1_Y, mikroY); |
||
307 | SetCtrlVal (p1h, P1_IY, posrec.iy); |
||
308 | //if (dsave) { |
||
309 | if (fmax && (ftell(fp) > fmax)) { |
||
310 | fcount+=1; |
||
311 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
||
312 | fclose(fp); |
||
313 | fp = fopen (dfile, "wb"); |
||
314 | } |
||
315 | |||
316 | time (&posrec.time); |
||
317 | status = fwrite (&posrec, 1, posrec.len, fp); |
||
318 | if (print) printf("POSREC status %d len %d\n", status, posrec.len); |
||
319 | //} |
||
320 | |||
321 | // clear the plots |
||
322 | for (j=0;j<NCH;j++) { |
||
323 | for (i=0;i<MAXCH;i++){ |
||
324 | dtdc[j][0][i]=0; |
||
325 | dtdc[j][1][i]=0; |
||
326 | } |
||
327 | } |
||
328 | |||
329 | evtrec.nev=1; |
||
330 | //time(&t); |
||
331 | //tstart=t; |
||
332 | if (print) printf("RUN START.\n"); |
||
333 | |||
334 | do { |
||
335 | unsigned long word[BSIZE]; |
||
336 | count=0; |
||
337 | ntics=0; |
||
338 | if (print) printf("Event counter: %d\n", evtrec.nev); |
||
339 | |||
340 | //if (t!=told ) printf("%d in %2.2f min daq::event() %s\n",i, (double)(t-tstart)/60., ctime(&t)); |
||
341 | |||
342 | #ifdef USE_DAQ |
||
343 | #ifdef CAEN_V673A |
||
344 | |||
345 | |||
346 | V462_start0(0); |
||
347 | //tmlnk (tout); |
||
348 | do { |
||
349 | ntrig = V673A_ntrig(0); |
||
350 | } while (ntrig==0 &&(ntics<2)); |
||
351 | //tmulk(); |
||
352 | //if (timer_out) { |
||
353 | // fprintf(stderr,"-----------------> V673a timeout !!!\n"); |
||
354 | // V673A_clallb(0); |
||
355 | // continue; |
||
356 | //} |
||
357 | |||
358 | if (ntics>=2) { |
||
359 | fprintf(stderr,"-----------------> V673a timeout !!!\n"); |
||
360 | printf("Timer tics %d\n", ntics); |
||
361 | ntics = 0; |
||
362 | evtrec.nev--; |
||
363 | V673A_clallb(0); |
||
364 | continue; |
||
365 | } |
||
366 | |||
367 | if (ntrig>0){ |
||
368 | // chip readout |
||
369 | for (chip=0;chip<2;chip++){ |
||
370 | if (chip) len = V673A_read1 (0, &word[count+2],maxn-count-2); |
||
371 | else len = V673A_read0 (0, &word[count+2],maxn-count-2); |
||
372 | |||
373 | if (len>16*32*4){ |
||
374 | if (print) printf("Length > 2048 per chip!\n"); |
||
375 | chip=2; |
||
376 | V673A_clallb(0); |
||
377 | evtrec.nev--; |
||
378 | continue; |
||
379 | } |
||
380 | pdata=&word[count+2]; |
||
381 | for(i=0;i< len;i++){ |
||
382 | tdcdata = pdata[i] & 0xFFFF ; |
||
383 | edge_type = (pdata[i]>>16)&0x1 ; |
||
384 | overflow = (pdata[i]>>17)&0x1 ; |
||
385 | tdc_num = (pdata[i]>>25)&0x1 ; |
||
386 | channel = ((pdata[i]>>18)&0x1F) |tdc_num<<5 ; |
||
387 | ev_dat = (pdata[i]>>23)&0x1 ; |
||
388 | last_dat = (pdata[i]>>30)&0x1 ; |
||
389 | nval_dat = (pdata[i]>>31)&0x1 ; |
||
390 | if (ev_dat) { |
||
391 | if(print) printf("Event %d\n",tdcdata); |
||
392 | } else { |
||
393 | dtdc[channel][edge_type][tdcdata]++; |
||
394 | |||
395 | if (print) printf |
||
396 | ("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n",channel, edge_type,ev_dat,tdcdata,last_dat,nval_dat); |
||
397 | } |
||
398 | } |
||
399 | if (count+2 < maxn) count+=module_header(0x140+chip,&word[count],len); |
||
400 | } |
||
401 | if (print) printf("Received triggers: %d \n", ntrig); |
||
402 | } else { |
||
403 | if (ntrig==0) { |
||
404 | fprintf(stderr,"-----------------> no trigger"); |
||
405 | break; |
||
406 | } else { |
||
407 | if (print) fprintf(stderr,"-----------------> wrong number of triggers in chips V673a !!!\n"); |
||
408 | } |
||
409 | V673A_clallb(0); |
||
410 | evtrec.nev--; |
||
411 | continue; |
||
412 | } |
||
413 | |||
414 | V673A_clallb(0); |
||
415 | #endif |
||
416 | #endif |
||
417 | |||
418 | |||
419 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
||
420 | evtrec.len = count*sizeof(unsigned long) + sizeof(evtrec); |
||
421 | if (print) printf("EVTREC.len = %d bytes.\n", evtrec.len); |
||
422 | |||
423 | status = fwrite (&evtrec, 1, sizeof(evtrec), fp); |
||
424 | status = fwrite (&word, 1, count*sizeof(unsigned long), fp); |
||
425 | |||
426 | |||
427 | if (!(evtrec.nev%1000)) SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
||
428 | |||
429 | if (!((evtrec.nev+1)%1000)) { |
||
430 | if (fmax && (ftell(fp) > fmax)) { |
||
431 | time (&endrec.time); |
||
432 | status = fwrite (&endrec, 1, endrec.len, fp); |
||
433 | fcount+=1; |
||
434 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
||
435 | fclose(fp); |
||
436 | fp = fopen (dfile, "wb"); |
||
437 | } |
||
438 | } |
||
439 | |||
440 | if(step_minutes > 0) { |
||
441 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
||
442 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
||
443 | time(&cur_time_s); |
||
444 | if(cur_time_s >= end_time_s) { |
||
445 | end_time_s = cur_time_s + step_minutes*60; |
||
446 | printf("STEP (nev):%2d-%2d-%2d @ %d\n", start_hours, start_minutes, start_seconds, posrec.xset); |
||
447 | break; |
||
448 | } |
||
449 | } |
||
450 | //told=t; |
||
451 | |||
452 | GetCtrlVal(p1h, P1_DAQ, &daq_on); |
||
453 | |||
454 | } while (evtrec.nev++<runrec.nev && daq_on); |
||
455 | if (!daq_on) break; |
||
456 | } // x loop |
||
457 | if (!daq_on) break; |
||
458 | } // y loop |
||
459 | if (!daq_on) break; |
||
460 | thrrec.threshold += thresholdStep*1000; |
||
461 | } // threhsold loop |
||
462 | |||
463 | //if (dsave) { |
||
464 | time (&endrec.time); |
||
465 | status = fwrite (&endrec, 1, endrec.len, fp); |
||
466 | if (print) printf("ENDREC status %d len %d\n", status, endrec.len); |
||
467 | fclose(fp); |
||
468 | //} |
||
469 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
||
470 | printf("STOP:%2d-%2d-%2d (start_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, runrec.time, endrec.time); |
||
471 | printf("Elapsed time: %u s.\n", endrec.time-runrec.time); |
||
472 | |||
473 | daq_on=0; |
||
474 | SetCtrlVal (p1h, P1_DAQ, daq_on); |
||
475 | SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
||
476 | if (print) printf("RUN END. \n\n"); |
||
477 | |||
478 | return 0; |
||
479 | } |
||
480 | |||
481 | |||
482 | int SetDac(int ch, double val){ |
||
483 | |||
484 | const unsigned int maxdac=0xFFF; |
||
485 | const double RANGE = +9.9976; //V |
||
486 | unsigned int dac; |
||
487 | |||
488 | if ((val > RANGE) || (val < 0)) { |
||
489 | printf("DAC value OUT OF RANGE!!!\n"); |
||
490 | return(-1); |
||
491 | } |
||
492 | |||
493 | dac = (val/RANGE)*maxdac; |
||
494 | CSSA_W(NDAC,ch,16,&dac); |
||
495 | printf("DAC ch %d set to %f V dac=%d\n", ch, val, dac); |
||
496 | return 0; |
||
497 | } |
||
498 | |||
499 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
||
500 | LPSTR lpszCmdLine, int nCmdShow) |
||
501 | { |
||
502 | int i,j,status,refon; |
||
503 | long int xpos, ypos, zpos; |
||
504 | char dfile[300]; |
||
505 | FILE *fp; |
||
506 | |||
507 | typedef struct { |
||
508 | unsigned long id,len; |
||
509 | unsigned long fver,time; |
||
510 | unsigned long nev,nch,ped,xy; |
||
511 | long nx,x0,dx,ny,y0,dy; |
||
512 | } RUNREC; |
||
513 | RUNREC runrec; |
||
514 | |||
515 | if (InitCVIRTE (hInstance, 0, 0) == 0) |
||
516 | return -1; /* out of memory */ |
||
517 | |||
518 | SetSleepPolicy(VAL_SLEEP_MORE); |
||
519 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
||
520 | |||
521 | SetStdioWindowOptions (1000, 0, 0); |
||
522 | SetStdioWindowSize (200, 560); |
||
523 | SetStdioWindowPosition (825, 250); |
||
524 | |||
525 | #ifdef USE_DAQ |
||
526 | VME_START(NULL); |
||
527 | #endif |
||
528 | |||
529 | #ifdef USE_MIKRO |
||
530 | MIKRO_Open (MIKRO_COM); |
||
531 | MIKRO_Init (MIKRO_X,0); |
||
532 | #ifdef USE_MIKRO_Y |
||
533 | MIKRO_Init (MIKRO_Y,0); |
||
534 | #endif |
||
535 | #ifdef USE_MIKRO_Z |
||
536 | MIKRO_Init (MIKRO_Z,0); |
||
537 | #endif |
||
538 | #endif |
||
539 | |||
32 | f9daq | 540 | if ((p1h = LoadPanel (0, "include/sipmThreshold_ui.uir", P1)) < 0) return -1; |
29 | f9daq | 541 | DisplayPanel (p1h); |
542 | SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1); |
||
543 | |||
544 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
||
545 | SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2); |
||
546 | |||
547 | QueueUserEvent (1000, p1h, P1_RESET); |
||
548 | //QueueUserEvent (1000, p1h, P1_ASD8THR); |
||
549 | QueueUserEvent (1000, p1h, P1_AMPDISSHTHR); |
||
550 | do { |
||
551 | GetUserEvent (1, &pID, &rID); |
||
552 | switch (rID) { |
||
553 | case P1_TIMER: |
||
554 | ntics+=1; |
||
555 | GetCtrlVal (p1h, P1_REFON, &refon); |
||
556 | if (refon) update_plots(); |
||
557 | break; |
||
558 | case P1_REFRESH: |
||
559 | update_plots(); |
||
560 | break; |
||
561 | case P1_DAQ: |
||
562 | GetCtrlVal (p1h, P1_DAQ, &daq_on); |
||
563 | if (daq_on) { |
||
564 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID); |
||
565 | } else { |
||
566 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, |
||
567 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
||
568 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID); |
||
569 | } |
||
570 | break; |
||
571 | |||
572 | case P1_ZSET: |
||
573 | if (!daq_on) { |
||
574 | GetCtrlVal (p1h, P1_ZSET, &zpos); |
||
575 | #ifdef USE_MIKRO_Z |
||
576 | MIKRO_MoveTo (MIKRO_Z, zpos); |
||
577 | #endif |
||
578 | } |
||
579 | break; |
||
580 | case P1_REREAD: |
||
581 | if (!daq_on) { |
||
582 | status = FileSelectPopup ("", "*.dat", ".dat", |
||
583 | "Choose the previous file", |
||
584 | VAL_LOAD_BUTTON, 0, 0, 1, 0, dfile); |
||
585 | if (status==1) { |
||
586 | fp = fopen (dfile, "rb"); |
||
587 | status = fread (&runrec, 1, sizeof(runrec), fp); |
||
588 | fclose(fp); |
||
589 | if (runrec.id==1) { |
||
590 | SetCtrlVal (p1h, P1_NX, runrec.nx); |
||
591 | SetCtrlVal (p1h, P1_XSTEP, runrec.dx); |
||
592 | SetCtrlVal (p1h, P1_XMIN, runrec.x0); |
||
593 | SetCtrlVal (p1h, P1_NY, runrec.ny); |
||
594 | SetCtrlVal (p1h, P1_YSTEP, runrec.dy); |
||
595 | SetCtrlVal (p1h, P1_YMIN, runrec.y0); |
||
596 | SetCtrlVal (p1h, P1_NEVE, runrec.nev); |
||
597 | } |
||
598 | } |
||
599 | } |
||
600 | break; |
||
601 | case P1_MGET: |
||
602 | #ifdef USE_MIKRO |
||
603 | MIKRO_GetPosition(MIKRO_X,&xpos); |
||
604 | Delay(0.01); |
||
605 | SetCtrlVal (p1h, P1_X, xpos); |
||
606 | #ifdef USE_MIKRO_Y |
||
607 | MIKRO_GetPosition(MIKRO_Y,&ypos); |
||
608 | Delay(0.01); |
||
609 | SetCtrlVal (p1h, P1_Y, ypos); |
||
610 | #endif |
||
611 | #ifdef USE_MIKRO_Z |
||
612 | MIKRO_GetPosition(MIKRO_Z,&zpos); |
||
613 | Delay(0.01); |
||
614 | SetCtrlVal (p1h, P1_Z, zpos); |
||
615 | #endif |
||
616 | #endif |
||
617 | break; |
||
618 | case P1_HO: |
||
619 | if (!daq_on) { |
||
620 | SetWaitCursor (1); |
||
621 | #ifdef USE_MIKRO |
||
622 | MIKRO_ReferenceMove (MIKRO_X); |
||
623 | #ifdef USE_MIKRO_Y |
||
624 | MIKRO_ReferenceMove (MIKRO_Y); |
||
625 | #endif |
||
626 | #ifdef USE_MIKRO_Z |
||
627 | MIKRO_ReferenceMove (MIKRO_Z); |
||
628 | #endif |
||
629 | #endif |
||
630 | SetWaitCursor (0); |
||
631 | } |
||
632 | break; |
||
633 | case P1_RESET: |
||
634 | for (j=0;j<NCH;j++) { |
||
635 | for (i=0;i<MAXCH;i++){ |
||
636 | dtdc[j][0][i]=0; |
||
637 | dtdc[j][1][i]=0; |
||
638 | |||
639 | } |
||
640 | } |
||
641 | update_plots(); |
||
642 | break; |
||
643 | case P1_TDCLOG: |
||
644 | GetCtrlVal (p1h, P1_TDCLOG, &status); |
||
645 | SetCtrlAttribute (p1h, P1_TDC, ATTR_YMAP_MODE, status); |
||
646 | update_plots(); |
||
647 | break; |
||
648 | case P1_ADCLOG: |
||
649 | GetCtrlVal (p1h, P1_ADCLOG, &status); |
||
650 | SetCtrlAttribute (p1h, P1_ADC, ATTR_YMAP_MODE, status); |
||
651 | update_plots(); |
||
652 | break; |
||
653 | /*case P1_ASD8THR: |
||
654 | { |
||
655 | double value; |
||
656 | GetCtrlVal (p1h, P1_SASD8THR, &value); |
||
657 | SetDac(0, value); |
||
658 | |||
659 | } |
||
660 | break;*/ |
||
661 | case P1_AMPDISSHTHR: |
||
662 | { |
||
663 | double value; |
||
664 | GetCtrlVal (p1h, P1_SAMPDISSHTHR, &value); |
||
665 | SetDac(1, value); |
||
666 | |||
667 | } |
||
668 | break; |
||
669 | |||
670 | } |
||
671 | |||
672 | } while ((rID != P1_EXIT)||daq_on); |
||
673 | |||
674 | CmtDiscardThreadPool (poolHandle); |
||
675 | DiscardPanel (p1h); |
||
676 | |||
677 | #ifdef USE_MIKRO |
||
678 | MIKRO_Close (); |
||
679 | #endif |
||
680 | |||
681 | #ifdef USE_DAQ |
||
682 | VME_STOP(); |
||
683 | #endif |
||
684 | return 0; |
||
685 | |||
686 | } |