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