Subversion Repositories f9daq

Rev

Rev 263 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 263 Rev 322
Line 13... Line 13...
13
#define MAXSAMPLES 16384
13
#define MAXSAMPLES 16384
14
#define MINTRGDELAY -8192
14
#define MINTRGDELAY -8192
15
 
15
 
16
 
16
 
17
static int panelHandle;
17
static int panelHandle;
-
 
18
 
-
 
19
static int outputHandle;
-
 
20
static int settingsHandle;
-
 
21
static int ch0Handle;
-
 
22
static int ch1Handle;
18
 
23
 
19
static unsigned int chandle = 0;
24
static unsigned int chandle = 0;
20
//static int tfID;
25
//static int tfID;
21
int pfreq;
26
int pfreq;
22
static int plothandle[2]= {0,0};
27
static int plothandle[2]= {0,0};
Line 30... Line 35...
30
int adctype;
35
int adctype;
31
float athreshold, twin0,twin1;
36
float athreshold, twin0,twin1;
32
float timebins[0XFFFF];
37
float timebins[0XFFFF];
33
float daqtime;
38
float daqtime;
34
double starttime;
39
double starttime;
35
 
40
 
36
FILE *foutput;
41
FILE *foutput;
37
int outwaveforms=0;
42
int outwaveforms=0;
38
 
43
 
39
static CmtThreadPoolHandle poolHandle = 0;
44
static CmtThreadPoolHandle poolHandle = 0;
40
int ctrl_c=0;
45
int ctrl_c=0;
41
 
46
 
42
 
47
 
43
int CVICALLBACK SocketCB (unsigned handle, int xType, int errCode, void *callbackData);
48
int CVICALLBACK SocketCB (unsigned handle, int xType, int errCode, void *callbackData);
44
 
49
 
45
 
50
 
46
 
51
 
47
static int export_data (int hid) {
52
static int export_data (int hid) {
48
 
53
 
49
  char filename[0xFF],rootcmd[0xFF];
54
  char filename[0xFF],rootcmd[0xFF];
50
  char fname[0xFF];
55
  char fname[0xFF];
-
 
56
  char path[0xFF];
-
 
57
  char datestr[0xFF];
51
  int type=0;
58
  int type=0;
52
 
59
 
53
  GetCtrlVal(panelHandle,PANEL_EXPORTNAME,fname);
60
  GetCtrlVal(settingsHandle,SETTINGS_EXPORTNAME,fname);
54
  GetCtrlVal(panelHandle,PANEL_FILETYPE,&type);
61
  GetCtrlVal(settingsHandle,SETTINGS_FILETYPE,&type);
-
 
62
  sprintf(path, "%s\\Desktop\\data", getenv("USERPROFILE"));
-
 
63
  MakeDir (path);
55
 
64
 
56
  FILE *fp;
65
  FILE *fp;
-
 
66
  int hour, min, month, day,year;
57
 
67
  double sec;
-
 
68
  double mtime;
-
 
69
  GetCurrentDateTime (&mtime);
-
 
70
  GetDateTimeElements (mtime, &hour, &min, &sec, &month, &day, &year);
-
 
71
  sprintf(datestr,"%02d_%02d_%02d", hour, min, (int) sec );
58
  switch (type) {
72
  switch (type) {
59
    case 0:
73
    case 0:
60
    case 1:
74
    case 1:
61
      sprintf(filename,"%s_%d.root",fname, hid);
75
      sprintf(filename,"%s\\%s_%d_%s.dat",path, fname, hid, datestr);
62
      fp  =fopen(filename,"wb");
76
      fp  =fopen(filename,"wb");
63
      if (fp) {
77
      if (fp) {
64
        H1D_Write2File(hid,fp);
78
        H1D_Write2File(hid,fp);
65
        fclose(fp);
79
        fclose(fp);
66
        if (type) {
80
        if (type) {
67
          sprintf(rootcmd ,"thisroot.bat && root.exe H1Dload.cxx(\\\"%s\\\")", filename);
81
          sprintf(rootcmd ,"thisroot.bat  && root.exe C:/home/cvi/apps/RedPitaya/soccli/H1Dload.cxx(\\\"%s_%d_%s.dat\\\")", fname, hid,  datestr);
68
          LaunchExecutable(rootcmd);
82
          LaunchExecutable(rootcmd);
69
 
83
 
70
        }
84
        }
71
        printf("Histogram %d exported to %s\n", hid, filename);
85
        printf("Histogram %d exported to %s \n%s\n", hid, filename, rootcmd);
72
      }
86
      }
73
      break;
87
      break;
74
    case 2:
88
    case 2:
75
      sprintf(filename,"%s_%d.txt",fname, hid);
89
      sprintf(filename,"%s\\%s_%d_%s.txt",path, fname, hid,  datestr);
76
      fp=fopen(filename,"w");
90
      fp=fopen(filename,"w");
77
      if (fp) {
91
      if (fp) {
78
        for (int i=0; i<H1D_GetNbinsX(hid); i++) fprintf(fp,"%g\t%g\n", H1D_GetXBinCenter(hid,i), H1D_GetBinContent(hid,i) );
92
        for (int i=0; i<H1D_GetNbinsX(hid); i++) fprintf(fp,"%g\t%g\n", H1D_GetXBinCenter(hid,i), H1D_GetBinContent(hid,i) );
79
        fclose(fp);
93
        fclose(fp);
80
        printf("Histogram %d exported to %s\n", hid, filename);
94
        printf("Histogram %d exported to %s\n", hid, filename);
Line 92... Line 106...
92
int main (int argc, char *argv[]) {
106
int main (int argc, char *argv[]) {
93
  if (InitCVIRTE (0, argv, 0) == 0)
107
  if (InitCVIRTE (0, argv, 0) == 0)
94
    return -1;  /* out of memory */
108
    return -1;  /* out of memory */
95
  if ((panelHandle = LoadPanel (0, "redpitaya_gui.uir", PANEL)) < 0)
109
  if ((panelHandle = LoadPanel (0, "redpitaya_gui.uir", PANEL)) < 0)
96
    return -1;
110
    return -1;
97
 
-
 
-
 
111
  GetPanelHandleFromTabPage (panelHandle, PANEL_TAB, 0, &settingsHandle);  
-
 
112
  GetPanelHandleFromTabPage (panelHandle, PANEL_TAB, 1, &outputHandle);  
-
 
113
  GetPanelHandleFromTabPage (panelHandle, PANEL_TAB, 2, &ch0Handle);  
-
 
114
  GetPanelHandleFromTabPage (panelHandle, PANEL_TAB, 3, &ch1Handle);  
98
 
115
 
99
  SetStdioPort (CVI_STDIO_WINDOW);
116
  SetStdioPort (CVI_STDIO_WINDOW);
100
  SetSleepPolicy(VAL_SLEEP_MORE);
117
  SetSleepPolicy(VAL_SLEEP_MORE);
101
  CmtNewThreadPool (MAX_THREADS,  &poolHandle);
118
  CmtNewThreadPool (MAX_THREADS,  &poolHandle);
102
 
119
 
Line 105... Line 122...
105
  DisplayPanel (panelHandle);
122
  DisplayPanel (panelHandle);
106
  RunUserInterface ();
123
  RunUserInterface ();
107
  DiscardPanel (panelHandle);
124
  DiscardPanel (panelHandle);
108
  CmtDiscardThreadPool (poolHandle);
125
  CmtDiscardThreadPool (poolHandle);
109
  if (chandle!=0) DisconnectFromTCPServer (chandle);
126
  if (chandle!=0) DisconnectFromTCPServer (chandle);
110
  return 0;
127
  return 0;
111
}
128
}
112
 
129
 
113
char strbuf[0xFF];
130
char strbuf[0xFF];
114
 
131
 
115
int gLog=0;
132
int gLog=0;
116
 
133
 
Line 120... Line 137...
120
  FILE *flog;
137
  FILE *flog;
121
 
138
 
122
  va_start(aptr, format);
139
  va_start(aptr, format);
123
  ret = vsprintf(strbuf, format, aptr);
140
  ret = vsprintf(strbuf, format, aptr);
124
  va_end(aptr);
141
  va_end(aptr);
125
  SetCtrlVal(panelHandle,PANEL_STDIO,strbuf);
142
  SetCtrlVal(outputHandle,OUTPUT_STDIO,strbuf);
126
 
143
 
127
  if (gLog) {
144
  if (gLog) {
128
    flog = fopen ("stdio.log", "a");
145
    flog = fopen ("stdio.log", "a");
129
    fprintf (flog, "%s", strbuf);
146
    fprintf (flog, "%s", strbuf);
130
    fclose (flog);
147
    fclose (flog);
Line 133... Line 150...
133
}
150
}
134
 
151
 
135
 
152
 
136
int CVICALLBACK SetGraphLogYCB (int panel, int control, int event,
153
int CVICALLBACK SetGraphLogYCB (int panel, int control, int event,
137
                                void *callbackData, int eventData1, int eventData2) {
154
                                void *callbackData, int eventData1, int eventData2) {
138
 
155
 
139
  int cid=0;
156
  int cid=0;
140
  int logy=0;
157
  int logy=0;
141
  switch (event) {
158
  switch (event) {
142
    case EVENT_COMMIT:
159
    case EVENT_COMMIT:
143
      GetCtrlVal(panel,control, &logy);
160
      GetCtrlVal(panel,control, &logy);
-
 
161
      if  (panel== ch0Handle){
144
      switch (control) {
162
          switch (control) {
145
        case PANEL_LOGY_1:
163
            case CH0_LOGY_1:
146
          cid = PANEL_TDC1;
164
              cid = CH0_TDC1;
147
          break;
165
              break;
148
        case PANEL_LOGY_2:
166
            case CH0_LOGY_2:
149
          cid = PANEL_ADC1;
167
              cid = CH0_ADC1;
150
          break;
168
              break;
-
 
169
 
-
 
170
          }
-
 
171
      }
-
 
172
      if (panel == ch1Handle){
-
 
173
          switch (control) {
-
 
174
 
151
        case PANEL_LOGY_3:
175
            case CH1_LOGY_3:
152
          cid = PANEL_TDC2;
176
              cid = CH1_TDC2;
153
          break;
177
              break;
154
        case PANEL_LOGY_4:
178
            case CH1_LOGY_4:
155
          cid = PANEL_ADC2;
179
              cid = CH1_ADC2;
156
          break;
180
              break;
-
 
181
          }
157
      }
182
      }
158
      if (logy) SetCtrlAttribute (panel, cid, ATTR_YMAP_MODE, VAL_LOG);
183
      if (logy) SetCtrlAttribute (panel, cid, ATTR_YMAP_MODE, VAL_LOG);
159
      else    SetCtrlAttribute (panel, cid, ATTR_YMAP_MODE, VAL_LINEAR);
184
      else    SetCtrlAttribute (panel, cid, ATTR_YMAP_MODE, VAL_LINEAR);
160
      break;
185
      break;
161
  }
186
  }
162
  return 0;
187
  return 0;
163
}
188
}
164
 
189
 
165
int CVICALLBACK SetGraphPropertiesCB (int panel, int control, int event,
190
int CVICALLBACK SetGraphPropertiesCB (int panel, int control, int event,
166
                                      void *callbackData, int eventData1, int eventData2) {
191
                                      void *callbackData, int eventData1, int eventData2) {
167
 
192
 
168
  float min, max;
193
  float min, max;
169
  int autoscale;
194
  int autoscale;
-
 
195
     
170
  switch (event) {
196
  switch (event) {
171
    case EVENT_COMMIT:
197
    case EVENT_COMMIT:
172
      GetCtrlVal(panelHandle,PANEL_MINX_5, &min);
198
      GetCtrlVal(panelHandle,PANEL_MINX_5, &min);
173
      GetCtrlVal(panelHandle,PANEL_MAXX_5, &max);
199
      GetCtrlVal(panelHandle,PANEL_MAXX_5, &max);
174
      GetCtrlVal(panelHandle,PANEL_AUTOY, &autoscale);
200
      GetCtrlVal(panelHandle,PANEL_AUTOY, &autoscale);
Line 184... Line 210...
184
        SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_AUTOSCALE, min, max);
210
        SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_AUTOSCALE, min, max);
185
      else
211
      else
186
        SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_MANUAL, min, max);
212
        SetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_MANUAL, min, max);
187
 
213
 
188
 
214
 
189
      GetCtrlVal(panelHandle,PANEL_MINX_7, &min);
215
      GetCtrlVal(ch0Handle,CH0_MINX_7, &min);
190
      GetCtrlVal(panelHandle,PANEL_MAXX_7, &max);
216
      GetCtrlVal(ch0Handle,CH0_MAXX_7, &max);
191
      GetCtrlVal(panelHandle,PANEL_AUTOY_2, &autoscale);
217
      GetCtrlVal(ch0Handle,CH0_AUTOY_2, &autoscale);
192
      if (autoscale)
218
      if (autoscale)
193
        SetAxisScalingMode (panelHandle, PANEL_TDC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
219
        SetAxisScalingMode (ch0Handle, CH0_TDC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
194
      else
220
      else
195
        SetAxisScalingMode (panelHandle, PANEL_TDC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
221
        SetAxisScalingMode (ch0Handle, CH0_TDC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
196
 
222
 
197
      GetCtrlVal(panelHandle,PANEL_MINX_8, &min);
223
      GetCtrlVal(ch0Handle,CH0_MINX_8, &min);
198
      GetCtrlVal(panelHandle,PANEL_MAXX_8, &max);
224
      GetCtrlVal(ch0Handle,CH0_MAXX_8, &max);
199
      GetCtrlVal(panelHandle,PANEL_AUTOY_3, &autoscale);
225
      GetCtrlVal(ch0Handle,CH0_AUTOY_3, &autoscale);
200
      if (autoscale)
226
      if (autoscale)
201
        SetAxisScalingMode (panelHandle, PANEL_ADC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
227
        SetAxisScalingMode (ch0Handle, CH0_ADC1, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
202
      else
228
      else
203
        SetAxisScalingMode (panelHandle, PANEL_ADC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
229
        SetAxisScalingMode (ch0Handle, CH0_ADC1, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
204
 
230
 
205
      GetCtrlVal(panelHandle,PANEL_MINX_9, &min);
231
      GetCtrlVal(ch1Handle,CH1_MINX_9, &min);
206
      GetCtrlVal(panelHandle,PANEL_MAXX_9, &max);
232
      GetCtrlVal(ch1Handle,CH1_MAXX_9, &max);
207
      GetCtrlVal(panelHandle,PANEL_AUTOY_4, &autoscale);
233
      GetCtrlVal(ch1Handle,CH1_AUTOY_4, &autoscale);
208
      if (autoscale)
234
      if (autoscale)
209
        SetAxisScalingMode (panelHandle, PANEL_TDC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
235
        SetAxisScalingMode (ch1Handle, CH1_TDC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
210
      else
236
      else
211
        SetAxisScalingMode (panelHandle, PANEL_TDC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
237
        SetAxisScalingMode (ch1Handle, CH1_TDC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
212
 
238
 
213
      GetCtrlVal(panelHandle,PANEL_MINX_10, &min);
239
      GetCtrlVal(ch1Handle,CH1_MINX_10, &min);
214
      GetCtrlVal(panelHandle,PANEL_MAXX_10, &max);
240
      GetCtrlVal(ch1Handle,CH1_MAXX_10, &max);
215
      GetCtrlVal(panelHandle,PANEL_AUTOY_5, &autoscale);
241
      GetCtrlVal(ch1Handle,CH1_AUTOY_5, &autoscale);
216
      if (autoscale)
242
      if (autoscale)
217
        SetAxisScalingMode (panelHandle, PANEL_ADC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
243
        SetAxisScalingMode (ch1Handle, CH1_ADC2, VAL_LEFT_YAXIS, VAL_AUTOSCALE, min, max);
218
      else
244
      else
219
        SetAxisScalingMode (panelHandle, PANEL_ADC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
245
        SetAxisScalingMode (ch1Handle, CH1_ADC2, VAL_LEFT_YAXIS, VAL_MANUAL, min, max);
220
 
246
 
221
 
247
 
222
 
248
 
223
      break;
249
      break;
224
  }
250
  }
Line 228... Line 254...
228
 
254
 
229
int histoinit() {
255
int histoinit() {
230
  int nch;
256
  int nch;
231
  float min,max;
257
  float min,max;
232
 
258
 
233
  GetCtrlVal(panelHandle,PANEL_NCH_1, &nch);
259
  GetCtrlVal(ch0Handle,CH0_NCH_1, &nch);
234
  GetCtrlVal(panelHandle,PANEL_MINX_1, &min);
260
  GetCtrlVal(ch0Handle,CH0_MINX_1, &min);
235
  GetCtrlVal(panelHandle,PANEL_MAXX_1, &max);
261
  GetCtrlVal(ch0Handle,CH0_MAXX_1, &max);
236
 
262
 
237
  H1D_Init(1, "ADC ch 1","Pulse height", nch, min, max );
263
  H1D_Init(1, "ADC ch 1","Pulse height", nch, min, max );
238
  H1D_SetTitleX(1,"ADC (V)");
264
  H1D_SetTitleX(1,"ADC (V)");
239
  H1D_SetTitleY(1,"N");
265
  H1D_SetTitleY(1,"N");
240
 
266
 
241
  GetCtrlVal(panelHandle,PANEL_NCH_2, &nch);
267
  GetCtrlVal(ch1Handle,CH1_NCH_2, &nch);
242
  GetCtrlVal(panelHandle,PANEL_MINX_2, &min);
268
  GetCtrlVal(ch1Handle,CH1_MINX_2, &min);
243
  GetCtrlVal(panelHandle,PANEL_MAXX_2, &max);
269
  GetCtrlVal(ch1Handle,CH1_MAXX_2, &max);
244
 
270
 
245
  H1D_Init(2, "ADC ch 2","Pulse height", nch, min, max );
271
  H1D_Init(2, "ADC ch 2","Pulse height", nch, min, max );
246
  H1D_SetTitleX(2,"ADC (V)");
272
  H1D_SetTitleX(2,"ADC (V)");
247
  H1D_SetTitleY(2,"N");
273
  H1D_SetTitleY(2,"N");
248
 
274
 
249
  GetCtrlVal(panelHandle,PANEL_NCH_3, &nch);
275
  GetCtrlVal(ch0Handle,CH0_NCH_3, &nch);
250
  GetCtrlVal(panelHandle,PANEL_MINX_3, &min);
276
  GetCtrlVal(ch0Handle,CH0_MINX_3, &min);
251
  GetCtrlVal(panelHandle,PANEL_MAXX_3, &max);
277
  GetCtrlVal(ch0Handle,CH0_MAXX_3, &max);
252
 
278
 
253
  H1D_Init(3, "TDC ch 1","TDC", nch, min, max  );
279
  H1D_Init(3, "TDC ch 1","TDC", nch, min, max  );
254
  H1D_SetTitleX(3,"TDC (us)");
280
  H1D_SetTitleX(3,"TDC (us)");
255
  H1D_SetTitleY(3,"N");
281
  H1D_SetTitleY(3,"N");
256
 
282
 
257
  GetCtrlVal(panelHandle,PANEL_NCH_4, &nch);
283
  GetCtrlVal(ch1Handle,CH1_NCH_4, &nch);
258
  GetCtrlVal(panelHandle,PANEL_MINX_4, &min);
284
  GetCtrlVal(ch1Handle,CH1_MINX_4, &min);
259
  GetCtrlVal(panelHandle,PANEL_MAXX_4, &max);
285
  GetCtrlVal(ch1Handle,CH1_MAXX_4, &max);
260
 
286
 
261
  H1D_Init(4, "TDC ch 2","TDC", nch, min, max   );
287
  H1D_Init(4, "TDC ch 2","TDC", nch, min, max   );
262
  H1D_SetTitleX(4,"TDC (us)");
288
  H1D_SetTitleX(4,"TDC (us)");
263
  H1D_SetTitleY(4,"N");
289
  H1D_SetTitleY(4,"N");
264
 
290
 
265
  SetCtrlAttribute  (panelHandle, PANEL_ADC1, ATTR_XNAME, H1D_GetTitleX(1) );
291
  SetCtrlAttribute  (ch0Handle, CH0_ADC1, ATTR_XNAME, H1D_GetTitleX(1) );
266
  SetCtrlAttribute  (panelHandle, PANEL_ADC1, ATTR_YNAME, H1D_GetTitleY(1) );
292
  SetCtrlAttribute  (ch0Handle, CH0_ADC1, ATTR_YNAME, H1D_GetTitleY(1) );
267
  SetCtrlAttribute  (panelHandle, PANEL_ADC2, ATTR_XNAME, H1D_GetTitleX(2) );
293
  SetCtrlAttribute  (ch1Handle, CH1_ADC2, ATTR_XNAME, H1D_GetTitleX(2) );
268
  SetCtrlAttribute  (panelHandle, PANEL_ADC2, ATTR_YNAME, H1D_GetTitleY(2) );
294
  SetCtrlAttribute  (ch1Handle, CH1_ADC2, ATTR_YNAME, H1D_GetTitleY(2) );
269
 
295
 
270
  SetCtrlAttribute  (panelHandle, PANEL_TDC1, ATTR_XNAME, H1D_GetTitleX(3) );
296
  SetCtrlAttribute  (ch0Handle, CH0_TDC1, ATTR_XNAME, H1D_GetTitleX(3) );
271
  SetCtrlAttribute  (panelHandle, PANEL_TDC1, ATTR_YNAME, H1D_GetTitleY(3) );
297
  SetCtrlAttribute  (ch0Handle, CH0_TDC1, ATTR_YNAME, H1D_GetTitleY(3) );
272
  SetCtrlAttribute  (panelHandle, PANEL_TDC2, ATTR_XNAME, H1D_GetTitleX(4) );
298
  SetCtrlAttribute  (ch1Handle, CH1_TDC2, ATTR_XNAME, H1D_GetTitleX(4) );
273
  SetCtrlAttribute  (panelHandle, PANEL_TDC2, ATTR_YNAME, H1D_GetTitleY(4) );
299
  SetCtrlAttribute  (ch1Handle, CH1_TDC2, ATTR_YNAME, H1D_GetTitleY(4) );
274
  SetGraphLogYCB( panelHandle, PANEL_LOGY_1,  EVENT_COMMIT,NULL,0,0);
300
  SetGraphLogYCB( ch0Handle, CH0_LOGY_1,  EVENT_COMMIT,NULL,0,0);
275
  SetGraphLogYCB( panelHandle, PANEL_LOGY_2,  EVENT_COMMIT,NULL,0,0);
301
  SetGraphLogYCB( ch0Handle, CH0_LOGY_2,  EVENT_COMMIT,NULL,0,0);
276
  SetGraphLogYCB( panelHandle, PANEL_LOGY_3,  EVENT_COMMIT,NULL,0,0);
302
  SetGraphLogYCB( ch1Handle, CH1_LOGY_3,  EVENT_COMMIT,NULL,0,0);
277
  SetGraphLogYCB( panelHandle, PANEL_LOGY_4,  EVENT_COMMIT,NULL,0,0);
303
  SetGraphLogYCB( ch1Handle, CH1_LOGY_4,  EVENT_COMMIT,NULL,0,0);
278
 
304
 
279
  SetGraphPropertiesCB( panelHandle, PANEL, EVENT_COMMIT,NULL,0,0);
305
  SetGraphPropertiesCB( panelHandle, PANEL, EVENT_COMMIT,NULL,0,0);
280
 
306
 
281
  SetCtrlAttribute  (panelHandle, PANEL_GRAPH, ATTR_LABEL_TEXT , "sampling adc data");
307
  SetCtrlAttribute  (panelHandle, PANEL_GRAPH, ATTR_LABEL_TEXT , "sampling adc data");
282
  SetCtrlAttribute  (panelHandle, PANEL_GRAPH, ATTR_XNAME, "t(us)" );
308
  SetCtrlAttribute  (panelHandle, PANEL_GRAPH, ATTR_XNAME, "t(us)" );
283
  SetCtrlAttribute  (panelHandle, PANEL_GRAPH, ATTR_YNAME, "U(V)" );
309
  SetCtrlAttribute  (panelHandle, PANEL_GRAPH, ATTR_YNAME, "U(V)" );
284
 
310
 
285
  GetCtrlVal(panelHandle,PANEL_TWIN0, &twin0);
311
  GetCtrlVal(settingsHandle,SETTINGS_TWIN0, &twin0);
286
  GetCtrlVal(panelHandle,PANEL_TWIN1, &twin1);
312
  GetCtrlVal(settingsHandle,SETTINGS_TWIN1, &twin1);
287
  GetCtrlVal(panelHandle,PANEL_ADCTYPE, &adctype);
313
  GetCtrlVal(panelHandle,PANEL_ADCTYPE, &adctype);
288
  GetCtrlVal(panelHandle,PANEL_ITRGLEVEL  , &athreshold);
314
  GetCtrlVal(settingsHandle,SETTINGS_ITRGLEVEL  , &athreshold);
289
  return 0;
315
  return 0;
290
}
316
}
291
 
317
 
292
int analyse(int nb, unsigned char *cdata, int *info, int *ninfo) {
318
int analyse(int nb, unsigned char *cdata, int *info, int *ninfo) {
293
 
319
 
Line 302... Line 328...
302
  *ninfo = 0;
328
  *ninfo = 0;
303
  printf("Run HDR LEN=%d NEVE=%d dt=%f adc=%f qdc=%f\n", ibuf[0],ibuf[1],fbuf[2],adc,qdc);
329
  printf("Run HDR LEN=%d NEVE=%d dt=%f adc=%f qdc=%f\n", ibuf[0],ibuf[1],fbuf[2],adc,qdc);
304
  daqtime += fbuf[2];
330
  daqtime += fbuf[2];
305
 
331
 
306
  SetCtrlVal(panelHandle, PANEL_CDAQTIME,daqtime);
332
  SetCtrlVal(panelHandle, PANEL_CDAQTIME,daqtime);
-
 
333
  float ctime = Timer() -starttime;
307
  SetCtrlVal(panelHandle, PANEL_CTIME, Timer() -starttime);
334
  SetCtrlVal(panelHandle, PANEL_CTIME, ctime);
-
 
335
  if (ctime>0)SetCtrlVal(panelHandle, PANEL_DAQEFF, daqtime/ctime);
308
  daqtime  =0;
336
  //daqtime  =0;
309
  while (nr<nb) {
337
  while (nr<nb) {
310
 
338
 
311
    int recid   = *data++;
339
    int recid   = *data++;
312
    int chmask  = *data++;
340
    int chmask  = *data++;
313
    nr +=8;
341
    nr +=8;
Line 332... Line 360...
332
      if ( nsamples>0  && neve % pfreq == 0) {
360
      if ( nsamples>0  && neve % pfreq == 0) {
333
        const int col[4]= {VAL_RED,VAL_GREEN,VAL_BLUE,VAL_WHITE};
361
        const int col[4]= {VAL_RED,VAL_GREEN,VAL_BLUE,VAL_WHITE};
334
        if (plothandle[id]) DeleteGraphPlot (panelHandle, PANEL_GRAPH, plothandle[id], VAL_IMMEDIATE_DRAW);
362
        if (plothandle[id]) DeleteGraphPlot (panelHandle, PANEL_GRAPH, plothandle[id], VAL_IMMEDIATE_DRAW);
335
 
363
 
336
        plothandle[id] = PlotXY (panelHandle, PANEL_GRAPH, timebins, fdata, nsamples, VAL_FLOAT, VAL_FLOAT, VAL_FAT_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[id]);
364
        plothandle[id] = PlotXY (panelHandle, PANEL_GRAPH, timebins, fdata, nsamples, VAL_FLOAT, VAL_FLOAT, VAL_FAT_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[id]);
337
 
365
 
338
        H1D_Draw(1,panelHandle,PANEL_ADC1,&adcplothandle[0]);
366
        H1D_Draw(1, ch0Handle,CH0_ADC1,&adcplothandle[0]);
339
        H1D_Draw(2,panelHandle,PANEL_ADC2,&adcplothandle[1]);
367
        H1D_Draw(2, ch1Handle,CH1_ADC2,&adcplothandle[1]);
340
        H1D_Draw(3,panelHandle,PANEL_TDC1,&tdcplothandle[0]);
368
        H1D_Draw(3, ch0Handle,CH0_TDC1,&tdcplothandle[0]);
341
        H1D_Draw(4,panelHandle,PANEL_TDC2,&tdcplothandle[1]);
369
        H1D_Draw(4, ch1Handle,CH1_TDC2,&tdcplothandle[1]);
342
 
370
 
343
        if (debug) for (int k=0; k<10; k++) printf("%d %d (%f , %d)\n", id,k, timebins[k],data[k]);
371
        if (debug) for (int k=0; k<10; k++) printf("%d %d (%f , %d)\n", id,k, timebins[k],data[k]);
344
      }
372
      }
345
 
373
 
346
      nr+=8;
374
      nr+=8;
347
      adc=10000;
375
      adc=10000;
Line 431... Line 459...
431
          printf("%s\n",data);
459
          printf("%s\n",data);
432
          break;
460
          break;
433
        case 1:// read
461
        case 1:// read
434
 
462
 
435
          GetCtrlVal(panelHandle,PANEL_CEVE     , &event);
463
          GetCtrlVal(panelHandle,PANEL_CEVE     , &event);
436
          GetCtrlVal(panelHandle,PANEL_NTOTAL   , &ncalls);
464
          GetCtrlVal(settingsHandle,SETTINGS_NTOTAL   , &ncalls);
437
 
465
 
438
          event += analyse(nb,data, evinfo, &ninfo);
466
          event += analyse(nb,data, evinfo, &ninfo);
439
          if (foutput) {
467
          if (foutput) {
440
            if (outwaveforms) fwrite(data, 1, nb, foutput);
468
            if (outwaveforms) fwrite(data, 1, nb, foutput);
441
            fwrite(evinfo, 1, ninfo*sizeof(int), foutput);
469
            fwrite(evinfo, 1, ninfo*sizeof(int), foutput);
Line 482... Line 510...
482
}
510
}
483
 
511
 
484
int CVICALLBACK StartCB (int panel, int control, int event,
512
int CVICALLBACK StartCB (int panel, int control, int event,
485
                         void *callbackData, int eventData1, int eventData2) {
513
                         void *callbackData, int eventData1, int eventData2) {
486
  char ip[0xFF];
514
  char ip[0xFF];
-
 
515
  char path[0xFF];
487
  int hdr[0xFF];
516
  int hdr[0xFF];
488
  char filename[0xFF];
517
  char filename[0xFF];
-
 
518
  char filepath[0xFF];  
489
  unsigned short *sbuff = (unsigned short *)&hdr[5] ;
519
  unsigned short *sbuff = (unsigned short *)&hdr[5] ;
490
  unsigned char  *cbuff = (unsigned char *)&sbuff[3] ;
520
  unsigned char  *cbuff = (unsigned char *)&sbuff[3] ;
491
  int imask[2];
521
  int imask[2];
492
  unsigned char mask;
522
  unsigned char mask;
493
  unsigned char trigger;
523
  unsigned char trigger;
Line 496... Line 526...
496
  int nbefore;
526
  int nbefore;
497
  unsigned int decimation;
527
  unsigned int decimation;
498
  unsigned short neve;
528
  unsigned short neve;
499
  int output;
529
  int output;
500
  switch (event) {
530
  switch (event) {
501
    case EVENT_COMMIT: {
531
    case EVENT_COMMIT: {                                                                                              
502
      GetCtrlVal(panel,PANEL_IP, ip);
532
      GetCtrlVal(settingsHandle,SETTINGS_IP, ip);
503
      GetCtrlVal(panel,PANEL_TRIGGER, &trigger);
533
      GetCtrlVal(settingsHandle,SETTINGS_TRIGGER, &trigger);
504
      GetCtrlVal(panel,PANEL_SAMPLES, &nsamples);
534
      GetCtrlVal(settingsHandle,SETTINGS_SAMPLES, &nsamples);
505
      GetCtrlVal(panel,PANEL_DECIMATION,&decimation);
535
      GetCtrlVal(settingsHandle,SETTINGS_DECIMATION,&decimation);
506
      GetCtrlVal(panel,PANEL_NEVE   , &neve);
536
      GetCtrlVal(settingsHandle,SETTINGS_NEVE   , &neve);
507
      GetCtrlVal(panel,PANEL_CH0    , &imask[0] );
537
      GetCtrlVal(settingsHandle,SETTINGS_CH0    , &imask[0] );
508
      GetCtrlVal(panel,PANEL_CH1    , &imask[1]  );
538
      GetCtrlVal(settingsHandle,SETTINGS_CH1    , &imask[1]  );
509
      GetCtrlVal(panel,PANEL_PFREQ  , &pfreq);
539
      GetCtrlVal(settingsHandle,SETTINGS_PFREQ  , &pfreq);
510
      GetCtrlVal(panel,PANEL_DEBUG  , &debug);
540
      GetCtrlVal(settingsHandle,SETTINGS_DEBUG  , &debug);
511
      GetCtrlVal(panel,PANEL_NBEFORE  , &nbefore);
541
      GetCtrlVal(settingsHandle,SETTINGS_NBEFORE  , &nbefore);
512
      GetCtrlVal(panel,PANEL_ENABLEDOUTPUT, &output);
542
      GetCtrlVal(settingsHandle,SETTINGS_ENABLEDOUTPUT, &output);
513
      GetCtrlVal(panel,PANEL_OUTWAVE, &outwaveforms);
543
      GetCtrlVal(panel,PANEL_OUTWAVE, &outwaveforms);
514
      GetCtrlVal(panel,PANEL_FILENAME, filename);
544
      GetCtrlVal(settingsHandle,SETTINGS_FILENAME, filename);
515
 
-
 
-
 
545
      sprintf(path, "%s\\Desktop\\data", getenv("USERPROFILE"));
-
 
546
      MakeDir (path);
-
 
547
      sprintf(filepath,"%s\\%s", path, filename);
516
      delay= MINTRGDELAY + nsamples - nbefore + 1;
548
      delay= MINTRGDELAY + nsamples - nbefore + 1;
517
 
549
 
518
      mask = 0;
550
      mask = 0;
519
      for (int i=0; i<2; i++) {
551
      for (int i=0; i<2; i++) {
520
        if (imask[i]) mask |= (1<<i);
552
        if (imask[i]) mask |= (1<<i);
521
      }
553
      }
522
 
554
 
523
      double level =0;
555
      double level =0;
524
      GetCtrlVal(panel,PANEL_TRGLEVEL , &level);
556
      GetCtrlVal(settingsHandle,SETTINGS_TRGLEVEL , &level);
525
 
557
 
526
 
558
 
527
      switch (control) {
559
      switch (control) {
528
        case PANEL_CONNECT: {
560
        case PANEL_CONNECT: {
529
          int state;
561
          int state;
Line 537... Line 569...
537
        }
569
        }
538
        break;
570
        break;
539
        case PANEL_START: {
571
        case PANEL_START: {
540
          int state;
572
          int state;
541
          GetCtrlVal(panel,PANEL_START, &state);
573
          GetCtrlVal(panel,PANEL_START, &state);
542
          GetCtrlVal(panel,PANEL_EXCLUDE_1, &excludefirst[0]);
574
          GetCtrlVal(ch0Handle,CH0_EXCLUDE_1, &excludefirst[0]);
543
          GetCtrlVal(panel,PANEL_EXCLUDE_2, &excludefirst[1]);
575
          GetCtrlVal(ch1Handle,CH1_EXCLUDE_2, &excludefirst[1]);
-
 
576
         
544
          if (state && eventData1==0) {
577
          if (state && eventData1==0) {
545
            histoinit();
578
            histoinit();
546
            starttime=Timer();
579
            starttime=Timer();
547
            daqtime  =0;
580
            daqtime  =0;
548
            /* decimation n (=1,8,64...) : frequency = 125/n MHz*/
581
            /* decimation n (=1,8,64...) : frequency = 125/n MHz*/
549
            for (int i=0; i<nsamples; i++) timebins[i]=(i-nbefore)* (float)decimation /125.;
582
            for (int i=0; i<nsamples; i++) timebins[i]=(i-nbefore)* (float)decimation /125.;
550
            if (output) foutput = fopen(filename, "wb");
583
            if (output) foutput = fopen(filepath, "wb");
551
            printf("decimation %d\n", decimation);
584
            printf("decimation %d\n", decimation);
552
            SetCtrlVal(panel,PANEL_CEVE  , 0);
585
            SetCtrlVal(panel,PANEL_CEVE  , 0);
553
            ctrl_c=0;
586
            ctrl_c=0;
554
            hdr[0] = 0;
587
            hdr[0] = 0;
555
            hdr[1] = 7*sizeof(int);
588
            hdr[1] = 7*sizeof(int);
Line 604... Line 637...
604
int CVICALLBACK ExportCB (int panel, int control, int event,
637
int CVICALLBACK ExportCB (int panel, int control, int event,
605
                          void *callbackData, int eventData1, int eventData2) {
638
                          void *callbackData, int eventData1, int eventData2) {
606
  int hid=0;
639
  int hid=0;
607
  switch (event) {
640
  switch (event) {
608
    case EVENT_COMMIT:
641
    case EVENT_COMMIT:
609
      switch (control) {
-
 
610
        case PANEL_EXPORT_1:
-
 
611
          hid=1;
-
 
612
          break;
-
 
613
        case PANEL_EXPORT_2:
642
      if  (panel== ch0Handle){
614
          hid=2;
-
 
615
          break;
-
 
616
        case PANEL_EXPORT_3:
643
          switch (control) {
617
          hid=3;
-
 
618
          break;
-
 
619
        case PANEL_EXPORT_4:
644
            case CH0_EXPORT_1:
620
          hid=4;
645
              hid=1;
621
          break;
646
              break;
622
 
647
 
-
 
648
            case CH0_EXPORT_3:
-
 
649
              hid=3;
-
 
650
              break;
-
 
651
 
-
 
652
 
-
 
653
          }
-
 
654
      }  
-
 
655
      if  (panel== ch1Handle){  
-
 
656
          switch (control) {
-
 
657
 
-
 
658
            case CH1_EXPORT_2:
-
 
659
              hid=2;
-
 
660
              break;
-
 
661
 
-
 
662
            case CH1_EXPORT_4:
-
 
663
              hid=4;
-
 
664
              break;
-
 
665
 
-
 
666
          }
623
      }
667
      }
624
      export_data(hid);
668
      export_data(hid);
625
      break;
669
      break;
626
  }
670
  }
627
  return 0;
671
  return 0;