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