Rev 341 | Go to most recent revision | Show entire file | Regard 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" |
28 | #endif |
31 | #endif |
29 | 32 | ||
30 | #include <userint.h> |
33 | #include <userint.h> |
31 | #include <ansi_c.h> |
34 | #include <ansi_c.h> |
32 | #include <utility.h> |
35 | #include <utility.h> |
33 | #include <analysis.h> |
36 | #include <analysis.h> |
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; |
Line 64... | Line 67... | ||
64 | static int ntics,dummy; |
67 | static int ntics,dummy; |
65 | // 0 1 2 3 4 5 6 7 8 9 A B C D E F |
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 | int i,j; |
107 | int i,j; |
108 | int ndat,dtype,ch,rg,adc,cres; |
108 | int ndat,dtype,ch,rg,adc,cres; |
109 | unsigned long a,b,ec1,ec2; |
109 | unsigned long a,b,ec1,ec2; |
110 | unsigned long data[100]; |
110 | unsigned long data[100]; |
111 | unsigned short aa[NCH][4]; |
111 | unsigned short aa[NCH][4]; |
Line 114... | Line 114... | ||
114 | char dfile[MAX_PATHNAME_LEN],dfile0[MAX_PATHNAME_LEN]; |
114 | char dfile[MAX_PATHNAME_LEN],dfile0[MAX_PATHNAME_LEN]; |
115 | int supr0,tdcmin,fseed,esave; |
115 | int supr0,tdcmin,fseed,esave; |
116 | float frac; |
116 | float frac; |
117 | double fracg; |
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 | ||
Line 211... | Line 211... | ||
211 | # ifdef NTDCP |
211 | # ifdef NTDCP |
212 | CSSA_R(NTDCP,0,9,&cres); |
212 | CSSA_R(NTDCP,0,9,&cres); |
213 | CSSA_R(NTDCP,0,11,&cres); |
213 | CSSA_R(NTDCP,0,11,&cres); |
214 | CSSA_R(NTDCP,0,26,&cres); |
214 | CSSA_R(NTDCP,0,26,&cres); |
215 | printf("CSSA_R(NTDCP,0,26,&cres)=0x%0x\n", cres); |
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 | if (dsave) { |
220 | if (dsave) { |
221 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
221 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
222 | fp = fopen (dfile, "wb"); |
222 | fp = fopen (dfile, "wb"); |
223 | time (&runrec.time); |
223 | time (&runrec.time); |
224 | status = fwrite (&runrec, 1, runrec.len, fp); |
224 | status = fwrite (&runrec, 1, runrec.len, fp); |
225 | } |
- | |
226 | if (supr0) { |
225 | if (supr0) { |
227 | fseed = runrec.time & 0x7fffffff; |
226 | fseed = runrec.time & 0x7fffffff; |
228 | Uniform (1, fseed, &fracg); |
227 | Uniform (1, fseed, &fracg); |
- | 228 | } |
|
229 | } |
229 | } |
230 | 230 | ||
231 | for (posrec.ix=0;posrec.ix<runrec.nx;posrec.ix++) { |
231 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
232 | posrec.xset=runrec.x0+posrec.ix*runrec.dx; |
232 | posrec.xset=runrec.x0+posrec.ix*runrec.dx; |
233 | #ifdef USE_MIKRO |
233 | #ifdef USE_MIKRO |
Line 296... | Line 296... | ||
296 | while((!(V965_status(VADC)&0x1))&&(ntics<2)&&daq_on); |
296 | while((!(V965_status(VADC)&0x1))&&(ntics<2)&&daq_on); |
297 | if (!daq_on) break; |
297 | if (!daq_on) break; |
298 | if (ntics>=2) { |
298 | if (ntics>=2) { |
299 | ndat=V965_read (VADC, &data[0]); |
299 | ndat=V965_read (VADC, &data[0]); |
300 | continue; |
300 | continue; |
- | 301 | } else { |
|
- | 302 | # ifdef USE_CAMAC |
|
- | 303 | # ifdef NTDCJ |
|
- | 304 | wait_loop(20000); |
|
- | 305 | // ntics=0; |
|
- | 306 | // do { |
|
- | 307 | // wait_loop(IWAIT); |
|
- | 308 | CSSA_R(NTDCJ,0,8,&cres); |
|
- | 309 | // if (!(cres&0x8000)) printf("CSSA_R(NTDCJ,0,8,&cres)=0x%0x\n", cres) ; |
|
- | 310 | // } while ((!(cres&0x8000))&&(ntics<2)&&daq_on); |
|
- | 311 | // if (!daq_on) break; |
|
- | 312 | // if (ntics>=2) { |
|
- | 313 | if (!(cres&0x8000)) { |
|
- | 314 | CSSA_R(NGL,0,25,&cres); |
|
- | 315 | ndat=V965_read (VADC, &data[0]); |
|
- | 316 | CSSA_R(NTDCJ,0,9,&cres); |
|
- | 317 | CSSA_R(NTDCJ,0,26,&cres); |
|
- | 318 | continue; |
|
- | 319 | } |
|
- | 320 | # endif |
|
- | 321 | # endif |
|
301 | } |
322 | } |
302 | wait_loop(2000); |
- | |
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 | if (dtype==0) { |
327 | if (dtype==0) { |
Line 313... | Line 333... | ||
313 | dtdc[ch][rg][adc]+=1; |
333 | dtdc[ch][rg][adc]+=1; |
314 | } |
334 | } |
315 | } |
335 | } |
316 | } |
336 | } |
317 | */ |
337 | */ |
318 | for (i=0; i<NCH; i++) { |
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 | CSSA_R(NTDCJ,ctdcmap[i],0,&adc); |
342 | CSSA_R(NTDCJ,ctdcmap[i],0,&adc); |
323 | # endif |
343 | # endif |
324 | # ifdef NTDCP |
344 | # ifdef NTDCP |
325 | CSSA_R(NTDCP,ctdcmap[i],0,&adc); |
345 | CSSA_R(NTDCP,ctdcmap[i],0,&adc); |
326 | # endif |
346 | # endif |
327 | # endif |
347 | # endif |
328 | // printf("TDC=0x%04X\n",adc); |
348 | // printf("TDC=0x%04X\n",adc); |
329 |
|
349 | // adc=adc&0xfff; |
- | 350 | if (adc&0x1000) adc=0xfff; else adc&=0xfff; |
|
330 | aa[i][0]=adc; |
351 | aa[i][0]=adc; |
331 | dtdc[i][0][adc]+=1; |
352 | dtdc[i][0][adc]+=1; |
332 | } |
353 | } |
333 | 354 | ||
334 | ndat=V965_read (VADC, &data[0]); |
355 | ndat=V965_read (VADC, &data[0]); |
Line 413... | Line 434... | ||
413 | 434 | ||
414 | return 0; |
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 |