Rev 39 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 39 | Rev 90 | ||
|---|---|---|---|
| Line 22... | Line 22... | ||
| 22 | 22 | ||
| 23 | #include <userint.h> |
23 | #include <userint.h> |
| 24 | #include <ansi_c.h> |
24 | #include <ansi_c.h> |
| 25 | #include <utility.h> |
25 | #include <utility.h> |
| 26 | #include <analysis.h> |
26 | #include <analysis.h> |
| - | 27 | #include <time.h> |
|
| - | 28 | //#include <zlib.h> |
|
| 27 | 29 | ||
| 28 | #include "c:\HOME\dino\sipmScan\include\sipmScan_ui.h" |
30 | #include "c:\HOME\dino\sipmScan\include\sipmScan_ui.h" |
| 29 | 31 | ||
| 30 | #ifdef USE_DAQ |
32 | #ifdef USE_DAQ |
| 31 | # define USE_CAMAC |
33 | # define USE_CAMAC |
| 32 | # include "camac.h" |
34 | # include "camac.h" |
| 33 | # define NDAC 1 |
35 | # define NDAC 1 |
| 34 | # define ASD8 0 // channels |
36 | # define ASD8 0 // channels |
| 35 | # define AMPDISSH 1 |
37 | # define AMPDISSH 1 |
| 36 | # define SIPM |
38 | # define SIPM 15 |
| 37 | //# define CAEN_V673A 0x10110000 // FMF |
39 | //# define CAEN_V673A 0x10110000 // FMF |
| 38 | # define CAEN_V673A 0x22220000 // IJS |
40 | # define CAEN_V673A 0x22220000 // IJS |
| 39 | # define CAEN_V462 0x100300 |
41 | # define CAEN_V462 0x100300 |
| 40 | #endif |
42 | #endif |
| 41 | 43 | ||
| 42 | #ifdef USE_MIKRO |
44 | #ifdef USE_MIKRO |
| 43 | # define MIKRO_COM |
45 | # define MIKRO_COM 3 |
| 44 | # define MIKRO_X 1 |
46 | # define MIKRO_X 1 |
| 45 | # define USE_MIKRO_Y |
47 | # define USE_MIKRO_Y |
| 46 | # define MIKRO_Y 2 |
48 | # define MIKRO_Y 2 |
| 47 | # define USE_MIKRO_Z |
49 | # define USE_MIKRO_Z |
| 48 | # define MIKRO_Z 3 |
50 | # define MIKRO_Z 3 |
| 49 | # define STEP_TOLERANCE 1 |
51 | # define STEP_TOLERANCE 1 |
| 50 | #endif |
52 | #endif |
| 51 | 53 | ||
| 52 | #define MAXCH |
54 | #define MAXCH 128 |
| 53 | #define MAX_THREADS 10 |
55 | #define MAX_THREADS 10 |
| 54 | 56 | ||
| 55 | #define IWAIT 200 |
57 | #define IWAIT 200 |
| 56 | 58 | ||
| 57 | #define POWERSUPPLY 66 // Power supply voltage for SiPM bias |
59 | #define POWERSUPPLY 66 // Power supply voltage for SiPM bias |
| Line 63... | Line 65... | ||
| 63 | static int something[NCH][2][MAXCH]; |
65 | static int something[NCH][2][MAXCH]; |
| 64 | 66 | ||
| 65 | static int daq_on; |
67 | static int daq_on; |
| 66 | static int poolHandle = 0; |
68 | static int poolHandle = 0; |
| 67 | static int ntics,dummy; |
69 | static int ntics,dummy; |
| - | 70 | ||
| - | 71 | static int offsetX = 5600; |
|
| - | 72 | static int offsetY = 5400; |
|
| 68 | 73 | ||
| 69 | /************************************************************/ |
74 | /************************************************************/ |
| 70 | void wait_loop(unsigned long iloop) |
75 | void wait_loop(unsigned long iloop) |
| 71 | 76 | ||
| 72 | { |
77 | { |
| Line 78... | Line 83... | ||
| 78 | 83 | ||
| 79 | int CVICALLBACK cb_timer (int panel, int control, int event, void *callbackData, |
84 | int CVICALLBACK cb_timer (int panel, int control, int event, void *callbackData, |
| 80 | int eventData1, int eventData2) |
85 | int eventData1, int eventData2) |
| 81 | { |
86 | { |
| 82 | QueueUserEvent (9000, p1h, P1_TIMER); |
87 | QueueUserEvent (9000, p1h, P1_TIMER); |
| 83 | return (0); |
88 | return (0); |
| 84 | } |
89 | } |
| 85 | 90 | ||
| 86 | int update_plots (void) |
91 | int update_plots (void) |
| 87 | { |
92 | { |
| 88 | int irange, ch; |
93 | int irange, ch; |
| 89 | 94 | ||
| 90 | GetCtrlVal (p1h, P1_PLCH, &ch); |
95 | GetCtrlVal (p1h, P1_PLCH, &ch); |
| Line 97... | Line 102... | ||
| 97 | if (ph_adc>0) DeleteGraphPlot (p1h, P1_ADC, ph_adc, VAL_DELAYED_DRAW); |
102 | if (ph_adc>0) DeleteGraphPlot (p1h, P1_ADC, ph_adc, VAL_DELAYED_DRAW); |
| 98 | GetCtrlVal (p1h, P1_ADCHL, &irange); |
103 | GetCtrlVal (p1h, P1_ADCHL, &irange); |
| 99 | ph_adc = PlotY (p1h, P1_ADC, &something[ch][irange], MAXCH, VAL_INTEGER, |
104 | ph_adc = PlotY (p1h, P1_ADC, &something[ch][irange], MAXCH, VAL_INTEGER, |
| 100 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE); |
105 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE); |
| 101 | return (0); |
106 | return (0); |
| 102 | } |
107 | } |
| 103 | 108 | ||
| 104 | 109 | ||
| 105 | int module_header(int recid,unsigned long *data,int len){ |
110 | int module_header(int recid,unsigned long *data,int len){ |
| 106 | data[0] = recid; |
111 | data[0] = recid; |
| 107 | data[1] = (len >0)? len : 0 ; |
112 | data[1] = (len >0)? len : 0 ; |
| Line 133... | Line 138... | ||
| 133 | int timer_out = 0; |
138 | int timer_out = 0; |
| 134 | //time_t t,told, tstart; |
139 | //time_t t,told, tstart; |
| 135 | int ntrig; |
140 | int ntrig; |
| 136 | int chip, len; |
141 | int chip, len; |
| 137 | unsigned long *pdata; |
142 | unsigned long *pdata; |
| 138 | 143 | ||
| 139 | FILE *fp; |
144 | FILE *fp; |
| 140 | #define RUNREC_ID 1 |
145 | #define RUNREC_ID 1 |
| 141 | #define ENDREC_ID 2 |
146 | #define ENDREC_ID 2 |
| 142 | #define POSREC_ID 3 |
147 | #define POSREC_ID 3 |
| 143 | #define EVTREC_ID 4 |
148 | #define EVTREC_ID 4 |
| 144 | 149 | ||
| 145 | typedef struct { |
150 | typedef struct { |
| 146 | unsigned long id,len; |
151 | unsigned long id,len; |
| 147 | unsigned long fver,time; |
152 | unsigned long fver,time; |
| 148 | unsigned long nev,nch,ped,xy; |
153 | unsigned long nev,nch,ped,xy; |
| 149 | long nx,x0,dx,ny,y0,dy; |
154 | long nx,x0,dx,ny,y0,dy; |
| 150 | } RUNREC; |
155 | } RUNREC; |
| 151 | RUNREC runrec; |
156 | RUNREC runrec; |
| 152 | 157 | ||
| 153 | typedef struct { |
158 | typedef struct { |
| 154 | unsigned long id,len; |
159 | unsigned long id,len; |
| 155 | unsigned long time; |
160 | unsigned long time; |
| 156 | } ENDREC; |
161 | } ENDREC; |
| 157 | ENDREC endrec; |
162 | ENDREC endrec; |
| 158 | 163 | ||
| 159 | typedef struct { |
164 | typedef struct { |
| 160 | unsigned long id,len; |
165 | unsigned long id,len; |
| Line 194... | Line 199... | ||
| 194 | 199 | ||
| 195 | cres = 0; |
200 | cres = 0; |
| 196 | 201 | ||
| 197 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev); |
202 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev); |
| 198 | GetCtrlVal (p1h, P1_PEDESTAL, &runrec.ped); |
203 | GetCtrlVal (p1h, P1_PEDESTAL, &runrec.ped); |
| 199 | 204 | ||
| 200 | GetCtrlVal (p1h, P1_NX, &runrec.nx); |
205 | GetCtrlVal (p1h, P1_NX, &runrec.nx); |
| 201 | GetCtrlVal (p1h, P1_XSTEP, &runrec.dx); |
206 | GetCtrlVal (p1h, P1_XSTEP, &runrec.dx); |
| 202 | GetCtrlVal (p1h, P1_XMIN, &runrec.x0); |
207 | GetCtrlVal (p1h, P1_XMIN, &runrec.x0); |
| 203 | GetCtrlVal (p1h, P1_NY, &runrec.ny); |
208 | GetCtrlVal (p1h, P1_NY, &runrec.ny); |
| 204 | GetCtrlVal (p1h, P1_YSTEP, &runrec.dy); |
209 | GetCtrlVal (p1h, P1_YSTEP, &runrec.dy); |
| 205 | GetCtrlVal (p1h, P1_YMIN, &runrec.y0); |
210 | GetCtrlVal (p1h, P1_YMIN, &runrec.y0); |
| 206 | 211 | ||
| 207 | GetCtrlVal (p1h, P1_NMIN, &step_minutes); |
212 | GetCtrlVal (p1h, P1_NMIN, &step_minutes); |
| 208 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
213 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
| 209 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
214 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
| 210 | time(&cur_time_s); |
215 | time(&cur_time_s); |
| 211 | end_time_s = cur_time_s + |
216 | end_time_s = cur_time_s + (int) (runrec.nx * runrec.ny * runrec.nev/10000.0 * 4.5); // expected seconds |
| 212 | 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); |
217 | 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); |
| - | 218 | SetCtrlAttribute(p1h, P1_EXPTIME, ATTR_DIMMED, 0); |
|
| - | 219 | SetCtrlVal(p1h, P1_EXPTIME, ctime(&end_time_s)); |
|
| 213 | 220 | ||
| 214 | //GetCtrlVal (p1h, P1_DSAVE, &dsave); |
221 | //GetCtrlVal (p1h, P1_DSAVE, &dsave); |
| 215 | //if (dsave) { |
222 | //if (dsave) { |
| 216 | GetCtrlVal (p1h, P1_DFILE, dfile0); |
223 | GetCtrlVal (p1h, P1_DFILE, dfile0); |
| 217 | 224 | ||
| 218 | fev=0; |
225 | fev=0; |
| 219 | fcount=1; |
226 | fcount=1; |
| 220 | GetCtrlVal (p1h, P1_NEWF, &fmax); |
227 | GetCtrlVal (p1h, P1_NEWF, &fmax); |
| Line 222... | Line 229... | ||
| 222 | //} |
229 | //} |
| 223 | GetCtrlVal (p1h, P1_SUPR, &supr0); |
230 | GetCtrlVal (p1h, P1_SUPR, &supr0); |
| 224 | if (supr0) { |
231 | if (supr0) { |
| 225 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin); |
232 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin); |
| 226 | GetCtrlVal (p1h, P1_FRAC, &frac); |
233 | GetCtrlVal (p1h, P1_FRAC, &frac); |
| 227 | } |
234 | } |
| 228 | 235 | ||
| 229 | #ifdef USE_DAQ |
236 | #ifdef USE_DAQ |
| 230 | V673A_map(0,CAEN_V673A,0); |
237 | V673A_map(0,CAEN_V673A,0); |
| 231 | V673A_init(0); |
238 | V673A_init(0); |
| 232 | 239 | ||
| 233 | V462_map(0,CAEN_V462,0); |
240 | V462_map(0,CAEN_V462,0); |
| 234 | V462_set0(0,1); |
241 | V462_set0(0,1); |
| 235 | #endif |
242 | #endif |
| 236 | 243 | ||
| 237 | //if (dsave) { |
244 | //if (dsave) { |
| 238 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
245 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
| - | 246 | SetCtrlVal(p1h, P1_FCOUNT,fcount); |
|
| 239 | 247 | ||
| 240 | fp = fopen (dfile, "wb"); |
248 | fp = fopen (dfile, "wb"); |
| 241 | time (&runrec.time); |
249 | time (&runrec.time); |
| 242 | status = fwrite (&runrec, 1, runrec.len, fp); |
250 | status = fwrite (&runrec, 1, runrec.len, fp); |
| 243 | //} |
251 | //} |
| 244 | if (supr0) { |
252 | if (supr0) { |
| 245 | fseed = runrec.time & 0x7fffffff; |
253 | fseed = runrec.time & 0x7fffffff; |
| 246 | Uniform (1, fseed, &fracg); |
254 | Uniform (1, fseed, &fracg); |
| 247 | } |
255 | } |
| 248 | - | ||
| 249 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
- | |
| 250 | posrec.xset = runrec.x0 + posrec.ix*runrec.dx; |
- | |
| 251 | #ifdef USE_MIKRO |
- | |
| 252 | do { |
- | |
| 253 | if (print) printf("MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
- | |
| 254 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
- | |
| 255 | MIKRO_GetPosition(MIKRO_X, &mikroX); |
- | |
| 256 | if (print) printf("%d\n", abs(posrec.xset - mikroX)); |
- | |
| 257 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE); |
- | |
| 258 | #endif |
- | |
| 259 |
|
256 | // vertical moving stage loop |
| 260 | SetCtrlVal (p1h, P1_X, posrec.xset); |
- | |
| 261 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
- | |
| 262 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) { |
257 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) { |
| 263 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy; |
258 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy; |
| 264 | #ifdef USE_MIKRO_Y |
259 | #ifdef USE_MIKRO_Y |
| 265 | if (print) printf("MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
260 | if (print) printf("MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
| 266 | do { |
261 | do { |
| 267 | MIKRO_MoveTo |
262 | MIKRO_MoveTo (MIKRO_Y, offsetY + posrec.yset); |
| 268 | MIKRO_GetPosition(MIKRO_Y, &mikroY); |
263 | MIKRO_GetPosition(MIKRO_Y, &mikroY); |
| - | 264 | mikroY -= offsetY; |
|
| 269 | if (print) printf("%d\n", abs(posrec.yset - mikroY)); |
265 | if (print) printf("%d\n", abs(posrec.yset - mikroY)); |
| 270 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE); |
266 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE); |
| 271 | if (print) printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
267 | if (print) printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
| 272 | #endif |
268 | #endif |
| 273 | posrec.yset = mikroY; |
269 | posrec.yset = mikroY; |
| 274 | SetCtrlVal (p1h, P1_Y, posrec.yset); |
270 | SetCtrlVal (p1h, P1_Y, posrec.yset); |
| 275 | SetCtrlVal (p1h, P1_IY, posrec.iy); |
271 | SetCtrlVal (p1h, P1_IY, posrec.iy); |
| - | 272 | ||
| - | 273 | // horizontal moving stage loop |
|
| - | 274 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
|
| - | 275 | posrec.xset = runrec.x0 + posrec.ix*runrec.dx; |
|
| - | 276 | #ifdef USE_MIKRO |
|
| - | 277 | do { |
|
| - | 278 | if (print) printf("MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
|
| - | 279 | MIKRO_MoveTo (MIKRO_X, offsetX + posrec.xset); |
|
| - | 280 | MIKRO_GetPosition(MIKRO_X, &mikroX); |
|
| - | 281 | mikroX -= offsetX; |
|
| - | 282 | if (print) printf("%d\n", abs(posrec.xset - mikroX)); |
|
| - | 283 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE); |
|
| - | 284 | #endif |
|
| - | 285 | posrec.xset = mikroX; // true value |
|
| - | 286 | SetCtrlVal (p1h, P1_X, posrec.xset); |
|
| - | 287 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
|
| - | 288 | ||
| - | 289 | ||
| 276 | //if (dsave) { |
290 | //if (dsave) { |
| 277 | if (fmax && (ftell(fp) > fmax)) { |
291 | if (fmax && (ftell(fp) > fmax)) { |
| 278 | fcount+=1; |
292 | fcount+=1; |
| 279 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
293 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
| 280 | fclose(fp); |
294 | fclose(fp); |
| 281 | fp = fopen (dfile, "wb"); |
295 | fp = fopen (dfile, "wb"); |
| 282 | } |
296 | } |
| 283 | 297 | ||
| 284 | time (&posrec.time); |
298 | time (&posrec.time); |
| 285 | status = fwrite (&posrec, 1, posrec.len, fp); |
299 | status = fwrite (&posrec, 1, posrec.len, fp); |
| 286 | if (print) printf("POSREC status %d len %d\n", status, posrec.len); |
300 | if (print) printf("POSREC status %d len %d\n", status, posrec.len); |
| 287 | //} |
301 | //} |
| 288 | 302 | ||
| Line 368... | Line 382... | ||
| 368 | } |
382 | } |
| 369 | if (print) printf("Received triggers: %d \n", ntrig); |
383 | if (print) printf("Received triggers: %d \n", ntrig); |
| 370 | } else { |
384 | } else { |
| 371 | if (ntrig==0) { |
385 | if (ntrig==0) { |
| 372 | fprintf(stderr,"-----------------> no trigger"); |
386 | fprintf(stderr,"-----------------> no trigger"); |
| 373 |
|
387 | //break; |
| 374 | } else { |
388 | } else { |
| 375 | if (print) fprintf(stderr,"-----------------> wrong number of triggers in chips V673a !!!\n"); |
389 | if (print) fprintf(stderr,"-----------------> wrong number of triggers in chips V673a !!!\n"); |
| 376 | } |
390 | } |
| 377 | V673A_clallb(0); |
391 | V673A_clallb(0); |
| 378 | evtrec.nev--; |
392 | evtrec.nev--; |
| 379 | continue; |
393 | continue; |
| 380 | } |
394 | } |
| 381 | 395 | ||
| 382 | V673A_clallb(0); |
396 | V673A_clallb(0); |
| 383 | #endif |
397 | #endif |
| 384 | #endif |
398 | #endif |
| 385 | 399 | ||
| 386 | 400 | ||
| 387 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
401 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
| 388 | evtrec.len = count*sizeof(unsigned long) + sizeof(evtrec); |
402 | evtrec.len = count*sizeof(unsigned long) + sizeof(evtrec); |
| 389 | status = fwrite (&evtrec, 1, sizeof(evtrec), fp); |
403 | status = fwrite (&evtrec, 1, sizeof(evtrec), fp); |
| 390 | status = fwrite (&word, 1, count*sizeof(unsigned long), fp); |
404 | status = fwrite (&word, 1, count*sizeof(unsigned long), fp); |
| 391 | 405 | ||
| 392 | 406 | ||
| 393 | if (!(evtrec.nev%1000)) SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
407 | if (!(evtrec.nev%1000)) SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
| 394 | 408 | ||
| 395 | if (!((evtrec.nev+1)%1000)) { |
409 | if (!((evtrec.nev+1)%1000)) { |
| 396 | if (fmax && (ftell(fp) > fmax)) { |
410 | if (fmax && (ftell(fp) > fmax)) { |
| 397 | time (&endrec.time); |
411 | time (&endrec.time); |
| 398 | status = fwrite (&endrec, 1, endrec.len, fp); |
412 | status = fwrite (&endrec, 1, endrec.len, fp); |
| 399 | fcount+=1; |
413 | fcount+=1; |
| 400 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
414 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
| - | 415 | SetCtrlVal(p1h, P1_FCOUNT,fcount); |
|
| 401 | fclose(fp); |
416 | fclose(fp); |
| 402 | fp = fopen (dfile, "wb"); |
417 | fp = fopen (dfile, "wb"); |
| 403 | } |
418 | } |
| 404 | } |
419 | } |
| 405 | 420 | ||
| 406 | if(step_minutes > 0) { |
421 | if(step_minutes > 0) { |
| 407 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
422 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
| 408 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
423 | //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; |
| 409 | time(&cur_time_s); |
424 | time(&cur_time_s); |
| Line 416... | Line 431... | ||
| 416 | //told=t; |
431 | //told=t; |
| 417 | 432 | ||
| 418 | GetCtrlVal(p1h, P1_DAQ, &daq_on); |
433 | GetCtrlVal(p1h, P1_DAQ, &daq_on); |
| 419 | 434 | ||
| 420 | } while (evtrec.nev++<runrec.nev && daq_on); |
435 | } while (evtrec.nev++<runrec.nev && daq_on); |
| 421 | if (!daq_on) break; |
- | |
| 422 | } // x loop |
- | |
| 423 | if (!daq_on) break; |
436 | if (!daq_on) break; |
| 424 | } // y loop |
437 | } // y loop |
| - | 438 | if (!daq_on) break; |
|
| - | 439 | } // x loop |
|
| 425 | 440 | ||
| 426 | //if (dsave) { |
441 | //if (dsave) { |
| 427 | time (&endrec.time); |
442 | time (&endrec.time); |
| 428 | status = fwrite (&endrec, 1, endrec.len, fp); |
443 | status = fwrite (&endrec, 1, endrec.len, fp); |
| 429 | if (print) printf("ENDREC status %d len %d\n", status, endrec.len); |
444 | if (print) printf("ENDREC status %d len %d\n", status, endrec.len); |
| 430 | fclose(fp); |
445 | fclose(fp); |
| Line 436... | Line 451... | ||
| 436 | daq_on=0; |
451 | daq_on=0; |
| 437 | SetCtrlVal (p1h, P1_DAQ, daq_on); |
452 | SetCtrlVal (p1h, P1_DAQ, daq_on); |
| 438 | SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
453 | SetCtrlVal (p1h, P1_CEVE, evtrec.nev); |
| 439 | if (print) printf("RUN END. \n\n"); |
454 | if (print) printf("RUN END. \n\n"); |
| 440 | 455 | ||
| 441 | return 0; |
456 | return 0; |
| 442 | } |
457 | } |
| 443 | 458 | ||
| 444 | 459 | ||
| 445 | int SetDac(int ch, double val){ |
460 | int SetDac(int ch, double val){ |
| 446 | 461 | ||
| 447 | const unsigned int maxdac=0xFFF; |
462 | const unsigned int maxdac=0xFFF; |
| 448 | const double RANGE = +9.9976; //V |
463 | const double RANGE = +9.9976; //V |
| 449 | unsigned int dac; |
464 | unsigned int dac; |
| Line 456... | Line 471... | ||
| 456 | dac = (val/RANGE)*maxdac; |
471 | dac = (val/RANGE)*maxdac; |
| 457 | CSSA_W(NDAC,ch,16,&dac); |
472 | CSSA_W(NDAC,ch,16,&dac); |
| 458 | printf("DAC ch %d set to %f V dac=%d\n", ch, val, dac); |
473 | printf("DAC ch %d set to %f V dac=%d\n", ch, val, dac); |
| 459 | return 0; |
474 | return 0; |
| 460 | } |
475 | } |
| 461 | 476 | ||
| 462 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
477 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
| 463 | LPSTR lpszCmdLine, int nCmdShow) |
478 | LPSTR lpszCmdLine, int nCmdShow) |
| 464 | { |
479 | { |
| 465 | int i,j,status,refon; |
480 | int i,j,status,refon; |
| 466 | long int xpos, ypos, zpos; |
481 | long int xpos, ypos, zpos; |
| 467 | char dfile[ |
482 | char dfile[512]; |
| - | 483 | char message[256]; |
|
| 468 | FILE *fp; |
484 | FILE *fp; |
| 469 | 485 | ||
| 470 | typedef struct { |
486 | typedef struct { |
| 471 | unsigned long id,len; |
487 | unsigned long id,len; |
| 472 | unsigned long fver,time; |
488 | unsigned long fver,time; |
| Line 475... | Line 491... | ||
| 475 | } RUNREC; |
491 | } RUNREC; |
| 476 | RUNREC runrec; |
492 | RUNREC runrec; |
| 477 | 493 | ||
| 478 | if (InitCVIRTE (hInstance, 0, 0) == 0) |
494 | if (InitCVIRTE (hInstance, 0, 0) == 0) |
| 479 | return -1; /* out of memory */ |
495 | return -1; /* out of memory */ |
| 480 | 496 | ||
| 481 | SetSleepPolicy(VAL_SLEEP_MORE); |
497 | SetSleepPolicy(VAL_SLEEP_MORE); |
| 482 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
498 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
| 483 | 499 | ||
| 484 | SetStdioWindowOptions (1000, 0, 0); |
500 | SetStdioWindowOptions (1000, 0, 0); |
| 485 | SetStdioWindowSize (200, 560); |
501 | SetStdioWindowSize (200, 560); |
| Line 492... | Line 508... | ||
| 492 | #ifdef USE_MIKRO |
508 | #ifdef USE_MIKRO |
| 493 | MIKRO_Open (MIKRO_COM); |
509 | MIKRO_Open (MIKRO_COM); |
| 494 | MIKRO_Init (MIKRO_X,0); |
510 | MIKRO_Init (MIKRO_X,0); |
| 495 | #ifdef USE_MIKRO_Y |
511 | #ifdef USE_MIKRO_Y |
| 496 | MIKRO_Init (MIKRO_Y,0); |
512 | MIKRO_Init (MIKRO_Y,0); |
| 497 | #endif |
513 | #endif |
| 498 | #ifdef USE_MIKRO_Z |
514 | #ifdef USE_MIKRO_Z |
| 499 | MIKRO_Init (MIKRO_Z,0); |
515 | MIKRO_Init (MIKRO_Z,0); |
| 500 | #endif |
516 | #endif |
| 501 | #endif |
517 | #endif |
| 502 | 518 | ||
| 503 | if ((p1h = LoadPanel (0, "include/sipmScan_ui.uir", P1)) < 0) return -1; |
519 | if ((p1h = LoadPanel (0, "include/sipmScan_ui.uir", P1)) < 0) return -1; |
| 504 | DisplayPanel (p1h); |
520 | DisplayPanel (p1h); |
| 505 | SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1); |
521 | SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1); |
| - | 522 | ||
| - | 523 | SetCtrlVal (p1h, P1_OFFSETX, offsetX); |
|
| - | 524 | SetCtrlVal (p1h, P1_OFFSETY, offsetY); |
|
| 506 | 525 | ||
| 507 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
526 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy); |
| 508 | SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2); |
527 | SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2); |
| 509 | 528 | ||
| 510 | QueueUserEvent (1000, p1h, P1_RESET); |
529 | QueueUserEvent (1000, p1h, P1_RESET); |
| 511 | QueueUserEvent (1000, p1h, P1_ASD8THR); |
530 | QueueUserEvent (1000, p1h, P1_ASD8THR); |
| 512 | QueueUserEvent (1000, p1h, P1_AMPDISSHTHR); |
531 | QueueUserEvent (1000, p1h, P1_AMPDISSHTHR); |
| 513 | QueueUserEvent (1000, p1h, P1_BIAS); |
532 | QueueUserEvent (1000, p1h, P1_BIAS); |
| - | 533 | QueueUserEvent (1000, p1h, P1_OFFSETX); |
|
| - | 534 | QueueUserEvent (1000, p1h, P1_OFFSETY); |
|
| 514 | 535 | ||
| 515 | printf("BIAS offset set to: %d\n", POWERSUPPLY); |
536 | printf("BIAS offset set to: %d\n", POWERSUPPLY); |
| 516 | 537 | ||
| 517 | do { |
538 | do { |
| 518 | GetUserEvent (1, &pID, &rID); |
539 | GetUserEvent (1, &pID, &rID); |
| Line 522... | Line 543... | ||
| 522 | GetCtrlVal (p1h, P1_REFON, &refon); |
543 | GetCtrlVal (p1h, P1_REFON, &refon); |
| 523 | if (refon) update_plots(); |
544 | if (refon) update_plots(); |
| 524 | break; |
545 | break; |
| 525 | case P1_REFRESH: |
546 | case P1_REFRESH: |
| 526 | update_plots(); |
547 | update_plots(); |
| 527 | break; |
548 | break; |
| 528 | case P1_DAQ: |
549 | case P1_DAQ: |
| 529 | GetCtrlVal (p1h, P1_DAQ, &daq_on); |
550 | GetCtrlVal (p1h, P1_DAQ, &daq_on); |
| 530 | if (daq_on) { |
551 | if (daq_on) { |
| 531 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID); |
552 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID); |
| 532 | } else { |
553 | } else { |
| 533 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, |
554 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
| 534 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
- | |
| 535 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID); |
555 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID); |
| 536 | } |
556 | } |
| 537 | break; |
557 | break; |
| - | 558 | case P1_XMIN: |
|
| - | 559 | if (!daq_on) { |
|
| - | 560 | GetCtrlVal (p1h, P1_XMIN, &xpos); |
|
| - | 561 | //backlash |
|
| - | 562 | MIKRO_MoveTo(MIKRO_X, xpos+offsetX-1000); |
|
| - | 563 | Delay(0.01); |
|
| - | 564 | MIKRO_MoveTo(MIKRO_X, xpos+offsetX); |
|
| 538 | 565 | } |
|
| - | 566 | break; |
|
| - | 567 | case P1_YMIN: |
|
| - | 568 | if (!daq_on) { |
|
| - | 569 | GetCtrlVal(p1h, P1_YMIN, &ypos); |
|
| - | 570 | MIKRO_MoveTo(MIKRO_Y, ypos+offsetY-1000); |
|
| - | 571 | Delay(0.01); |
|
| - | 572 | MIKRO_MoveTo(MIKRO_Y, ypos+offsetY); |
|
| - | 573 | } |
|
| - | 574 | break; |
|
| 539 | case P1_ZSET: |
575 | case P1_ZSET: |
| 540 | if (!daq_on) { |
576 | if (!daq_on) { |
| 541 | GetCtrlVal (p1h, P1_ZSET, &zpos); |
577 | GetCtrlVal (p1h, P1_ZSET, &zpos); |
| 542 | #ifdef USE_MIKRO_Z |
578 | #ifdef USE_MIKRO_Z |
| 543 | MIKRO_MoveTo (MIKRO_Z, zpos); |
579 | MIKRO_MoveTo (MIKRO_Z, zpos); |
| Line 567... | Line 603... | ||
| 567 | break; |
603 | break; |
| 568 | case P1_MGET: |
604 | case P1_MGET: |
| 569 | #ifdef USE_MIKRO |
605 | #ifdef USE_MIKRO |
| 570 | MIKRO_GetPosition(MIKRO_X,&xpos); |
606 | MIKRO_GetPosition(MIKRO_X,&xpos); |
| 571 | Delay(0.01); |
607 | Delay(0.01); |
| 572 | SetCtrlVal (p1h, P1_X, xpos); |
608 | SetCtrlVal (p1h, P1_X, xpos-offsetX); |
| 573 | #ifdef USE_MIKRO_Y |
609 | #ifdef USE_MIKRO_Y |
| 574 | MIKRO_GetPosition(MIKRO_Y,&ypos); |
610 | MIKRO_GetPosition(MIKRO_Y,&ypos); |
| 575 | Delay(0.01); |
611 | Delay(0.01); |
| 576 | SetCtrlVal (p1h, P1_Y, ypos); |
612 | SetCtrlVal (p1h, P1_Y, ypos-offsetY); |
| 577 | #endif |
613 | #endif |
| 578 | #ifdef USE_MIKRO_Z |
614 | #ifdef USE_MIKRO_Z |
| 579 | MIKRO_GetPosition(MIKRO_Z,&zpos); |
615 | MIKRO_GetPosition(MIKRO_Z,&zpos); |
| 580 | Delay(0.01); |
616 | Delay(0.01); |
| 581 | SetCtrlVal (p1h, P1_Z, zpos); |
617 | SetCtrlVal (p1h, P1_Z, zpos); |
| Line 639... | Line 675... | ||
| 639 | GetCtrlVal (p1h, P1_SBIAS, &value); |
675 | GetCtrlVal (p1h, P1_SBIAS, &value); |
| 640 | value -= POWERSUPPLY; |
676 | value -= POWERSUPPLY; |
| 641 | SetDac(SIPM, value); |
677 | SetDac(SIPM, value); |
| 642 | } |
678 | } |
| 643 | break; |
679 | break; |
| - | 680 | // reset SiPM bias to initial power supply voltage |
|
| - | 681 | case P1_BIASOFF: |
|
| - | 682 | { |
|
| - | 683 | SetDac(SIPM, 0); |
|
| - | 684 | SetCtrlVal(p1h, P1_SBIAS, (double) POWERSUPPLY); |
|
| - | 685 | } |
|
| - | 686 | case P1_OFFSETX: |
|
| - | 687 | { |
|
| - | 688 | GetCtrlVal(p1h, P1_OFFSETX, &offsetX); |
|
| - | 689 | } |
|
| - | 690 | case P1_OFFSETY: |
|
| - | 691 | { |
|
| - | 692 | GetCtrlVal(p1h, P1_OFFSETY, &offsetY); |
|
| - | 693 | } |
|
| 644 | 694 | ||
| 645 | } |
695 | } |
| 646 | 696 | ||
| 647 | } while ((rID != P1_EXIT)||daq_on); |
697 | } while ((rID != P1_EXIT)||daq_on); |
| 648 | 698 | ||