Rev 341 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
341 | f9daq | 1 | /* Program l2d.c za testiranje povrsinske obcutljivosti |
2 | |||
3 | Avtor: Samo Korpar |
||
4 | Verzija: |
||
5 | 1.00 3.5.2007 |
||
6 | - |
||
7 | */ |
||
8 | |||
342 | f9daq | 9 | #define USE_DAQ |
10 | #define USE_MIKRO |
||
341 | f9daq | 11 | |
12 | // Izberi ustrezni interface v meniju projektnega okna |
||
13 | // Options->CompilerDefines (dodaj /DSISVME ali /DWIENVME) |
||
342 | f9daq | 14 | |
341 | f9daq | 15 | #ifdef USE_DAQ |
16 | # define USE_CAMAC |
||
17 | # include "camac.h" |
||
342 | f9daq | 18 | //# ifdef SISVME |
19 | //# include "sisvme_dll.h" |
||
20 | //# endif |
||
341 | f9daq | 21 | # ifdef WIENVME |
22 | # include "wienvme_dll.h" |
||
23 | # endif |
||
342 | f9daq | 24 | # define VME_START(NODE) WIENVME_VME_START((NODE)) |
25 | # define VME_STOP() WIENVME_VME_STOP() |
||
341 | f9daq | 26 | # include "CAENV965.h" |
27 | #endif |
||
28 | |||
29 | #ifdef USE_MIKRO |
||
30 | # include "MIKRO.h" |
||
31 | #endif |
||
32 | |||
33 | #include <userint.h> |
||
34 | #include <ansi_c.h> |
||
35 | #include <utility.h> |
||
36 | #include <analysis.h> |
||
37 | |||
38 | #include "l2d_ui.h" |
||
39 | |||
40 | #ifdef USE_DAQ |
||
41 | //# define VTDC_ADDR 0x330000 |
||
342 | f9daq | 42 | # define VADC_ADDR 0x350000 |
341 | f9daq | 43 | //# define VTDC 0 |
44 | # define VADC 1 |
||
45 | //# define IO1_ADDR 0x100200 |
||
46 | //# define NTDCP 20 |
||
342 | f9daq | 47 | # define NTDCJ 20 |
341 | f9daq | 48 | # define NGL 23 |
49 | #endif |
||
50 | |||
51 | #ifdef USE_MIKRO |
||
52 | # define MIKRO_COM 3 |
||
53 | #endif |
||
54 | |||
55 | #define MAXCH 0x1000 |
||
56 | #define MAX_THREADS 10 |
||
57 | |||
342 | f9daq | 58 | #define IWAIT 2000 |
341 | f9daq | 59 | |
342 | f9daq | 60 | # define NCH 2 |
341 | f9daq | 61 | static int p1h, pID, rID, tfID; |
62 | static int ph_tdc, ph_adc; |
||
63 | static int dtdc[NCH][2][MAXCH]; |
||
64 | static int dadc[NCH][2][MAXCH]; |
||
65 | static int daq_on; |
||
66 | static int poolHandle = 0; |
||
67 | static int ntics,dummy; |
||
342 | f9daq | 68 | // 0 1 2 3 4 5 6 7 8 9 A B C D E F |
69 | static int tdcmap[16]= { 0, 1, 2, 3, 4, 5, 6, 7,99,99,99,99,99,99,99,99}; |
||
70 | static int adcmap[16]= {99,99,99,99,99,99,99,99, 0, 1, 2, 3, 4, 5, 6, 7}; |
||
71 | static int ctdcmap[16]= { 0, 1, 2, 3, 4, 5, 6, 7,99,99,99,99,99,99,99,99}; |
||
341 | f9daq | 72 | |
73 | /************************************************************/ |
||
74 | void wait_loop(unsigned long iloop) |
||
75 | |||
76 | { |
||
77 | int i; |
||
342 | f9daq | 78 | |
79 | for (i=0; i<iloop; i++); |
||
341 | f9daq | 80 | return; |
81 | } |
||
82 | |||
83 | int CVICALLBACK cb_timer (int panel, int control, int event, void *callbackData, |
||
342 | f9daq | 84 | int eventData1, int eventData2) { |
341 | f9daq | 85 | QueueUserEvent (9000, p1h, P1_TIMER); |
86 | return (0); |
||
87 | } |
||
88 | |||
342 | f9daq | 89 | int update_plots (void) { |
341 | f9daq | 90 | int irange, ch; |
342 | f9daq | 91 | |
341 | f9daq | 92 | GetCtrlVal (p1h, P1_PLCH, &ch); |
342 | f9daq | 93 | |
341 | f9daq | 94 | if (ph_tdc>0) DeleteGraphPlot (p1h, P1_TDC, ph_tdc, VAL_DELAYED_DRAW); |
95 | GetCtrlVal (p1h, P1_TDCHL, &irange); |
||
96 | ph_tdc = PlotY (p1h, P1_TDC, &dtdc[ch][irange], MAXCH, VAL_INTEGER, |
||
97 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
||
98 | |||
99 | if (ph_adc>0) DeleteGraphPlot (p1h, P1_ADC, ph_adc, VAL_DELAYED_DRAW); |
||
100 | GetCtrlVal (p1h, P1_ADCHL, &irange); |
||
101 | ph_adc = PlotY (p1h, P1_ADC, &dadc[ch][irange], MAXCH, VAL_INTEGER, |
||
102 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE); |
||
103 | return (0); |
||
104 | } |
||
105 | |||
342 | f9daq | 106 | int CVICALLBACK daq_run(void *functionData) { |
107 | int i,j; |
||
108 | int ndat,dtype,ch,rg,adc,cres; |
||
109 | unsigned long a,b,ec1,ec2; |
||
110 | unsigned long data[100]; |
||
111 | unsigned short aa[NCH][4]; |
||
341 | f9daq | 112 | |
342 | f9daq | 113 | int dsave,status,fmax,fcount,fev; |
114 | char dfile[MAX_PATHNAME_LEN],dfile0[MAX_PATHNAME_LEN]; |
||
115 | int supr0,tdcmin,fseed,esave; |
||
116 | float frac; |
||
117 | double fracg; |
||
341 | f9daq | 118 | |
342 | f9daq | 119 | FILE *fp=NULL; |
341 | f9daq | 120 | #define RUNREC_ID 1 |
121 | #define ENDREC_ID 2 |
||
122 | #define POSREC_ID 3 |
||
123 | #define EVTREC_ID 4 |
||
124 | |||
342 | f9daq | 125 | typedef struct { |
341 | f9daq | 126 | unsigned long id,len; |
127 | unsigned long fver,time; |
||
128 | unsigned long nev,nch,ped,xy; |
||
129 | long nx,x0,dx,ny,y0,dy; |
||
342 | f9daq | 130 | } RUNREC; |
131 | RUNREC runrec; |
||
132 | |||
133 | typedef struct { |
||
341 | f9daq | 134 | unsigned long id,len; |
135 | unsigned long time; |
||
342 | f9daq | 136 | } ENDREC; |
137 | ENDREC endrec; |
||
138 | |||
139 | typedef struct { |
||
341 | f9daq | 140 | unsigned long id,len; |
141 | unsigned long time; |
||
142 | long ix,x,xset,iy,y,yset; |
||
342 | f9daq | 143 | } POSREC; |
144 | POSREC posrec; |
||
341 | f9daq | 145 | |
342 | f9daq | 146 | typedef struct { |
341 | f9daq | 147 | unsigned long id,len; |
148 | unsigned long nev; |
||
149 | unsigned short data[NCH*2]; |
||
342 | f9daq | 150 | } EVTREC; |
151 | EVTREC evtrec; |
||
341 | f9daq | 152 | |
342 | f9daq | 153 | runrec.id = RUNREC_ID; |
154 | runrec.len = sizeof(runrec); |
||
155 | runrec.fver = 0x10000; |
||
156 | runrec.nch = NCH; |
||
157 | runrec.xy = 1; |
||
158 | endrec.id = ENDREC_ID; |
||
159 | endrec.len = sizeof(endrec); |
||
160 | posrec.id = POSREC_ID; |
||
161 | posrec.len = sizeof(posrec); |
||
162 | evtrec.id = EVTREC_ID; |
||
163 | evtrec.len = sizeof(evtrec); |
||
341 | f9daq | 164 | |
342 | f9daq | 165 | cres = 0; |
166 | |||
167 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev); |
||
168 | GetCtrlVal (p1h, P1_PEDESTAL, &runrec.ped); |
||
169 | |||
170 | GetCtrlVal (p1h, P1_NX, &runrec.nx); |
||
171 | GetCtrlVal (p1h, P1_XSTEP, &runrec.dx); |
||
172 | GetCtrlVal (p1h, P1_XMIN, &runrec.x0); |
||
173 | GetCtrlVal (p1h, P1_NY, &runrec.ny); |
||
174 | GetCtrlVal (p1h, P1_YSTEP, &runrec.dy); |
||
175 | GetCtrlVal (p1h, P1_YMIN, &runrec.y0); |
||
176 | |||
177 | GetCtrlVal (p1h, P1_DSAVE, &dsave); |
||
178 | if (dsave) { |
||
179 | GetCtrlVal (p1h, P1_DFILE, dfile0); |
||
180 | |||
181 | fev=0; |
||
182 | fcount=1; |
||
183 | GetCtrlVal (p1h, P1_NEWF, &fmax); |
||
184 | } |
||
185 | GetCtrlVal (p1h, P1_SUPR, &supr0); |
||
186 | if (supr0) { |
||
187 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin); |
||
188 | GetCtrlVal (p1h, P1_FRAC, &frac); |
||
189 | } |
||
190 | |||
341 | f9daq | 191 | #ifdef USE_DAQ |
342 | f9daq | 192 | // V965_map (VTDC, VTDC_ADDR, 1); |
193 | // V965_init (VTDC, pedestal); |
||
341 | f9daq | 194 | |
342 | f9daq | 195 | V965_map (VADC, VADC_ADDR, 1); |
196 | V965_init (VADC, runrec.ped); |
||
197 | |||
341 | f9daq | 198 | # ifdef USE_CAMAC |
342 | f9daq | 199 | BZ(&cres); |
200 | CCCZ(&cres); |
||
201 | CCCC(&cres); |
||
202 | CREM_I(&cres); |
||
203 | CSSA_R(NGL,0,25,&cres); |
||
204 | Delay(0.01); |
||
341 | f9daq | 205 | # ifdef NTDCJ |
342 | f9daq | 206 | CSSA_R(NTDCJ,0,9,&cres); |
207 | printf("CSSA_R(NTDCJ,0,9,&cres)=0x%0x\n", cres); |
||
208 | CSSA_R(NTDCJ,0,26,&cres); |
||
209 | printf("CSSA_R(NTDCJ,0,26,&cres)=0x%0x\n", cres); |
||
341 | f9daq | 210 | # endif |
211 | # ifdef NTDCP |
||
342 | f9daq | 212 | CSSA_R(NTDCP,0,9,&cres); |
213 | CSSA_R(NTDCP,0,11,&cres); |
||
214 | CSSA_R(NTDCP,0,26,&cres); |
||
215 | printf("CSSA_R(NTDCP,0,26,&cres)=0x%0x\n", cres); |
||
341 | f9daq | 216 | # endif |
217 | # endif |
||
218 | #endif |
||
219 | |||
342 | f9daq | 220 | if (dsave) { |
221 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
||
222 | fp = fopen (dfile, "wb"); |
||
223 | time (&runrec.time); |
||
224 | status = fwrite (&runrec, 1, runrec.len, fp); |
||
225 | if (supr0) { |
||
226 | fseed = runrec.time & 0x7fffffff; |
||
227 | Uniform (1, fseed, &fracg); |
||
228 | } |
||
229 | } |
||
341 | f9daq | 230 | |
342 | f9daq | 231 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
232 | posrec.xset=runrec.x0+posrec.ix*runrec.dx; |
||
341 | f9daq | 233 | #ifdef USE_MIKRO |
342 | f9daq | 234 | // printf("MIKRO_MoveTo (1, x);%d\n",x); |
235 | MIKRO_MoveTo (1, posrec.xset); |
||
236 | // printf("->MIKRO_MoveTo (1, x);%d\n",x); |
||
341 | f9daq | 237 | #endif |
238 | |||
342 | f9daq | 239 | SetCtrlVal (p1h, P1_X, posrec.xset); |
240 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
||
241 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) { |
||
341 | f9daq | 242 | |
342 | f9daq | 243 | posrec.yset=runrec.y0+posrec.iy*runrec.dy; |
341 | f9daq | 244 | #ifdef USE_MIKRO |
342 | f9daq | 245 | // printf("MIKRO_MoveTo (2, y);%d\n",y); |
246 | MIKRO_MoveTo (2, posrec.yset); |
||
247 | // printf("->MIKRO_MoveTo (2, y);%d\n",y); |
||
341 | f9daq | 248 | #endif |
249 | |||
342 | f9daq | 250 | SetCtrlVal (p1h, P1_Y, posrec.yset); |
251 | SetCtrlVal (p1h, P1_IY, posrec.iy); |
||
341 | f9daq | 252 | |
342 | f9daq | 253 | if (dsave) { |
254 | time (&posrec.time); |
||
255 | status = fwrite (&posrec, 1, posrec.len, fp); |
||
256 | } |
||
257 | |||
341 | f9daq | 258 | // clear the plots |
342 | f9daq | 259 | for (j=0; j<NCH; j++) { |
260 | for (i=0; i<MAXCH; i++) { |
||
261 | dtdc[j][0][i]=0; |
||
262 | dtdc[j][1][i]=0; |
||
263 | dadc[j][0][i]=0; |
||
264 | dadc[j][1][i]=0; |
||
341 | f9daq | 265 | } |
342 | f9daq | 266 | } |
341 | f9daq | 267 | |
342 | f9daq | 268 | evtrec.nev=1; |
269 | do { |
||
270 | for (j=0; j<NCH; j++) |
||
271 | for (i=0; i<4; i++) |
||
272 | aa[j][i]=0; |
||
273 | // if((neve%1000)==0) printf("Events %ld\n",neve); |
||
341 | f9daq | 274 | |
275 | #ifdef USE_DAQ |
||
342 | f9daq | 276 | ndat = 0; |
341 | f9daq | 277 | // a = 0x0001; |
278 | // VME_A24D16_W(IO1_ADDR + 0x000008, &a); //poslje laserski sunek |
||
279 | |||
342 | f9daq | 280 | ntics=0; |
341 | f9daq | 281 | # ifdef USE_CAMAC |
342 | f9daq | 282 | CSSA_R(NGL,0,10,&cres); |
341 | f9daq | 283 | // do { |
284 | // wait_loop(IWAIT); |
||
285 | // Delay(0.1); |
||
286 | # ifdef NTDCJ |
||
342 | f9daq | 287 | // CSSA_R(NTDCJ,0,8,&cres); |
341 | f9daq | 288 | # endif |
289 | # ifdef NTDCP |
||
342 | f9daq | 290 | // CSSA_R(NTDCP,0,8,&cres); |
341 | f9daq | 291 | # endif |
342 | f9daq | 292 | // if (!(cres&0x8000)) printf("CSSA_R(NTDCJ,0,8,&cres)=0x%0x\n", cres) ; |
341 | f9daq | 293 | // } while ((!(cres&0x8000))&&(ntics<2)&&daq_on); |
294 | # endif |
||
295 | // wait_loop(2000); |
||
342 | f9daq | 296 | while((!(V965_status(VADC)&0x1))&&(ntics<2)&&daq_on); |
297 | if (!daq_on) break; |
||
298 | if (ntics>=2) { |
||
299 | ndat=V965_read (VADC, &data[0]); |
||
300 | continue; |
||
301 | } else { |
||
302 | # ifdef USE_CAMAC |
||
303 | # ifdef NTDCJ |
||
304 | wait_loop(20000); |
||
305 | // ntics=0; |
||
306 | // do { |
||
307 | // wait_loop(IWAIT); |
||
308 | CSSA_R(NTDCJ,0,8,&cres); |
||
309 | // if (!(cres&0x8000)) printf("CSSA_R(NTDCJ,0,8,&cres)=0x%0x\n", cres) ; |
||
310 | // } while ((!(cres&0x8000))&&(ntics<2)&&daq_on); |
||
311 | // if (!daq_on) break; |
||
312 | // if (ntics>=2) { |
||
313 | if (!(cres&0x8000)) { |
||
314 | CSSA_R(NGL,0,25,&cres); |
||
341 | f9daq | 315 | ndat=V965_read (VADC, &data[0]); |
342 | f9daq | 316 | CSSA_R(NTDCJ,0,9,&cres); |
317 | CSSA_R(NTDCJ,0,26,&cres); |
||
341 | f9daq | 318 | continue; |
319 | } |
||
342 | f9daq | 320 | # endif |
321 | # endif |
||
322 | } |
||
323 | /* |
||
324 | ndat=V965_read (VTDC, &data[0]); |
||
325 | for (i=0; i<ndat; i++) { |
||
326 | dtype=(data[i]>>25)&0x3; |
||
327 | if (dtype==0) { |
||
328 | ch=tdcmap[(data[i]>>17)&0xf]; |
||
329 | if (ch<NCH) { |
||
330 | rg=(data[i]>>16)&0x1; |
||
331 | adc=data[i]&0xfff; |
||
332 | aa[ch][rg]=adc; |
||
333 | dtdc[ch][rg][adc]+=1; |
||
334 | } |
||
335 | } |
||
336 | } |
||
337 | */ |
||
338 | for (i=0; i<NCH; i++) { |
||
341 | f9daq | 339 | wait_loop(IWAIT); |
340 | # ifdef USE_CAMAC |
||
341 | # ifdef NTDCJ |
||
342 | f9daq | 342 | CSSA_R(NTDCJ,ctdcmap[i],0,&adc); |
341 | f9daq | 343 | # endif |
344 | # ifdef NTDCP |
||
342 | f9daq | 345 | CSSA_R(NTDCP,ctdcmap[i],0,&adc); |
341 | f9daq | 346 | # endif |
347 | # endif |
||
342 | f9daq | 348 | // printf("TDC=0x%04X\n",adc); |
349 | // adc=adc&0xfff; |
||
350 | if (adc&0x1000) adc=0xfff; else adc&=0xfff; |
||
351 | aa[i][0]=adc; |
||
352 | dtdc[i][0][adc]+=1; |
||
353 | } |
||
354 | |||
355 | ndat=V965_read (VADC, &data[0]); |
||
356 | for (i=0; i<ndat; i++) { |
||
357 | dtype=(data[i]>>25)&0x3; |
||
358 | if (dtype==0) { |
||
359 | ch=adcmap[(data[i]>>17)&0xf]; |
||
360 | if (ch<NCH) { |
||
361 | rg=(data[i]>>16)&0x1; |
||
362 | adc=data[i]&0xfff; |
||
363 | aa[ch][rg+2]=adc; |
||
364 | dadc[ch][rg][adc]+=1; |
||
365 | } |
||
341 | f9daq | 366 | } |
342 | f9daq | 367 | } |
341 | f9daq | 368 | |
369 | # ifdef USE_CAMAC |
||
342 | f9daq | 370 | wait_loop(IWAIT); |
341 | f9daq | 371 | # ifdef NTDCJ |
342 | f9daq | 372 | CSSA_R(NTDCJ,0,9,&cres); |
341 | f9daq | 373 | # endif |
374 | # ifdef NTDCP |
||
342 | f9daq | 375 | CSSA_R(NTDCP,0,9,&cres); |
376 | CSSA_R(NTDCP,0,26,&cres); |
||
377 | // printf("2 CSSA_R(NTDCP,0,26,&cres)=0x%0x\n", cres); |
||
378 | # endif |
||
341 | f9daq | 379 | // Delay(0.001); |
380 | // wait_loop(IWAIT); |
||
381 | // CSSA_R(NGL,0,10,&cres); |
||
382 | # endif |
||
342 | f9daq | 383 | |
341 | f9daq | 384 | #else /* generate test data */ |
342 | f9daq | 385 | if (!daq_on) break; |
386 | for (i=0; i<NCH; i++) { |
||
387 | adc=100+evtrec.nev%200; |
||
388 | dtdc[i][1][adc]+=1; |
||
389 | dadc[i][1][adc]+=1; |
||
390 | aa[i][0]=adc; |
||
391 | aa[i][2]=adc; |
||
392 | adc=200+evtrec.nev%400; |
||
393 | dtdc[i][0][adc]+=1; |
||
394 | dadc[i][0][adc]+=1; |
||
395 | aa[i][1]=adc; |
||
396 | aa[i][3]=adc; |
||
397 | } |
||
341 | f9daq | 398 | #endif |
399 | esave=dsave; |
||
342 | f9daq | 400 | if (supr0 && esave) { |
341 | f9daq | 401 | Uniform (1, -1, &fracg); |
402 | if (fracg > frac) { |
||
403 | esave=0; |
||
342 | f9daq | 404 | for (i=0; i<NCH; i++) { |
341 | f9daq | 405 | if ((aa[i][0] >= tdcmin) && (aa[i][0] < 4000)) esave=1; |
406 | } |
||
407 | } |
||
408 | } |
||
409 | if (esave) { |
||
410 | // time (&evtrec.time); |
||
342 | f9daq | 411 | for (i=0; i<NCH; i++) { |
341 | f9daq | 412 | evtrec.data[i] = aa[i][0]; |
413 | evtrec.data[i+NCH] = aa[i][2]; |
||
414 | } |
||
342 | f9daq | 415 | status = fwrite (&evtrec, 1, evtrec.len, fp); |
416 | } |
||
341 | f9daq | 417 | |
342 | f9daq | 418 | if (!(evtrec.nev%1000)) SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
419 | } while (evtrec.nev++<runrec.nev); |
||
420 | if (!daq_on) break; |
||
421 | } |
||
422 | if (!daq_on) break; |
||
423 | } |
||
424 | |||
425 | if (dsave) { |
||
426 | time (&endrec.time); |
||
427 | status = fwrite (&endrec, 1, endrec.len, fp); |
||
428 | fclose(fp); |
||
429 | } |
||
430 | |||
431 | daq_on=0; |
||
432 | SetCtrlVal (p1h, P1_DAQ, daq_on); |
||
433 | SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
||
434 | |||
435 | return 0; |
||
341 | f9daq | 436 | } |
437 | |||
438 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
||
342 | f9daq | 439 | LPSTR lpszCmdLine, int nCmdShow) { |
341 | f9daq | 440 | int i,j,status,refon; |
441 | long int zpos; |
||
442 | char dfile[300]; |
||
443 | FILE *fp; |
||
342 | f9daq | 444 | |
341 | f9daq | 445 | typedef struct { |
342 | f9daq | 446 | unsigned long id,len; |
447 | unsigned long fver,time; |
||
448 | unsigned long nev,nch,ped,xy; |
||
449 | long nx,x0,dx,ny,y0,dy; |
||
341 | f9daq | 450 | } RUNREC; |
451 | RUNREC runrec; |
||
452 | |||
453 | if (InitCVIRTE (hInstance, 0, 0) == 0) |
||
342 | f9daq | 454 | return -1; /* out of memory */ |
341 | f9daq | 455 | |
456 | SetSleepPolicy(VAL_SLEEP_MORE); |
||
457 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
||
458 | |||
459 | SetStdioWindowOptions (1000, 0, 0); |
||
460 | SetStdioWindowSize (150, 600); |
||
461 | SetStdioWindowPosition (825, 20); |
||
462 | |||
463 | #ifdef USE_DAQ |
||
464 | VME_START(NULL); |
||
465 | #endif |
||
466 | |||
467 | #ifdef USE_MIKRO |
||
468 | MIKRO_Open (MIKRO_COM); |
||
469 | MIKRO_Init (1,0); |
||
470 | MIKRO_Init (2,0); |
||
471 | MIKRO_Init (3,0); |
||
472 | #endif |
||
342 | f9daq | 473 | |
341 | f9daq | 474 | if ((p1h = LoadPanel (0, "l2d_ui.uir", P1)) < 0) return -1; |
475 | DisplayPanel (p1h); |
||
476 | SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1); |
||
477 | |||
478 | QueueUserEvent (1000, p1h, P1_RESET); |
||
342 | f9daq | 479 | |
341 | f9daq | 480 | do { |
481 | GetUserEvent (1, &pID, &rID); |
||
342 | f9daq | 482 | switch (rID) { |
341 | f9daq | 483 | case P1_TIMER: |
484 | ntics+=1; |
||
485 | GetCtrlVal (p1h, P1_REFON, &refon); |
||
342 | f9daq | 486 | if (refon) update_plots(); |
487 | break; |
||
341 | f9daq | 488 | case P1_REFRESH: |
342 | f9daq | 489 | update_plots(); |
490 | break; |
||
491 | case P1_DAQ: |
||
492 | GetCtrlVal (p1h, P1_DAQ, &daq_on); |
||
493 | if (daq_on) { |
||
494 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID); |
||
495 | } else { |
||
341 | f9daq | 496 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, |
342 | f9daq | 497 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
498 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID); |
||
499 | } |
||
500 | break; |
||
501 | case P1_ZSET: |
||
502 | if (!daq_on) { |
||
503 | GetCtrlVal (p1h, P1_ZSET, &zpos); |
||
341 | f9daq | 504 | #ifdef USE_MIKRO |
505 | MIKRO_MoveTo (3, zpos); |
||
506 | #endif |
||
507 | } |
||
342 | f9daq | 508 | break; |
509 | case P1_REREAD: |
||
510 | if (!daq_on) { |
||
341 | f9daq | 511 | status = FileSelectPopup ("", "*.dat", ".dat", |
512 | "Izberi datoteko s podatki", |
||
513 | VAL_LOAD_BUTTON, 0, 0, 1, 0, dfile); |
||
514 | if (status==1) { |
||
515 | fp = fopen (dfile, "rb"); |
||
342 | f9daq | 516 | status = fread (&runrec, 1, sizeof(runrec), fp); |
517 | fclose(fp); |
||
518 | if (runrec.id==1) { |
||
519 | SetCtrlVal (p1h, P1_NX, runrec.nx); |
||
520 | SetCtrlVal (p1h, P1_XSTEP, runrec.dx); |
||
521 | SetCtrlVal (p1h, P1_XMIN, runrec.x0); |
||
522 | SetCtrlVal (p1h, P1_NY, runrec.ny); |
||
523 | SetCtrlVal (p1h, P1_YSTEP, runrec.dy); |
||
524 | SetCtrlVal (p1h, P1_YMIN, runrec.y0); |
||
525 | SetCtrlVal (p1h, P1_NEVE, runrec.nev); |
||
341 | f9daq | 526 | } |
342 | f9daq | 527 | } |
341 | f9daq | 528 | } |
342 | f9daq | 529 | break; |
530 | case P1_HO: |
||
531 | if (!daq_on) { |
||
532 | SetWaitCursor (1); |
||
341 | f9daq | 533 | #ifdef USE_MIKRO |
342 | f9daq | 534 | MIKRO_ReferenceMove (1); |
535 | MIKRO_ReferenceMove (2); |
||
536 | MIKRO_ReferenceMove (3); |
||
341 | f9daq | 537 | #endif |
342 | f9daq | 538 | SetWaitCursor (0); |
539 | } |
||
540 | break; |
||
541 | case P1_RESET: |
||
542 | for (j=0; j<NCH; j++) { |
||
543 | for (i=0; i<MAXCH; i++) { |
||
341 | f9daq | 544 | dtdc[j][0][i]=0; |
545 | dtdc[j][1][i]=0; |
||
546 | dadc[j][0][i]=0; |
||
547 | dadc[j][1][i]=0; |
||
548 | } |
||
549 | } |
||
342 | f9daq | 550 | update_plots(); |
551 | break; |
||
552 | case P1_TDCLOG: |
||
553 | GetCtrlVal (p1h, P1_TDCLOG, &status); |
||
341 | f9daq | 554 | SetCtrlAttribute (p1h, P1_TDC, ATTR_YMAP_MODE, status); |
342 | f9daq | 555 | update_plots(); |
556 | break; |
||
557 | case P1_ADCLOG: |
||
558 | GetCtrlVal (p1h, P1_ADCLOG, &status); |
||
341 | f9daq | 559 | SetCtrlAttribute (p1h, P1_ADC, ATTR_YMAP_MODE, status); |
342 | f9daq | 560 | update_plots(); |
561 | break; |
||
562 | } |
||
563 | |||
341 | f9daq | 564 | } while ((rID != P1_EXIT)||daq_on); |
342 | f9daq | 565 | |
341 | f9daq | 566 | CmtDiscardThreadPool (poolHandle); |
567 | DiscardPanel (p1h); |
||
568 | |||
569 | #ifdef USE_MIKRO |
||
570 | MIKRO_Close (); |
||
571 | #endif |
||
572 | |||
573 | #ifdef USE_DAQ |
||
574 | VME_STOP(); |
||
342 | f9daq | 575 | #endif |
341 | f9daq | 576 | return 0; |
342 | f9daq | 577 | |
341 | f9daq | 578 | } |