Rev 39 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 39 | Rev 90 | ||
---|---|---|---|
1 | #define USE_DAQ |
1 | #define USE_DAQ |
2 | #define USE_MIKRO |
2 | #define USE_MIKRO |
3 | 3 | ||
4 | // Izberi ustrezni interface v meniju projektnega okna |
4 | // Izberi ustrezni interface v meniju projektnega okna |
5 | // Options->CompilerDefines (dodaj /DSISVME ali /DWIENVME) |
5 | // Options->CompilerDefines (dodaj /DSISVME ali /DWIENVME) |
6 | #ifdef USE_DAQ |
6 | #ifdef USE_DAQ |
7 | # define USE_CAMAC |
7 | # define USE_CAMAC |
8 | # include "c:\HOME\dino\sipmScan\include\camac.h" |
8 | # include "c:\HOME\dino\sipmScan\include\camac.h" |
9 | # ifdef SISVME |
9 | # ifdef SISVME |
10 | # include "sisvme_dll.h" |
10 | # include "sisvme_dll.h" |
11 | # endif |
11 | # endif |
12 | # ifdef WIENVME |
12 | # ifdef WIENVME |
13 | # include "wienvme_dll.h" |
13 | # include "wienvme_dll.h" |
14 | # endif |
14 | # endif |
15 | # include "CAENV673A.h" |
15 | # include "CAENV673A.h" |
16 | # include "CAENV462.h" |
16 | # include "CAENV462.h" |
17 | #endif |
17 | #endif |
18 | 18 | ||
19 | #ifdef USE_MIKRO |
19 | #ifdef USE_MIKRO |
20 | # include "MIKRO.h" |
20 | # include "MIKRO.h" |
21 | #endif |
21 | #endif |
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 |
58 | #define NCH 64 |
60 | #define NCH 64 |
59 | 61 | ||
60 | static int p1h, pID, rID, tfID; |
62 | static int p1h, pID, rID, tfID; |
61 | static int ph_tdc, ph_adc; |
63 | static int ph_tdc, ph_adc; |
62 | static int dtdc[NCH][2][MAXCH]; |
64 | static int dtdc[NCH][2][MAXCH]; |
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 | { |
73 | int i; |
78 | int i; |
74 | 79 | ||
75 | for (i=0;i<iloop;i++); |
80 | for (i=0;i<iloop;i++); |
76 | return; |
81 | return; |
77 | } |
82 | } |
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); |
91 | 96 | ||
92 | if (ph_tdc>0) DeleteGraphPlot (p1h, P1_TDC, ph_tdc, VAL_DELAYED_DRAW); |
97 | if (ph_tdc>0) DeleteGraphPlot (p1h, P1_TDC, ph_tdc, VAL_DELAYED_DRAW); |
93 | GetCtrlVal (p1h, P1_TDCHL, &irange); |
98 | GetCtrlVal (p1h, P1_TDCHL, &irange); |
94 | ph_tdc = PlotY (p1h, P1_TDC, &dtdc[ch][irange], MAXCH, VAL_INTEGER, |
99 | ph_tdc = PlotY (p1h, P1_TDC, &dtdc[ch][irange], MAXCH, VAL_INTEGER, |
95 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
100 | VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
96 | 101 | ||
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 ; |
108 | return data[1]+2; |
113 | return data[1]+2; |
109 | } |
114 | } |
110 | 115 | ||
111 | int CVICALLBACK daq_run(void *functionData) |
116 | int CVICALLBACK daq_run(void *functionData) |
112 | { |
117 | { |
113 | // *** |
118 | // *** |
114 | // variable declarations |
119 | // variable declarations |
115 | int i,j; |
120 | int i,j; |
116 | int dtype,ch,rg,adc,cres,bsr; |
121 | int dtype,ch,rg,adc,cres,bsr; |
117 | 122 | ||
118 | //unsigned short aa[NCH][4]; |
123 | //unsigned short aa[NCH][4]; |
119 | unsigned long tdc[NCH]; |
124 | unsigned long tdc[NCH]; |
120 | unsigned long step_minutes, end_time_s, cur_time_s; |
125 | unsigned long step_minutes, end_time_s, cur_time_s; |
121 | int start_hours, start_minutes, start_seconds; |
126 | int start_hours, start_minutes, start_seconds; |
122 | 127 | ||
123 | int status,fmax,fcount,fev; |
128 | int status,fmax,fcount,fev; |
124 | int popupret; |
129 | int popupret; |
125 | 130 | ||
126 | char dfile[MAX_PATHNAME_LEN],dfile0[MAX_PATHNAME_LEN]; |
131 | char dfile[MAX_PATHNAME_LEN],dfile0[MAX_PATHNAME_LEN]; |
127 | int supr0,tdcmin,fseed; |
132 | int supr0,tdcmin,fseed; |
128 | float frac; |
133 | float frac; |
129 | double fracg; |
134 | double fracg; |
130 | unsigned short dum16; |
135 | unsigned short dum16; |
131 | int count; |
136 | int count; |
132 | int print = 0; |
137 | int print = 0; |
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; |
161 | unsigned long time; |
166 | unsigned long time; |
162 | long ix,x,xset,iy,y,yset; |
167 | long ix,x,xset,iy,y,yset; |
163 | } POSREC; |
168 | } POSREC; |
164 | POSREC posrec; |
169 | POSREC posrec; |
165 | long mikroX; |
170 | long mikroX; |
166 | long mikroY; |
171 | long mikroY; |
167 | 172 | ||
168 | typedef struct { |
173 | typedef struct { |
169 | unsigned long id,len; |
174 | unsigned long id,len; |
170 | unsigned long nev; |
175 | unsigned long nev; |
171 | //unsigned short data[NCH]; |
176 | //unsigned short data[NCH]; |
172 | } EVTREC; |
177 | } EVTREC; |
173 | EVTREC evtrec; |
178 | EVTREC evtrec; |
174 | #define BSIZE 20000 |
179 | #define BSIZE 20000 |
175 | 180 | ||
176 | int maxn = BSIZE-4; // 2 words x 2 headers |
181 | int maxn = BSIZE-4; // 2 words x 2 headers |
177 | int tdcdata, edge_type, overflow, tdc_num, channel, ev_dat, last_dat, nval_dat; |
182 | int tdcdata, edge_type, overflow, tdc_num, channel, ev_dat, last_dat, nval_dat; |
178 | // end of declarations |
183 | // end of declarations |
179 | // *** |
184 | // *** |
180 | 185 | ||
181 | runrec.id = RUNREC_ID; |
186 | runrec.id = RUNREC_ID; |
182 | runrec.len = sizeof(runrec); |
187 | runrec.len = sizeof(runrec); |
183 | //runrec.fver = 0x10000; |
188 | //runrec.fver = 0x10000; |
184 | runrec.nch = NCH; |
189 | runrec.nch = NCH; |
185 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);//runrec.xy = 1; |
190 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);//runrec.xy = 1; |
186 | GetCtrlVal(p1h, P1_DEBUG, &print); |
191 | GetCtrlVal(p1h, P1_DEBUG, &print); |
187 | endrec.id = ENDREC_ID; |
192 | endrec.id = ENDREC_ID; |
188 | endrec.len = sizeof(endrec); |
193 | endrec.len = sizeof(endrec); |
189 | posrec.id = POSREC_ID; |
194 | posrec.id = POSREC_ID; |
190 | posrec.len = sizeof(posrec); |
195 | posrec.len = sizeof(posrec); |
191 | evtrec.id = EVTREC_ID; |
196 | evtrec.id = EVTREC_ID; |
192 | evtrec.len = sizeof(evtrec); |
197 | evtrec.len = sizeof(evtrec); |
193 | 198 | ||
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); |
221 | fmax*=1000000;//fmax in Mega Bytes |
228 | fmax*=1000000;//fmax in Mega Bytes |
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 | } |
- | 256 | // vertical moving stage loop |
|
- | 257 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) { |
|
- | 258 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy; |
|
- | 259 | #ifdef USE_MIKRO_Y |
|
- | 260 | if (print) printf("MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
|
- | 261 | do { |
|
- | 262 | MIKRO_MoveTo (MIKRO_Y, offsetY + posrec.yset); |
|
- | 263 | MIKRO_GetPosition(MIKRO_Y, &mikroY); |
|
- | 264 | mikroY -= offsetY; |
|
- | 265 | if (print) printf("%d\n", abs(posrec.yset - mikroY)); |
|
- | 266 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE); |
|
- | 267 | if (print) 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); |
|
248 | 272 | ||
- | 273 | // horizontal moving stage loop |
|
249 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
274 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
250 |
|
275 | posrec.xset = runrec.x0 + posrec.ix*runrec.dx; |
251 | #ifdef USE_MIKRO |
276 | #ifdef USE_MIKRO |
252 | do { |
277 | do { |
253 | if (print) printf("MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
278 | if (print) printf("MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
254 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
279 | MIKRO_MoveTo (MIKRO_X, offsetX + posrec.xset); |
255 | MIKRO_GetPosition(MIKRO_X, &mikroX); |
280 | MIKRO_GetPosition(MIKRO_X, &mikroX); |
- | 281 | mikroX -= offsetX; |
|
256 | if (print) printf("%d\n", abs(posrec.xset - mikroX)); |
282 | if (print) printf("%d\n", abs(posrec.xset - mikroX)); |
257 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE); |
283 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE); |
258 | #endif |
284 | #endif |
259 | posrec.xset = mikroX; // true value |
285 | posrec.xset = mikroX; // true value |
260 | SetCtrlVal (p1h, P1_X, posrec.xset); |
286 | SetCtrlVal (p1h, P1_X, posrec.xset); |
261 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
287 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
262 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) { |
- | |
263 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy; |
- | |
264 | #ifdef USE_MIKRO_Y |
- | |
265 | if (print) printf("MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
- | |
266 | do { |
288 | |
267 | MIKRO_MoveTo (MIKRO_Y, posrec.yset); |
- | |
268 | MIKRO_GetPosition(MIKRO_Y, &mikroY); |
- | |
269 | if (print) printf("%d\n", abs(posrec.yset - mikroY)); |
- | |
270 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE); |
- | |
271 | if (print) printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
- | |
272 | #endif |
289 | |
273 | posrec.yset = mikroY; |
- | |
274 | SetCtrlVal (p1h, P1_Y, posrec.yset); |
- | |
275 | SetCtrlVal (p1h, P1_IY, posrec.iy); |
- | |
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 | ||
289 | // clear the plots |
303 | // clear the plots |
290 | for (j=0;j<NCH;j++) { |
304 | for (j=0;j<NCH;j++) { |
291 | for (i=0;i<MAXCH;i++){ |
305 | for (i=0;i<MAXCH;i++){ |
292 | dtdc[j][0][i]=0; |
306 | dtdc[j][0][i]=0; |
293 | dtdc[j][1][i]=0; |
307 | dtdc[j][1][i]=0; |
294 | } |
308 | } |
295 | } |
309 | } |
296 | 310 | ||
297 | evtrec.nev=1; |
311 | evtrec.nev=1; |
298 | //time(&t); |
312 | //time(&t); |
299 | //tstart=t; |
313 | //tstart=t; |
300 | if (print) printf("RUN START.\n"); |
314 | if (print) printf("RUN START.\n"); |
301 | 315 | ||
302 | do { |
316 | do { |
303 | unsigned long word[BSIZE]; |
317 | unsigned long word[BSIZE]; |
304 | count=0; |
318 | count=0; |
305 | ntics=0; |
319 | ntics=0; |
306 | if (print) printf("Event counter: %d\n", evtrec.nev); |
320 | if (print) printf("Event counter: %d\n", evtrec.nev); |
307 | 321 | ||
308 | //if (t!=told ) printf("%d in %2.2f min daq::event() %s\n",i, (double)(t-tstart)/60., ctime(&t)); |
322 | //if (t!=told ) printf("%d in %2.2f min daq::event() %s\n",i, (double)(t-tstart)/60., ctime(&t)); |
309 | 323 | ||
310 | #ifdef USE_DAQ |
324 | #ifdef USE_DAQ |
311 | #ifdef CAEN_V673A |
325 | #ifdef CAEN_V673A |
312 | 326 | ||
313 | 327 | ||
314 | V462_start0(0); |
328 | V462_start0(0); |
315 | //tmlnk (tout); |
329 | //tmlnk (tout); |
316 | do { |
330 | do { |
317 | ntrig = V673A_ntrig(0); |
331 | ntrig = V673A_ntrig(0); |
318 | } while (ntrig==0 &&(ntics<2)); |
332 | } while (ntrig==0 &&(ntics<2)); |
319 | //tmulk(); |
333 | //tmulk(); |
320 | //if (timer_out) { |
334 | //if (timer_out) { |
321 | // fprintf(stderr,"-----------------> V673a timeout !!!\n"); |
335 | // fprintf(stderr,"-----------------> V673a timeout !!!\n"); |
322 | // V673A_clallb(0); |
336 | // V673A_clallb(0); |
323 | // continue; |
337 | // continue; |
324 | //} |
338 | //} |
325 | 339 | ||
326 | if (ntics>=2) { |
340 | if (ntics>=2) { |
327 | fprintf(stderr,"-----------------> V673a timeout !!!\n"); |
341 | fprintf(stderr,"-----------------> V673a timeout !!!\n"); |
328 | printf("Timer tics %d\n", ntics); |
342 | printf("Timer tics %d\n", ntics); |
329 | ntics = 0; |
343 | ntics = 0; |
330 | evtrec.nev--; |
344 | evtrec.nev--; |
331 | V673A_clallb(0); |
345 | V673A_clallb(0); |
332 | continue; |
346 | continue; |
333 | } |
347 | } |
334 | 348 | ||
335 | if (ntrig>0){ |
349 | if (ntrig>0){ |
336 | // chip readout |
350 | // chip readout |
337 | for (chip=0;chip<2;chip++){ |
351 | for (chip=0;chip<2;chip++){ |
338 | if (chip) len = V673A_read1 (0, &word[count+2],maxn-count-2); |
352 | if (chip) len = V673A_read1 (0, &word[count+2],maxn-count-2); |
339 | else len = V673A_read0 (0, &word[count+2],maxn-count-2); |
353 | else len = V673A_read0 (0, &word[count+2],maxn-count-2); |
340 | 354 | ||
341 | if (len>16*32*4){ |
355 | if (len>16*32*4){ |
342 | if (print) printf("Length > 2048 per chip!\n"); |
356 | if (print) printf("Length > 2048 per chip!\n"); |
343 | chip=2; |
357 | chip=2; |
344 | V673A_clallb(0); |
358 | V673A_clallb(0); |
345 | evtrec.nev--; |
359 | evtrec.nev--; |
346 | continue; |
360 | continue; |
347 | } |
361 | } |
348 | pdata=&word[count+2]; |
362 | pdata=&word[count+2]; |
349 | for(i=0;i< len;i++){ |
363 | for(i=0;i< len;i++){ |
350 | tdcdata = pdata[i] & 0xFFFF ; |
364 | tdcdata = pdata[i] & 0xFFFF ; |
351 | edge_type = (pdata[i]>>16)&0x1 ; |
365 | edge_type = (pdata[i]>>16)&0x1 ; |
352 | overflow = (pdata[i]>>17)&0x1 ; |
366 | overflow = (pdata[i]>>17)&0x1 ; |
353 | tdc_num = (pdata[i]>>25)&0x1 ; |
367 | tdc_num = (pdata[i]>>25)&0x1 ; |
354 | channel = ((pdata[i]>>18)&0x1F) |tdc_num<<5 ; |
368 | channel = ((pdata[i]>>18)&0x1F) |tdc_num<<5 ; |
355 | ev_dat = (pdata[i]>>23)&0x1 ; |
369 | ev_dat = (pdata[i]>>23)&0x1 ; |
356 | last_dat = (pdata[i]>>30)&0x1 ; |
370 | last_dat = (pdata[i]>>30)&0x1 ; |
357 | nval_dat = (pdata[i]>>31)&0x1 ; |
371 | nval_dat = (pdata[i]>>31)&0x1 ; |
358 | if (ev_dat) { |
372 | if (ev_dat) { |
359 | if(print) printf("Event %d\n",tdcdata); |
373 | if(print) printf("Event %d\n",tdcdata); |
360 | } else { |
374 | } else { |
361 | dtdc[channel][edge_type][tdcdata]++; |
375 | dtdc[channel][edge_type][tdcdata]++; |
362 | 376 | ||
363 | if (print) printf |
377 | if (print) printf |
364 | ("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n",channel, edge_type,ev_dat,tdcdata,last_dat,nval_dat); |
378 | ("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n",channel, edge_type,ev_dat,tdcdata,last_dat,nval_dat); |
365 | } |
379 | } |
366 | } |
380 | } |
367 | if (count+2 < maxn) count+=module_header(0x140+chip,&word[count],len); |
381 | if (count+2 < maxn) count+=module_header(0x140+chip,&word[count],len); |
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); |
410 | if(cur_time_s >= end_time_s) { |
425 | if(cur_time_s >= end_time_s) { |
411 | end_time_s = cur_time_s + step_minutes*60; |
426 | end_time_s = cur_time_s + step_minutes*60; |
412 | printf("STEP (nev):%2d-%2d-%2d @ %d\n", start_hours, start_minutes, start_seconds, posrec.xset); |
427 | printf("STEP (nev):%2d-%2d-%2d @ %d\n", start_hours, start_minutes, start_seconds, posrec.xset); |
413 | break; |
428 | break; |
414 | } |
429 | } |
415 | } |
430 | } |
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; |
436 | if (!daq_on) break; |
422 | } // |
437 | } // y loop |
423 | if (!daq_on) break; |
438 | if (!daq_on) break; |
424 | } // |
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); |
431 | //} |
446 | //} |
432 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
447 | GetSystemTime(&start_hours, &start_minutes, &start_seconds); |
433 | printf("STOP:%2d-%2d-%2d (start_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, runrec.time, endrec.time); |
448 | printf("STOP:%2d-%2d-%2d (start_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, runrec.time, endrec.time); |
434 | printf("Elapsed time: %u s.\n", endrec.time-runrec.time); |
449 | printf("Elapsed time: %u s.\n", endrec.time-runrec.time); |
435 | 450 | ||
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; |
450 | 465 | ||
451 | if ((val > RANGE) || (val < 0)) { |
466 | if ((val > RANGE) || (val < 0)) { |
452 | printf("DAC value OUT OF RANGE!!!\n"); |
467 | printf("DAC value OUT OF RANGE!!!\n"); |
453 | return(-1); |
468 | return(-1); |
454 | } |
469 | } |
455 | 470 | ||
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; |
473 | unsigned long nev,nch,ped,xy; |
489 | unsigned long nev,nch,ped,xy; |
474 | long nx,x0,dx,ny,y0,dy; |
490 | long nx,x0,dx,ny,y0,dy; |
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); |
486 | SetStdioWindowPosition (825, 250); |
502 | SetStdioWindowPosition (825, 250); |
487 | 503 | ||
488 | #ifdef USE_DAQ |
504 | #ifdef USE_DAQ |
489 | VME_START(NULL); |
505 | VME_START(NULL); |
490 | #endif |
506 | #endif |
491 | 507 | ||
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); |
519 | switch (rID) { |
540 | switch (rID) { |
520 | case P1_TIMER: |
541 | case P1_TIMER: |
521 | ntics+=1; |
542 | ntics+=1; |
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); |
544 | #endif |
580 | #endif |
545 | } |
581 | } |
546 | break; |
582 | break; |
547 | case P1_REREAD: |
583 | case P1_REREAD: |
548 | if (!daq_on) { |
584 | if (!daq_on) { |
549 | status = FileSelectPopup ("", "*.dat", ".dat", |
585 | status = FileSelectPopup ("", "*.dat", ".dat", |
550 | "Izberi datoteko s podatki", |
586 | "Izberi datoteko s podatki", |
551 | VAL_LOAD_BUTTON, 0, 0, 1, 0, dfile); |
587 | VAL_LOAD_BUTTON, 0, 0, 1, 0, dfile); |
552 | if (status==1) { |
588 | if (status==1) { |
553 | fp = fopen (dfile, "rb"); |
589 | fp = fopen (dfile, "rb"); |
554 | status = fread (&runrec, 1, sizeof(runrec), fp); |
590 | status = fread (&runrec, 1, sizeof(runrec), fp); |
555 | fclose(fp); |
591 | fclose(fp); |
556 | if (runrec.id==1) { |
592 | if (runrec.id==1) { |
557 | SetCtrlVal (p1h, P1_NX, runrec.nx); |
593 | SetCtrlVal (p1h, P1_NX, runrec.nx); |
558 | SetCtrlVal (p1h, P1_XSTEP, runrec.dx); |
594 | SetCtrlVal (p1h, P1_XSTEP, runrec.dx); |
559 | SetCtrlVal (p1h, P1_XMIN, runrec.x0); |
595 | SetCtrlVal (p1h, P1_XMIN, runrec.x0); |
560 | SetCtrlVal (p1h, P1_NY, runrec.ny); |
596 | SetCtrlVal (p1h, P1_NY, runrec.ny); |
561 | SetCtrlVal (p1h, P1_YSTEP, runrec.dy); |
597 | SetCtrlVal (p1h, P1_YSTEP, runrec.dy); |
562 | SetCtrlVal (p1h, P1_YMIN, runrec.y0); |
598 | SetCtrlVal (p1h, P1_YMIN, runrec.y0); |
563 | SetCtrlVal (p1h, P1_NEVE, runrec.nev); |
599 | SetCtrlVal (p1h, P1_NEVE, runrec.nev); |
564 | } |
600 | } |
565 | } |
601 | } |
566 | } |
602 | } |
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); |
582 | #endif |
618 | #endif |
583 | #endif |
619 | #endif |
584 | break; |
620 | break; |
585 | case P1_HO: |
621 | case P1_HO: |
586 | if (!daq_on) { |
622 | if (!daq_on) { |
587 | SetWaitCursor (1); |
623 | SetWaitCursor (1); |
588 | #ifdef USE_MIKRO |
624 | #ifdef USE_MIKRO |
589 | MIKRO_ReferenceMove (MIKRO_X); |
625 | MIKRO_ReferenceMove (MIKRO_X); |
590 | #ifdef USE_MIKRO_Y |
626 | #ifdef USE_MIKRO_Y |
591 | MIKRO_ReferenceMove (MIKRO_Y); |
627 | MIKRO_ReferenceMove (MIKRO_Y); |
592 | #endif |
628 | #endif |
593 | #ifdef USE_MIKRO_Z |
629 | #ifdef USE_MIKRO_Z |
594 | MIKRO_ReferenceMove (MIKRO_Z); |
630 | MIKRO_ReferenceMove (MIKRO_Z); |
595 | #endif |
631 | #endif |
596 | #endif |
632 | #endif |
597 | SetWaitCursor (0); |
633 | SetWaitCursor (0); |
598 | } |
634 | } |
599 | break; |
635 | break; |
600 | case P1_RESET: |
636 | case P1_RESET: |
601 | for (j=0;j<NCH;j++) { |
637 | for (j=0;j<NCH;j++) { |
602 | for (i=0;i<MAXCH;i++){ |
638 | for (i=0;i<MAXCH;i++){ |
603 | dtdc[j][0][i]=0; |
639 | dtdc[j][0][i]=0; |
604 | dtdc[j][1][i]=0; |
640 | dtdc[j][1][i]=0; |
605 | 641 | ||
606 | } |
642 | } |
607 | } |
643 | } |
608 | update_plots(); |
644 | update_plots(); |
609 | break; |
645 | break; |
610 | case P1_TDCLOG: |
646 | case P1_TDCLOG: |
611 | GetCtrlVal (p1h, P1_TDCLOG, &status); |
647 | GetCtrlVal (p1h, P1_TDCLOG, &status); |
612 | SetCtrlAttribute (p1h, P1_TDC, ATTR_YMAP_MODE, status); |
648 | SetCtrlAttribute (p1h, P1_TDC, ATTR_YMAP_MODE, status); |
613 | update_plots(); |
649 | update_plots(); |
614 | break; |
650 | break; |
615 | case P1_ADCLOG: |
651 | case P1_ADCLOG: |
616 | GetCtrlVal (p1h, P1_ADCLOG, &status); |
652 | GetCtrlVal (p1h, P1_ADCLOG, &status); |
617 | SetCtrlAttribute (p1h, P1_ADC, ATTR_YMAP_MODE, status); |
653 | SetCtrlAttribute (p1h, P1_ADC, ATTR_YMAP_MODE, status); |
618 | update_plots(); |
654 | update_plots(); |
619 | break; |
655 | break; |
620 | case P1_ASD8THR: |
656 | case P1_ASD8THR: |
621 | { |
657 | { |
622 | double value; |
658 | double value; |
623 | GetCtrlVal (p1h, P1_SASD8THR, &value); |
659 | GetCtrlVal (p1h, P1_SASD8THR, &value); |
624 | SetDac(ASD8, value); |
660 | SetDac(ASD8, value); |
625 | 661 | ||
626 | } |
662 | } |
627 | break; |
663 | break; |
628 | case P1_AMPDISSHTHR: |
664 | case P1_AMPDISSHTHR: |
629 | { |
665 | { |
630 | double value; |
666 | double value; |
631 | GetCtrlVal (p1h, P1_SAMPDISSHTHR, &value); |
667 | GetCtrlVal (p1h, P1_SAMPDISSHTHR, &value); |
632 | SetDac(AMPDISSH, value); |
668 | SetDac(AMPDISSH, value); |
633 | 669 | ||
634 | } |
670 | } |
635 | break; |
671 | break; |
636 | case P1_BIAS: |
672 | case P1_BIAS: |
637 | { |
673 | { |
638 | double value; |
674 | double value; |
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 | ||
649 | CmtDiscardThreadPool (poolHandle); |
699 | CmtDiscardThreadPool (poolHandle); |
650 | DiscardPanel (p1h); |
700 | DiscardPanel (p1h); |
651 | 701 | ||
652 | #ifdef USE_MIKRO |
702 | #ifdef USE_MIKRO |
653 | MIKRO_Close (); |
703 | MIKRO_Close (); |
654 | #endif |
704 | #endif |
655 | 705 | ||
656 | #ifdef USE_DAQ |
706 | #ifdef USE_DAQ |
657 | VME_STOP(); |
707 | VME_STOP(); |
658 | #endif |
708 | #endif |
659 | return 0; |
709 | return 0; |
660 | 710 | ||
661 | } |
711 | } |
662 | 712 |