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