Rev 265 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 265 | Rev 317 | ||
|---|---|---|---|
| Line -... | Line 1... | ||
| - | 1 | #include <tcpsupp.h> |
|
| 1 | #include "H1D.h" |
2 | #include "H1D.h" |
| 2 | #include "H2D.h" |
3 | #include "H2D.h" |
| 3 | #include <formatio.h> |
4 | #include <formatio.h> |
| 4 | #include <utility.h> |
5 | #include <utility.h> |
| 5 | #include <ansi_c.h> |
6 | #include <ansi_c.h> |
| 6 | #include <cvirte.h> |
7 | #include <cvirte.h> |
| 7 | #include <userint.h> |
8 | #include <userint.h> |
| 8 | #include "drs4.h" |
9 | #include "drs4.h" |
| - | 10 | #include "scaler.h" |
|
| 9 | #include "drsread.h" |
11 | #include "drsread.h" |
| - | 12 | #include "K6517.h" |
|
| 10 | 13 | ||
| - | 14 | K6517STATUS K6517Stat; |
|
| - | 15 | static int K6517_Interface,K6517_Port,K6517_Gdev; |
|
| 11 |
|
16 | //#define MIKRO |
| 12 | 17 | ||
| 13 | #ifdef MIKRO |
18 | #ifdef MIKRO |
| 14 | #include "MIKRO.h" |
19 | #include "MIKRO.h" |
| 15 | #endif |
20 | #endif |
| 16 | 21 | ||
| - | 22 | ||
| - | 23 | /*---------------------------------------------------------------------------*/ |
|
| - | 24 | /* Module-globals */ |
|
| - | 25 | /*---------------------------------------------------------------------------*/ |
|
| - | 26 | static unsigned int g_hconversation; |
|
| - | 27 | static int g_hmainPanel; |
|
| - | 28 | static int g_connected = 0; |
|
| - | 29 | static int g_TCPError = 0; |
|
| - | 30 | ||
| - | 31 | ||
| 17 |
|
32 | int daq_on; |
| - | 33 | int ph, p2,p3,p4, plothandle[4]= {0,0,0,0}; |
|
| 18 | static int |
34 | static int qdcplothandle[4]= {0,0,0,0}; |
| 19 | static int scanplothandle; |
35 | static int scanplothandle; |
| 20 | static int tfID; |
36 | static int tfID; |
| - | 37 | static int rID; |
|
| 21 | static int controlID; |
38 | static int controlID; |
| 22 | 39 | ||
| 23 | #define MAX_THREADS 10 |
40 | #define MAX_THREADS 10 |
| 24 | 41 | ||
| 25 | static CmtThreadPoolHandle poolHandle = 0; |
42 | static CmtThreadPoolHandle poolHandle = 0; |
| 26 | 43 | ||
| 27 | static float gSum[4]={0,0,0,0}; |
44 | static float gSum[4]={0,0,0,0}; |
| - | 45 | ||
| - | 46 | ||
| - | 47 | int gActive[4]= {0,0,0,0}; |
|
| - | 48 | double gTwinMin[4]= {0,0,0,0}; |
|
| - | 49 | double gTwinMax[4]= {0,0,0,0}; |
|
| - | 50 | double gFx[4]= {0,0,0,0}; |
|
| - | 51 | ||
| 28 | int main (int argc, char *argv[]) { |
52 | int main (int argc, char *argv[]) { |
| 29 | short port; |
53 | short port; |
| 30 | if (InitCVIRTE (0, argv, 0) == 0) |
54 | if (InitCVIRTE (0, argv, 0) == 0) |
| 31 | return -1; /* out of memory */ |
55 | return -1; /* out of memory */ |
| 32 | if ((ph = LoadPanel (0, "drs4.uir", PANEL)) < 0) |
56 | if ((ph = LoadPanel (0, "drs4.uir", PANEL)) < 0) |
| 33 | return -1; |
57 | return -1; |
| 34 | if ((p2 = LoadPanel (0, "drs4.uir", SCAN)) < 0) |
58 | if ((p2 = LoadPanel (0, "drs4.uir", SCAN)) < 0) |
| 35 | return -1; |
59 | return -1; |
| - | 60 | if ((p3 = LoadPanel (0, "drs4.uir", QDC)) < 0) |
|
| - | 61 | return -1; |
|
| - | 62 | if ((p4 = LoadPanel (0, "scaler.uir", SCALER)) < 0) |
|
| - | 63 | return -1; |
|
| - | 64 | ||
| - | 65 | DisableBreakOnLibraryErrors(); |
|
| 36 | SetStdioPort (CVI_STDIO_WINDOW); |
66 | SetStdioPort (CVI_STDIO_WINDOW); |
| 37 | SetSleepPolicy(VAL_SLEEP_MORE); |
67 | SetSleepPolicy(VAL_SLEEP_MORE); |
| 38 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
68 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
| 39 | 69 | ||
| 40 | DisplayPanel (ph); |
70 | DisplayPanel (ph); |
| 41 | DisplayPanel (p2); |
71 | DisplayPanel (p2); |
| - | 72 | DisplayPanel (p3); |
|
| 42 | 73 | DisplayPanel (p4); |
|
| 43 | #ifdef MIKRO |
74 | #ifdef MIKRO |
| 44 | GetCtrlVal(p2, SCAN_PORT, &port); |
75 | GetCtrlVal(p2, SCAN_PORT, &port); |
| 45 | if (MIKRO_Open (port)) MessagePopup ("Error", "Mikro Port Not found !\n Change in the GUI") ; |
76 | if (MIKRO_Open (port)) MessagePopup ("Error", "Mikro Port Not found !\n Change in the GUI") ; |
| 46 | MIKRO_Init(1,0); |
77 | MIKRO_Init(1,0); |
| 47 | MIKRO_Init(2,0); |
78 | MIKRO_Init(2,0); |
| 48 | #endif |
79 | #endif |
| - | 80 | ||
| - | 81 | K6517_open (1,4,3,0,13); |
|
| 49 | 82 | ||
| 50 | RunUserInterface (); |
83 | RunUserInterface (); |
| 51 | DiscardPanel (ph); |
84 | DiscardPanel (ph); |
| 52 | DiscardPanel (p2); |
85 | DiscardPanel (p2); |
| - | 86 | DiscardPanel (p3); |
|
| - | 87 | DiscardPanel (p4); |
|
| 53 | CmtDiscardThreadPool (poolHandle); |
88 | CmtDiscardThreadPool (poolHandle); |
| - | 89 | #ifdef MIKRO |
|
| 54 | MIKRO_Close (); |
90 | MIKRO_Close (); |
| - | 91 | #endif |
|
| 55 | return 0; |
92 | return 0; |
| 56 | } |
93 | } |
| 57 | 94 | ||
| 58 | 95 | ||
| 59 | char strbuf[0xFF]; |
96 | char strbuf[0xFF]; |
| Line 90... | Line 127... | ||
| 90 | DRSSetTimeout(); |
127 | DRSSetTimeout(); |
| 91 | } |
128 | } |
| 92 | 129 | ||
| 93 | 130 | ||
| 94 | 131 | ||
| - | 132 | void CVICALLBACK EndOfThresholdScanThread ( CmtThreadPoolHandle poolhandle, |
|
| - | 133 | CmtThreadFunctionID functionID, unsigned int event, |
|
| - | 134 | int value, void *callbackData ) { |
|
| - | 135 | printf("End of Threshold Scan Thread \n"); |
|
| - | 136 | return ; |
|
| - | 137 | ||
| - | 138 | } |
|
| 95 | 139 | ||
| 96 | void CVICALLBACK EndOfThread ( CmtThreadPoolHandle poolhandle, |
140 | void CVICALLBACK EndOfThread ( CmtThreadPoolHandle poolhandle, |
| 97 | CmtThreadFunctionID functionID, unsigned int event, |
141 | CmtThreadFunctionID functionID, unsigned int event, |
| 98 | int value, void *callbackData ) { |
142 | int value, void *callbackData ) { |
| 99 | 143 | ||
| Line 104... | Line 148... | ||
| 104 | 148 | ||
| 105 | } |
149 | } |
| 106 | 150 | ||
| 107 | 151 | ||
| 108 | static float xs[4][1024]; |
152 | static float xs[4][1024]; |
| - | 153 | ||
| 109 | int CVICALLBACK daq(void *functionData) { |
154 | int CVICALLBACK daq(void *functionData) { |
| 110 | 155 | ||
| 111 | 156 | ||
| 112 | int neve; |
157 | int neve; |
| 113 | char filename[0xff]; |
158 | char filename[0xff]; |
| 114 | int imask[4]; |
159 | int imask[4]; |
| Line 124... | Line 169... | ||
| 124 | int pfreq; |
169 | int pfreq; |
| 125 | int enabledoutput; |
170 | int enabledoutput; |
| 126 | int neveold = 0; |
171 | int neveold = 0; |
| 127 | double rate; |
172 | double rate; |
| 128 | int *args = (int *) functionData; |
173 | int *args = (int *) functionData; |
| 129 | double twin[2]; |
- | |
| 130 | 174 | ||
| 131 | 175 | int wfm=0; |
|
| - | 176 | const int init[4] = { QDC_INIT_1 ,QDC_INIT_2 ,QDC_INIT_3 ,QDC_INIT_4 }; |
|
| - | 177 | const int fx[4] = { PANEL_SCALE_1 ,PANEL_SCALE_2 ,PANEL_SCALE_3 ,PANEL_SCALE_4 }; |
|
| - | 178 | const int active[4] = { QDC_ACTIVE_1 ,QDC_ACTIVE_2 ,QDC_ACTIVE_3 ,QDC_ACTIVE_4 }; |
|
| 132 | 179 | ||
| 133 | GetCtrlVal(ph, PANEL_CH0, &imask[0] ); |
180 | GetCtrlVal(ph, PANEL_CH0, &imask[0] ); |
| 134 | GetCtrlVal(ph, PANEL_CH1, &imask[1] ); |
181 | GetCtrlVal(ph, PANEL_CH1, &imask[1] ); |
| 135 | GetCtrlVal(ph, PANEL_CH2, &imask[2] ); |
182 | GetCtrlVal(ph, PANEL_CH2, &imask[2] ); |
| 136 | GetCtrlVal(ph, PANEL_CH3, &imask[3] ); |
183 | GetCtrlVal(ph, PANEL_CH3, &imask[3] ); |
| - | 184 | GetCtrlVal(p3, QDC_WFM, &wfm ); |
|
| 137 | mask = 0; |
185 | mask = 0; |
| 138 | for (int i=0; i<4; i++) { |
186 | for (int i=0; i<4; i++) { |
| - | 187 | if (imask[i]) { |
|
| 139 |
|
188 | mask |= (1<<i); |
| - | 189 | ScaleCB(ph,fx[i],EVENT_COMMIT,NULL, 0,0); |
|
| - | 190 | SetActiveCB(p3,active[i],EVENT_COMMIT,NULL, 0,0); |
|
| - | 191 | InitQdcHistogramCB(p3, init[i],EVENT_COMMIT,NULL, 0,0); |
|
| - | 192 | } |
|
| 140 | } |
193 | } |
| 141 | - | ||
| - | 194 | LogScaleCB(p3, QDC_LOGY,EVENT_COMMIT,NULL, 0,0); |
|
| 142 | 195 | ||
| 143 | 196 | ||
| 144 | GetCtrlVal(ph,PANEL_NEVE, &neve); |
197 | GetCtrlVal(ph,PANEL_NEVE, &neve); |
| 145 | GetCtrlVal(ph,PANEL_DEBUG, &verbose); |
198 | GetCtrlVal(ph,PANEL_DEBUG, &verbose); |
| 146 | GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
199 | GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
| 147 | GetCtrlVal(ph,PANEL_ENABLEDOUTPUT, &enabledoutput); |
200 | GetCtrlVal(ph,PANEL_ENABLEDOUTPUT, &enabledoutput); |
| 148 | 201 | ||
| 149 | GetCtrlVal(ph,PANEL_FREQUENCY, &frequency); |
202 | GetCtrlVal(ph,PANEL_FREQUENCY, &frequency); |
| 150 | GetCtrlVal(ph,PANEL_TRGDELAY, &trgdelay); |
203 | GetCtrlVal(ph,PANEL_TRGDELAY, &trgdelay); |
| 151 | GetCtrlVal(ph,PANEL_TRGCHANNEL, &trgchannel); |
204 | GetCtrlVal(ph,PANEL_TRGCHANNEL, &trgchannel); |
| 152 | 205 | ||
| 153 | 206 | ||
| 154 | GetCtrlVal(ph,PANEL_TRGTYPE, &trgtype); |
207 | GetCtrlVal(ph,PANEL_TRGTYPE, &trgtype); |
| 155 | GetCtrlVal(ph,PANEL_TRGLEVEL, &trglevel); |
208 | GetCtrlVal(ph,PANEL_TRGLEVEL, &trglevel); |
| 156 | GetCtrlVal(ph,PANEL_TRGPOLARITY, &trgpolarity); |
209 | GetCtrlVal(ph,PANEL_TRGPOLARITY, &trgpolarity); |
| 157 | GetCtrlVal(ph,PANEL_RANGE, &range); |
210 | GetCtrlVal(ph,PANEL_RANGE, &range); |
| 158 | 211 | ||
| 159 | GetCtrlVal(ph,PANEL_TWIN0, &twin[0]); |
- | |
| 160 | GetCtrlVal(ph,PANEL_TWIN1, &twin[1]); |
- | |
| - | 212 | ||
| 161 | //printf("mask=0x%x\n",mask); |
213 | //printf("mask=0x%x\n",mask); |
| 162 | 214 | ||
| 163 | DRSSetMask( (unsigned char)( mask & 0xF ) ); |
215 | DRSSetMask( (unsigned char)( mask & 0xF ) ); |
| 164 | 216 | ||
| 165 | DRSSetFrequency( frequency ); |
217 | DRSSetFrequency( frequency ); |
| 166 | DRSSetTriggerDelay(trgdelay ); |
218 | DRSSetTriggerDelay(trgdelay ); |
| 167 | DRSSetTriggerChannel(trgchannel ); |
219 | DRSSetTriggerChannel(trgchannel ); |
| 168 | DRSSetTriggerType( trgtype ); |
220 | DRSSetTriggerType( trgtype ); |
| 169 | DRSSetTriggerLevel(trglevel); |
221 | DRSSetTriggerLevel(trglevel); |
| 170 | DRSSetTriggerPolarity(trgpolarity); |
222 | DRSSetTriggerPolarity(trgpolarity); |
| 171 | 223 | ||
| 172 | DRSSetRange ( range ); |
224 | DRSSetRange ( range ); |
| 173 | 225 | ||
| 174 | 226 | ||
| 175 | 227 | ||
| 176 | FILE *fp= NULL; |
228 | FILE *fp= NULL; |
| 177 | 229 | ||
| 178 | if (enabledoutput) { |
230 | if (enabledoutput) { |
| 179 | if ( |
231 | if (1==1) { |
| 180 | GetCtrlVal(ph, PANEL_FILENAME, filename ); |
232 | GetCtrlVal(ph, PANEL_FILENAME, filename ); |
| - | 233 | printf("%s\n", filename); |
|
| 181 | fp = fopen(filename,"wb"); |
234 | fp = fopen(filename,"wb"); |
| 182 | } else { |
235 | } else { |
| 183 | GetCtrlVal(p2, SCAN_FILENAME, filename ); |
236 | GetCtrlVal(p2, SCAN_FILENAME, filename ); |
| 184 | fp = fopen(filename,"ab"); |
237 | fp = fopen(filename,"ab"); |
| - | 238 | printf("%s\n", filename); |
|
| 185 | } |
239 | } |
| 186 | } |
240 | } |
| 187 | 241 | ||
| 188 | static unsigned char *buffer; |
242 | static unsigned char *buffer; |
| 189 | 243 | ||
| 190 | int buffer_size = 0; |
244 | int buffer_size = 0; |
| 191 | const int nBoards=1; |
245 | const int nBoards=1; |
| 192 | const int waveDepth=1024; |
246 | const int waveDepth=1024; |
| 193 | 247 | ||
| 194 | if (buffer_size == 0) { |
248 | if (buffer_size == 0) { |
| Line 217... | Line 271... | ||
| 217 | if (retval) i--; |
271 | if (retval) i--; |
| 218 | nev++; |
272 | nev++; |
| 219 | if (!daq_on) break; |
273 | if (!daq_on) break; |
| 220 | time(&t); |
274 | time(&t); |
| 221 | if (t!=told ) { |
275 | if (t!=told ) { |
| - | 276 | PlotQdcHistogramCB(0,0,EVENT_COMMIT,NULL, 0,0); |
|
| 222 | rate = (i-neveold); |
277 | rate = (i-neveold); |
| 223 | printf("%d events in %2.2f min (%d s) Rate %f Hz %s ",i+1, (double)(t-tstart)/60.,(t-tstart), rate , ctime(&t)); |
278 | printf("%d events in %2.2f min (%d s) Rate %f Hz %s ",i+1, (double)(t-tstart)/60.,(t-tstart), rate , ctime(&t)); |
| 224 | GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
279 | GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
| 225 | neveold = i; |
280 | neveold = i; |
| 226 | } |
281 | } |
| 227 | told=t; |
282 | told=t; |
| 228 | // Save data |
283 | // Save data |
| - | 284 | ||
| 229 | if (nb>0 && fp) fwrite(buffer, 1,nb ,fp); |
285 | if (nb>0 && fp) fwrite(buffer, 1,nb ,fp); |
| 230 | // Plot Data |
286 | // Plot Data |
| - | 287 | ||
| 231 | for (int k=0; k<4; k++) { |
288 | for (int k=0; k<4; k++) { |
| 232 | if ( (mask & ( 0x1<<k )) ){ |
289 | if ( (mask & ( 0x1<<k )) ){ |
| - | 290 | double fSum= 0; |
|
| 233 | float *t=DRSGetTime(k); |
291 | float *t=DRSGetTime(k); |
| 234 | float *x=DRSGetWave(k); |
292 | float *x=DRSGetWave(k); |
| 235 | ; |
293 | ; |
| 236 | for (int j=0 ; j<1024 ; j++) { |
294 | for (int j=0 ; j<1024 ; j++) { |
| 237 | xs[k][j]= x[j]*1e-3; |
295 | xs[k][j]= x[j]*1e-3*gFx[k]; |
| - | 296 | if (gActive[k]){ |
|
| - | 297 | if (t[j]> gTwinMin[k] && t[j] < gTwinMax[k]) { |
|
| - | 298 | fSum+= fabs(xs[k][j]); |
|
| - | 299 | } |
|
| - | 300 | if (wfm){ |
|
| - | 301 | H2D_Fill(200+k,t[j], xs[k][j],1); |
|
| - | 302 | } |
|
| - | 303 | //if (verbose) printf("[%d] %d. x= %3.2f y=%3.2f\n", k, i, t[j], x[j] ); |
|
| - | 304 | } |
|
| - | 305 | } |
|
| - | 306 | if (verbose) printf("qdc[%d] %3.2f active=%d\n", k, fSum ,gActive[k]); |
|
| - | 307 | if (gActive[k]) { |
|
| - | 308 | if (!wfm) { |
|
| - | 309 | H1D_Fill(200+k,fSum,1.); |
|
| - | 310 | } |
|
| - | 311 | } |
|
| - | 312 | gSum[k]+=fSum; |
|
| 238 | 313 | ||
| 239 | if (t[j]> twin[0] && t[j] < twin[1]) gSum[k]+= fabs(xs[k][j]); |
- | |
| 240 | if (verbose) printf("[%d] %d. x= %3.2f y=%3.2f\n", k, i, t[j], x[j] ); |
- | |
| 241 | //h[k]->Fill( t[i], x[i]*1e-3); |
- | |
| 242 | } |
- | |
| 243 | - | ||
| 244 | if (i % pfreq == 0) { |
314 | if (i % pfreq == 0) { |
| 245 | - | ||
| 246 | const int col[4]= {VAL_WHITE,VAL_RED,VAL_GREEN,VAL_BLUE}; |
315 | const int col[4]= {VAL_WHITE,VAL_RED,VAL_GREEN,VAL_BLUE}; |
| 247 | if (plothandle[k]) DeleteGraphPlot (ph, PANEL_GRAPH, plothandle[k], VAL_IMMEDIATE_DRAW); |
316 | if (plothandle[k]) DeleteGraphPlot (ph, PANEL_GRAPH, plothandle[k], VAL_IMMEDIATE_DRAW); |
| 248 | plothandle[k] = PlotXY (ph, PANEL_GRAPH, t, xs[k], 1024, VAL_FLOAT, VAL_FLOAT, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[k]); |
317 | plothandle[k] = PlotXY (ph, PANEL_GRAPH, t, xs[k], 1024, VAL_FLOAT, VAL_FLOAT, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[k]); |
| 249 | } |
318 | } |
| 250 | } |
319 | } |
| 251 | 320 | ||
| 252 | } |
321 | } |
| 253 | 322 | ||
| 254 | 323 | ||
| 255 | } |
324 | } |
| 256 | time(&t); |
325 | time(&t); |
| 257 | printf("%d events in %2.2f min (%d s) %s",nev, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
326 | printf("%d events in %2.2f min (%d s) %s",nev, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
| 258 | DRSEnd(); |
327 | DRSEnd(); |
| 259 | } |
328 | } |
| 260 | 329 | ||
| 261 | if (fp) fclose(fp); |
330 | if (fp) fclose(fp); |
| 262 | 331 | ||
| 263 | free(buffer); |
332 | free(buffer); |
| - | 333 | ||
| - | 334 | return 0; |
|
| - | 335 | ||
| - | 336 | } |
|
| - | 337 | ||
| - | 338 | ||
| - | 339 | void CVICALLBACK EndOfThrScan ( CmtThreadPoolHandle poolhandle, |
|
| - | 340 | CmtThreadFunctionID functionID, unsigned int event, |
|
| - | 341 | int value, void *callbackData ) { |
|
| - | 342 | ||
| - | 343 | ||
| - | 344 | //SetDimming(0); |
|
| - | 345 | printf("End of thrscan \n"); |
|
| - | 346 | return ; |
|
| - | 347 | ||
| - | 348 | } |
|
| - | 349 | ||
| - | 350 | ||
| - | 351 | ||
| - | 352 | int scaler(int min, int max, int dx, int time_set, char *filename); |
|
| - | 353 | ||
| - | 354 | int CVICALLBACK thrscan(void *functionData) { |
|
| - | 355 | char str[0xFF]; |
|
| - | 356 | char path[0xFF]; |
|
| - | 357 | ||
| - | 358 | int step,min,max, mtime; |
|
| - | 359 | GetCtrlVal(p4, SCALER_STEP,&step); |
|
| - | 360 | GetCtrlVal(p4, SCALER_TIME,&mtime); |
|
| - | 361 | GetCtrlVal(p4, SCALER_MAX,&max); |
|
| - | 362 | GetCtrlVal(p4, SCALER_MIN,&min); |
|
| - | 363 | GetCtrlVal(ph, PANEL_FILENAME,path); |
|
| - | 364 | ||
| - | 365 | sprintf(str, "%s.thr", path); |
|
| - | 366 | scaler(min,max,step,mtime,str); |
|
| - | 367 | return 0; |
|
| - | 368 | ||
| - | 369 | ||
| - | 370 | } |
|
| - | 371 | ||
| - | 372 | ||
| - | 373 | int CVICALLBACK acquire_data (void *arg) { |
|
| - | 374 | ||
| - | 375 | ||
| - | 376 | char *sarg = (char *) arg; |
|
| - | 377 | printf("sarg %s\n", sarg); |
|
| - | 378 | char str[0xFF]; |
|
| - | 379 | char path[0xFF]; |
|
| - | 380 | GetCtrlVal(ph,PANEL_PATH,path); |
|
| - | 381 | sprintf(str, "%s%s.dat", path, sarg); |
|
| - | 382 | SetCtrlVal(ph, PANEL_FILENAME,str); |
|
| - | 383 | ||
| - | 384 | int flag=0; |
|
| - | 385 | ThreadFunctionPtr mythread = thrscan; |
|
| - | 386 | int data; |
|
| - | 387 | int threadhandle; |
|
| - | 388 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &data, |
|
| - | 389 | DEFAULT_THREAD_PRIORITY, |
|
| - | 390 | EndOfThresholdScanThread, |
|
| - | 391 | EVENT_TP_THREAD_FUNCTION_END, |
|
| - | 392 | NULL, RUN_IN_SCHEDULED_THREAD, |
|
| - | 393 | &threadhandle); |
|
| - | 394 | daq(&flag); |
|
| - | 395 | CmtWaitForThreadPoolFunctionCompletionEx (poolHandle, threadhandle, OPT_TP_PROCESS_EVENTS_WHILE_WAITING, CMT_WAIT_FOREVER); |
|
| - | 396 | return 0; |
|
| - | 397 | } |
|
| - | 398 | ||
| - | 399 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
|
| - | 400 | void *callbackData, int eventData1, int eventData2) |
|
| - | 401 | { |
|
| - | 402 | unsigned char state; |
|
| - | 403 | switch (event) |
|
| - | 404 | { |
|
| - | 405 | case EVENT_COMMIT: |
|
| - | 406 | GetCtrlVal(panel, control, &state); |
|
| - | 407 | K6517_vsource_operate (state); |
|
| - | 408 | break; |
|
| - | 409 | } |
|
| - | 410 | return 0; |
|
| - | 411 | } |
|
| - | 412 | ||
| - | 413 | ||
| - | 414 | int CVICALLBACK SetVoltageCB (int panel, int control, int event, |
|
| - | 415 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 416 | double vbr; |
|
| - | 417 | switch (event) { |
|
| - | 418 | case EVENT_COMMIT: |
|
| - | 419 | GetCtrlVal (ph, PANEL_VBR, &vbr ); |
|
| - | 420 | K6517_vsource_set (vbr+2); |
|
| - | 421 | break; |
|
| - | 422 | } |
|
| - | 423 | return 0; |
|
| - | 424 | } |
|
| - | 425 | ||
| - | 426 | ||
| - | 427 | ||
| - | 428 | int TScan () { |
|
| - | 429 | ||
| - | 430 | double temp; |
|
| - | 431 | double volt,vbr; |
|
| - | 432 | int n=0; |
|
| - | 433 | int led; |
|
| - | 434 | GetNumTableRows (ph, PANEL_TABLE, &n ); |
|
| - | 435 | daq_on = 1; |
|
| - | 436 | for(int i=0; i<n; i++) { |
|
| - | 437 | if (!daq_on) break; |
|
| - | 438 | GetTableCellVal (ph, PANEL_TABLE, MakePoint (1,i+1), &temp); |
|
| - | 439 | GetTableCellVal (ph, PANEL_TABLE, MakePoint (2,i+1), &vbr); |
|
| - | 440 | if (temp>100) break; |
|
| - | 441 | char transmitBuf[512]= {0}; |
|
| - | 442 | sprintf(transmitBuf, "1 %f\n", temp); |
|
| - | 443 | ||
| - | 444 | ||
| - | 445 | if (g_connected) |
|
| - | 446 | if ( ClientTCPWrite (g_hconversation, transmitBuf, strlen (transmitBuf), 1000) < 0) printf("Transmit Error\n"); else printf("%s\n", transmitBuf); |
|
| - | 447 | SetCtrlVal(ph,PANEL_LED, 0); |
|
| - | 448 | do { |
|
| - | 449 | time_t t0 = time(NULL); |
|
| - | 450 | SetCtrlVal(ph,PANEL_TIME, ctime(&t0)); |
|
| - | 451 | Delay(1); |
|
| - | 452 | GetCtrlVal(ph,PANEL_LED, &led); |
|
| - | 453 | if (led) { |
|
| - | 454 | for (int k=0;k<10;k++){ |
|
| - | 455 | Delay(1); |
|
| - | 456 | if (!daq_on) break; |
|
| - | 457 | } |
|
| - | 458 | GetCtrlVal(ph,PANEL_LED, &led); |
|
| - | 459 | } |
|
| - | 460 | if (!daq_on) break; |
|
| - | 461 | } while (!led); |
|
| - | 462 | if (!daq_on) break; |
|
| - | 463 | ||
| - | 464 | int itemp = (int) temp; |
|
| - | 465 | int n1=0; |
|
| - | 466 | GetNumTableRows (ph, PANEL_VTABLE, &n1 ); |
|
| - | 467 | ||
| - | 468 | for(int k=0; k<n1; k++) { |
|
| - | 469 | if (!daq_on) break; |
|
| - | 470 | GetTableCellVal (ph, PANEL_VTABLE, MakePoint (1,k+1), &volt); |
|
| - | 471 | if (volt<-100) break; |
|
| - | 472 | double voltage = vbr + volt; |
|
| - | 473 | int ivolt=(int)(volt*100); |
|
| - | 474 | K6517_vsource_set (voltage); |
|
| - | 475 | K6517_vsource_operate (1); |
|
| - | 476 | char str[0xFF]; |
|
| - | 477 | sprintf(str,"%d_%d", itemp, ivolt); |
|
| - | 478 | printf("%d %d %s\n",i,k, str); |
|
| - | 479 | acquire_data(str); |
|
| - | 480 | K6517_vsource_operate (0); |
|
| - | 481 | } |
|
| - | 482 | } |
|
| 264 | 483 | ||
| - | 484 | return 0; |
|
| - | 485 | } |
|
| - | 486 | ||
| - | 487 | int CVICALLBACK TScanCB (int panel, int control, int event, |
|
| - | 488 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 489 | ||
| - | 490 | switch (event) { |
|
| - | 491 | case EVENT_COMMIT:{ |
|
| - | 492 | ThreadFunctionPtr mythread = TScan; |
|
| - | 493 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID, |
|
| - | 494 | DEFAULT_THREAD_PRIORITY, |
|
| - | 495 | EndOfThread, |
|
| - | 496 | EVENT_TP_THREAD_FUNCTION_END, |
|
| - | 497 | NULL, RUN_IN_SCHEDULED_THREAD, |
|
| - | 498 | &tfID); |
|
| - | 499 | } |
|
| - | 500 | break; |
|
| - | 501 | } |
|
| - | 502 | return 0; |
|
| - | 503 | } |
|
| - | 504 | ||
| - | 505 | int CVICALLBACK LogScaleCB (int panel, int control, int event, |
|
| - | 506 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 507 | ||
| - | 508 | ||
| - | 509 | const unsigned int gr[4] = { QDC_GRAPH_1 ,QDC_GRAPH_2 ,QDC_GRAPH_3 ,QDC_GRAPH_4 }; |
|
| - | 510 | int wfm=0; |
|
| - | 511 | int attr, logy, selected; |
|
| - | 512 | switch (event) { |
|
| - | 513 | case EVENT_COMMIT: |
|
| - | 514 | GetCtrlVal(p3,QDC_WFM,&wfm); |
|
| - | 515 | GetCtrlVal(panel, control, &selected); |
|
| - | 516 | ||
| - | 517 | attr= ATTR_YMAP_MODE; |
|
| - | 518 | if(selected) logy=VAL_LOG; else logy=VAL_LINEAR; |
|
| - | 519 | if (wfm) logy=VAL_LINEAR; |
|
| - | 520 | for (int i=0;i<4;i++) SetCtrlAttribute (panel, gr[i],attr, logy); |
|
| - | 521 | break; |
|
| - | 522 | } |
|
| - | 523 | ||
| - | 524 | return 0; |
|
| - | 525 | } |
|
| - | 526 | ||
| - | 527 | int CVICALLBACK ExecRootCB (int panel, int control, int event, |
|
| - | 528 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 529 | switch (event) { |
|
| - | 530 | case EVENT_COMMIT:{ |
|
| - | 531 | char fileName[100]; |
|
| - | 532 | char fname[100]; |
|
| - | 533 | char path[100]; |
|
| - | 534 | int trgchannel; |
|
| - | 535 | GetCtrlVal(panel, PANEL_FILENAME, fileName); |
|
| - | 536 | GetCtrlVal(panel,PANEL_TRGCHANNEL, &trgchannel); |
|
| - | 537 | GetCtrlVal(panel, PANEL_PATH, path); |
|
| - | 538 | sprintf(fname, "%s/%s", path, fileName); |
|
| - | 539 | //sprintf(fname, "%s", fileName); |
|
| - | 540 | int status; |
|
| - | 541 | char name[MAX_PATHNAME_LEN]; |
|
| - | 542 | // char dfile[MAX_PATHNAME_LEN]; |
|
| - | 543 | // char efile[MAX_PATHNAME_LEN]; |
|
| - | 544 | // status = FileSelectPopup ("dat", "*.dat", ".dat", |
|
| - | 545 | // "Izberi datoteko s podatki", |
|
| - | 546 | // VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
|
| - | 547 | // EscapeString(efile,dfile); |
|
| - | 548 | sprintf(name ,"C:/home/dominik/runroot.bat \"C:/home/dominik/AnalyseWaveForms.cxx(-1,1000,\\\"%s\\\",%d)\" ", fname, trgchannel); |
|
| - | 549 | ||
| - | 550 | printf("%s\n",name); |
|
| - | 551 | LaunchExecutable(name); |
|
| - | 552 | break; |
|
| - | 553 | } |
|
| - | 554 | } |
|
| - | 555 | return 0; |
|
| - | 556 | } |
|
| - | 557 | ||
| - | 558 | ||
| - | 559 | int CVICALLBACK TempTableCB (int panel, int control, int event, |
|
| - | 560 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 561 | switch (event) { |
|
| - | 562 | case EVENT_COMMIT: { |
|
| - | 563 | int status; |
|
| - | 564 | char name[MAX_PATHNAME_LEN]; |
|
| - | 565 | char dfile[MAX_PATHNAME_LEN]; |
|
| - | 566 | char efile[MAX_PATHNAME_LEN]; |
|
| - | 567 | status = FileSelectPopup ("dat", "*.dat", ".dat", |
|
| - | 568 | "Izberi datoteko s podatki", |
|
| - | 569 | VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
|
| - | 570 | printf("%s", efile); |
|
| - | 571 | ||
| - | 572 | ||
| - | 573 | FILE *fp=fopen(efile,"r"); |
|
| - | 574 | float I; |
|
| - | 575 | float V; |
|
| - | 576 | int temp; |
|
| - | 577 | int ndim=400; |
|
| - | 578 | char line[400]; |
|
| - | 579 | if (fp) { |
|
| - | 580 | int k=0; |
|
| - | 581 | while (fgets(line,ndim,fp)!=NULL) { |
|
| - | 582 | k++; |
|
| - | 583 | sscanf(line,"%*s%d%f%f",&temp,&I,&V); |
|
| - | 584 | printf("%d %f %f\n", temp, I, V); |
|
| - | 585 | SetTableCellVal (ph, PANEL_TABLE, MakePoint (1,k), (double)temp); |
|
| - | 586 | SetTableCellVal (ph, PANEL_TABLE, MakePoint (2,k), V); |
|
| - | 587 | ||
| - | 588 | } |
|
| - | 589 | ||
| - | 590 | SetTableCellVal (ph, PANEL_TABLE, MakePoint (1,k+1), 1000.0); |
|
| - | 591 | fclose(fp); |
|
| - | 592 | ||
| - | 593 | ||
| - | 594 | } |
|
| - | 595 | break; |
|
| - | 596 | } |
|
| - | 597 | } |
|
| 265 | return 0; |
598 | return 0; |
| 266 | - | ||
| 267 | } |
599 | } |
| - | 600 | ||
| 268 | 601 | ||
| 269 | 602 | ||
| 270 | 603 | ||
| 271 | int CVICALLBACK scan(void *functionData) { |
604 | int CVICALLBACK scan(void *functionData) { |
| 272 | 605 | ||
| Line 368... | Line 701... | ||
| 368 | if (!daq_on) break; |
701 | if (!daq_on) break; |
| 369 | } |
702 | } |
| 370 | 703 | ||
| 371 | return 0; |
704 | return 0; |
| 372 | } |
705 | } |
| - | 706 | ||
| - | 707 | ||
| 373 | 708 | ||
| 374 | 709 | ||
| 375 | int CVICALLBACK StartCB (int panel, int control, int event, |
710 | int CVICALLBACK StartCB (int panel, int control, int event, |
| 376 | void *callbackData, int eventData1, int eventData2) { |
711 | void *callbackData, int eventData1, int eventData2) { |
| 377 | ThreadFunctionPtr mythread = NULL; |
712 | ThreadFunctionPtr mythread = NULL; |
| Line 383... | Line 718... | ||
| 383 | if (panel == ph && control == PANEL_START) { |
718 | if (panel == ph && control == PANEL_START) { |
| 384 | mythread = daq; |
719 | mythread = daq; |
| 385 | controlID= control; |
720 | controlID= control; |
| 386 | } |
721 | } |
| 387 | if (panel == p2 && control == SCAN_SCAN) mythread = scan; |
722 | if (panel == p2 && control == SCAN_SCAN) mythread = scan; |
| - | 723 | if (panel == p4 && control == SCALER_START) mythread = thrscan; |
|
| - | 724 | if (panel == ph && control == PANEL_ACQUIRE) { |
|
| - | 725 | mythread = acquire_data; |
|
| - | 726 | controlID=50; |
|
| - | 727 | } |
|
| - | 728 | ||
| 388 | if (mythread!=NULL) { |
729 | if (mythread!=NULL) { |
| 389 | printf("New Thread panel=%d button=%d\n", panel, control); |
730 | printf("New Thread panel=%d button=%d\n", panel, control); |
| 390 | 731 | ||
| 391 | // SetDimming(1); |
732 | // SetDimming(1); |
| 392 | 733 | ||
| Line 531... | Line 872... | ||
| 531 | #endif |
872 | #endif |
| 532 | break; |
873 | break; |
| 533 | } |
874 | } |
| 534 | return 0; |
875 | return 0; |
| 535 | } |
876 | } |
| - | 877 | ||
| - | 878 | int CVICALLBACK InitQdcHistogramCB (int panel, int control, int event, |
|
| - | 879 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 880 | const int min[4] = { QDC_MIN_1 ,QDC_MIN_2 ,QDC_MIN_3 ,QDC_MIN_4 }; |
|
| - | 881 | const int max[4] = { QDC_MAX_1 ,QDC_MAX_2 ,QDC_MAX_3 ,QDC_MAX_4 }; |
|
| - | 882 | const int nbin[4] = { QDC_NBIN_1 ,QDC_NBIN_2 ,QDC_NBIN_3 ,QDC_NBIN_4 }; |
|
| - | 883 | ||
| - | 884 | const int init[4] = { QDC_INIT_1 ,QDC_INIT_2 ,QDC_INIT_3 ,QDC_INIT_4 }; |
|
| - | 885 | char title[0xFF]; |
|
| - | 886 | char name[0xFF]; |
|
| - | 887 | switch (event) { |
|
| - | 888 | case EVENT_COMMIT:{ |
|
| - | 889 | int ctrl=-1; |
|
| - | 890 | for (int k=0;k<4;k++) if ( init[k]==control & panel==p3 ) ctrl=k; |
|
| - | 891 | if (ctrl<0) break; |
|
| - | 892 | double minx; |
|
| - | 893 | double maxx; |
|
| - | 894 | int nbins; |
|
| - | 895 | int wfm; |
|
| - | 896 | int frq; |
|
| - | 897 | GetCtrlVal(p3,min[ctrl],&minx); |
|
| - | 898 | GetCtrlVal(p3,max[ctrl],&maxx); |
|
| - | 899 | GetCtrlVal(p3,nbin[ctrl],&nbins); |
|
| - | 900 | GetCtrlVal(p3,QDC_WFM,&wfm); |
|
| - | 901 | GetCtrlVal(ph,PANEL_FREQUENCY,&frq); |
|
| - | 902 | sprintf(name,"qdc%d", ctrl); |
|
| - | 903 | sprintf(title,"QDC ch %d", ctrl); |
|
| - | 904 | H1D_Init(200+ctrl, name, title, nbins, minx,maxx); |
|
| - | 905 | sprintf(name,"avgwfm%d", ctrl); |
|
| - | 906 | sprintf(title,"Average waveform ch %d", ctrl); |
|
| - | 907 | H2D_Init(200+ctrl, name, title, 1024, 0,1024/frq, 100, -0.5,0.5); |
|
| - | 908 | break; |
|
| - | 909 | } |
|
| - | 910 | } |
|
| - | 911 | return 0; |
|
| - | 912 | ||
| - | 913 | } |
|
| - | 914 | ||
| - | 915 | ||
| - | 916 | int CVICALLBACK PlotQdcHistogramCB (int panel, int control, int event, |
|
| - | 917 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 918 | int hid=0; |
|
| - | 919 | int nx; |
|
| - | 920 | int ny; |
|
| - | 921 | const unsigned int gr[4] = { QDC_GRAPH_1 ,QDC_GRAPH_2 ,QDC_GRAPH_3 ,QDC_GRAPH_4 }; |
|
| - | 922 | int wfm=0; |
|
| - | 923 | switch (event) { |
|
| - | 924 | case EVENT_COMMIT: |
|
| - | 925 | GetCtrlVal(p3,QDC_WFM,&wfm); |
|
| - | 926 | for (int i=0;i<4;i++) if (wfm) H2D_Draw(200+i,p3,gr[i],&qdcplothandle[i]); else H1D_Draw(200+i,p3,gr[i],&qdcplothandle[i]); |
|
| - | 927 | break; |
|
| - | 928 | } |
|
| - | 929 | return 0; |
|
| - | 930 | } |
|
| - | 931 | ||
| 536 | 932 | ||
| 537 | int CVICALLBACK PlotScanHistogramCB (int panel, int control, int event, |
933 | int CVICALLBACK PlotScanHistogramCB (int panel, int control, int event, |
| 538 | void *callbackData, int eventData1, int eventData2) { |
934 | void *callbackData, int eventData1, int eventData2) { |
| 539 | int hid=0; |
935 | int hid=0; |
| 540 | int nx; |
936 | int nx; |
| 541 | int ny; |
937 | int ny; |
| 542 | switch (event) { |
938 | switch (event) { |
| 543 | case EVENT_COMMIT: |
939 | case EVENT_COMMIT: |
| 544 | GetCtrlVal (p2, SCAN_CHANNEL, &hid); |
940 | GetCtrlVal (p2, SCAN_CHANNEL, &hid); |
| 545 | GetCtrlVal(p2, SCAN_NSTEPSX, &nx); |
941 | GetCtrlVal(p2, SCAN_NSTEPSX, &nx); |
| 546 | GetCtrlVal(p2, SCAN_NSTEPSY, &ny); |
942 | GetCtrlVal(p2, SCAN_NSTEPSY, &ny); |
| 547 | if (nx>1 && ny>1) { |
943 | if (nx>1 && ny>1) { |
| 548 | H2D_Draw(hid,p2,SCAN_GRAPH,&scanplothandle); |
944 | H2D_Draw(hid,p2,SCAN_GRAPH,&scanplothandle); |
| Line 555... | Line 951... | ||
| 555 | if (ny>1) { |
951 | if (ny>1) { |
| 556 | printf("redraw 1d x\n"); |
952 | printf("redraw 1d x\n"); |
| 557 | H1D_Draw(100+hid,p2,SCAN_GRAPH,&scanplothandle); |
953 | H1D_Draw(100+hid,p2,SCAN_GRAPH,&scanplothandle); |
| 558 | } |
954 | } |
| 559 | } |
955 | } |
| 560 | break; |
956 | break; |
| - | 957 | } |
|
| - | 958 | return 0; |
|
| - | 959 | } |
|
| - | 960 | ||
| - | 961 | int CVICALLBACK OpenGuiCB (int panel, int control, int event, |
|
| - | 962 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 963 | switch (event) { |
|
| - | 964 | case EVENT_COMMIT: |
|
| - | 965 | DisplayPanel (ph); |
|
| - | 966 | DisplayPanel (p2); |
|
| - | 967 | break; |
|
| 561 | } |
968 | } |
| 562 | return 0; |
969 | return 0; |
| 563 | } |
970 | } |
| 564 | 971 | ||
| - | 972 | ||
| 565 | int CVICALLBACK |
973 | int CVICALLBACK OpenQdcCB (int panel, int control, int event, |
| 566 | void *callbackData, int eventData1, int eventData2) { |
974 | void *callbackData, int eventData1, int eventData2) { |
| 567 | switch (event) { |
975 | switch (event) { |
| 568 | case EVENT_COMMIT: |
976 | case EVENT_COMMIT: |
| 569 | DisplayPanel (ph); |
977 | DisplayPanel (ph); |
| 570 | DisplayPanel ( |
978 | DisplayPanel (p3); |
| 571 | break; |
979 | break; |
| 572 | } |
980 | } |
| 573 | return 0; |
981 | return 0; |
| 574 | } |
982 | } |
| - | 983 | ||
| 575 | 984 | ||
| 576 | int CVICALLBACK CalibrateCB (int panel, int control, int event, |
985 | int CVICALLBACK CalibrateCB (int panel, int control, int event, |
| 577 | void *callbackData, int eventData1, int eventData2) { |
986 | void *callbackData, int eventData1, int eventData2) { |
| 578 | int status = 0; |
987 | int status = 0; |
| 579 | switch (event) { |
988 | switch (event) { |
| 580 | case EVENT_COMMIT: |
989 | case EVENT_COMMIT: |
| 581 | status = DRSCalibrateTiming(); |
990 | status = DRSCalibrateTiming(); |
| 582 | printf("DRSCalibrateTiming() status = %d\n", status); |
991 | printf("DRSCalibrateTiming() status = %d\n", status); |
| 583 | break; |
992 | break; |
| 584 | } |
993 | } |
| 585 | return 0; |
994 | return 0; |
| - | 995 | } |
|
| - | 996 | ||
| - | 997 | int CVICALLBACK SetActiveCB (int panel, int control, int event, |
|
| - | 998 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 999 | const int c[4] = { QDC_ACTIVE_1 ,QDC_ACTIVE_2 ,QDC_ACTIVE_3 ,QDC_ACTIVE_4 }; |
|
| - | 1000 | const double twin0[4] = { QDC_TWIN0_1 ,QDC_TWIN0_2 ,QDC_TWIN0_3 ,QDC_TWIN0_4 }; |
|
| - | 1001 | const double twin1[4] = { QDC_TWIN1_1 ,QDC_TWIN1_2 ,QDC_TWIN1_3 ,QDC_TWIN1_4 }; |
|
| - | 1002 | int val=0; |
|
| - | 1003 | switch (event) { |
|
| - | 1004 | case EVENT_COMMIT: |
|
| - | 1005 | GetCtrlVal(panel, control, &val); |
|
| - | 1006 | int ctrl=-1; |
|
| - | 1007 | for (int k=0;k<4;k++) if ( c[k]==control & panel==p3 ) ctrl=k; |
|
| - | 1008 | if (ctrl<0) break; |
|
| - | 1009 | ||
| - | 1010 | gActive[ctrl] = val; |
|
| - | 1011 | GetCtrlVal(panel, twin0[ctrl], &gTwinMin[ctrl]); |
|
| - | 1012 | GetCtrlVal(panel, twin1[ctrl], &gTwinMax[ctrl]); |
|
| - | 1013 | printf("Channel gActive[%d]=%d tmin %f tmax %f\n", ctrl,gActive[ctrl], gTwinMin[ctrl], gTwinMax[ctrl]); |
|
| - | 1014 | break; |
|
| - | 1015 | } |
|
| - | 1016 | return 0; |
|
| - | 1017 | } |
|
| - | 1018 | ||
| - | 1019 | int CVICALLBACK ScaleCB (int panel, int control, int event, |
|
| - | 1020 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 1021 | const int c[4] = { PANEL_SCALE_1 ,PANEL_SCALE_2 ,PANEL_SCALE_3 ,PANEL_SCALE_4 }; |
|
| - | 1022 | switch (event) { |
|
| - | 1023 | case EVENT_COMMIT: { |
|
| - | 1024 | double val; |
|
| - | 1025 | GetCtrlVal(panel, control, &val); |
|
| - | 1026 | int ctrl=-1; |
|
| - | 1027 | for (int k=0;k<4;k++) if ( c[k]==control & panel==ph ) ctrl=k; |
|
| - | 1028 | if (ctrl<0) break; |
|
| - | 1029 | gFx[ctrl] = val; |
|
| - | 1030 | printf("Scaling factor gFx[%d]=%f\n", ctrl,gFx[ctrl]); |
|
| - | 1031 | ||
| - | 1032 | break; |
|
| - | 1033 | } |
|
| - | 1034 | } |
|
| - | 1035 | return 0; |
|
| - | 1036 | } |
|
| - | 1037 | ||
| - | 1038 | ||
| - | 1039 | ||
| - | 1040 | ||
| - | 1041 | /*---------------------------------------------------------------------------*/ |
|
| - | 1042 | /* Macros */ |
|
| - | 1043 | /*---------------------------------------------------------------------------*/ |
|
| - | 1044 | #define tcpChk(f) if ((g_TCPError=(f)) < 0) {ReportTCPError();} |
|
| - | 1045 | ||
| - | 1046 | ||
| - | 1047 | /*---------------------------------------------------------------------------*/ |
|
| - | 1048 | /* Internal function prototypes */ |
|
| - | 1049 | /*---------------------------------------------------------------------------*/ |
|
| - | 1050 | int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, |
|
| - | 1051 | void *callbackData); |
|
| - | 1052 | static void ReportTCPError (void); |
|
| - | 1053 | ||
| - | 1054 | ||
| - | 1055 | /*---------------------------------------------------------------------------*/ |
|
| - | 1056 | /* Report TCP Errors if any */ |
|
| - | 1057 | /*---------------------------------------------------------------------------*/ |
|
| - | 1058 | static void ReportTCPError(void) |
|
| - | 1059 | { |
|
| - | 1060 | if (g_TCPError < 0) |
|
| - | 1061 | { |
|
| - | 1062 | char messageBuffer[1024]; |
|
| - | 1063 | sprintf(messageBuffer, |
|
| - | 1064 | "TCP library error message: %s\nSystem error message: %s", |
|
| - | 1065 | GetTCPErrorString (g_TCPError), GetTCPSystemErrorString()); |
|
| - | 1066 | MessagePopup ("Error", messageBuffer); |
|
| - | 1067 | g_TCPError = 0; |
|
| - | 1068 | } |
|
| - | 1069 | } |
|
| - | 1070 | /*---------------------------------------------------------------------------*/ |
|
| - | 1071 | ||
| - | 1072 | ||
| - | 1073 | int CVICALLBACK DisconnectCB (int panel, int control, int event, |
|
| - | 1074 | void *callbackData, int eventData1, int eventData2) { |
|
| - | 1075 | switch (event) { |
|
| - | 1076 | case EVENT_COMMIT: |
|
| - | 1077 | if (g_connected) |
|
| - | 1078 | DisconnectFromTCPServer (g_hconversation); |
|
| - | 1079 | g_hconversation = 0; |
|
| - | 1080 | g_connected = 0; |
|
| - | 1081 | break; |
|
| - | 1082 | } |
|
| - | 1083 | return 0; |
|
| - | 1084 | } |
|
| - | 1085 | ||
| - | 1086 | int CVICALLBACK ConnectCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { |
|
| - | 1087 | int portNum=10000; |
|
| - | 1088 | char tempBuf[512]; |
|
| - | 1089 | sprintf(tempBuf,"localhost"); |
|
| - | 1090 | switch (event) { |
|
| - | 1091 | case EVENT_COMMIT: |
|
| - | 1092 | if (g_connected) return 0; |
|
| - | 1093 | if (ConnectToTCPServer (&g_hconversation, portNum, tempBuf, ClientTCPCB, NULL, 5000) < 0) |
|
| - | 1094 | MessagePopup("TCP Client", "Connection to server failed !"); |
|
| - | 1095 | else |
|
| - | 1096 | { |
|
| - | 1097 | SetWaitCursor (0); |
|
| - | 1098 | g_connected = 1; |
|
| - | 1099 | ||
| - | 1100 | /* We are successfully connected -- gather info */ |
|
| - | 1101 | ||
| - | 1102 | if (GetTCPHostAddr (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
|
| - | 1103 | if (GetTCPHostName (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
|
| - | 1104 | ||
| - | 1105 | tcpChk (GetTCPPeerAddr (g_hconversation, tempBuf, 256)); |
|
| - | 1106 | printf("%s\n" ,tempBuf); |
|
| - | 1107 | tcpChk (GetTCPPeerName (g_hconversation, tempBuf, 256)); |
|
| - | 1108 | printf("%s\n" ,tempBuf); |
|
| - | 1109 | } |
|
| - | 1110 | break; |
|
| - | 1111 | } |
|
| - | 1112 | return 0; |
|
| - | 1113 | } |
|
| - | 1114 | ||
| - | 1115 | ||
| - | 1116 | int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, void *callbackData) |
|
| - | 1117 | { |
|
| - | 1118 | char receiveBuf[256] = {0}; |
|
| - | 1119 | ssize_t dataSize = sizeof (receiveBuf) - 1; |
|
| - | 1120 | ||
| - | 1121 | switch (event) |
|
| - | 1122 | { |
|
| - | 1123 | case TCP_DATAREADY: |
|
| - | 1124 | if ((dataSize = ClientTCPRead (g_hconversation, receiveBuf, |
|
| - | 1125 | dataSize, 1000)) |
|
| - | 1126 | < 0) |
|
| - | 1127 | { |
|
| - | 1128 | printf( "Receive Error\n"); |
|
| - | 1129 | } |
|
| - | 1130 | else |
|
| - | 1131 | { |
|
| - | 1132 | receiveBuf[dataSize] = '\0'; |
|
| - | 1133 | //printf("%s", receiveBuf); |
|
| - | 1134 | float temp = 0; |
|
| - | 1135 | float humidity = 0; |
|
| - | 1136 | float dt=0; |
|
| - | 1137 | float tdiff=0; |
|
| - | 1138 | int t0 = 0; |
|
| - | 1139 | sscanf(receiveBuf, "%d%f%f%f%f", &t0,&humidity,&temp, &tdiff, &dt); |
|
| - | 1140 | SetCtrlVal(ph,PANEL_TMON, temp); |
|
| - | 1141 | SetCtrlVal(ph,PANEL_HUMIDITY, humidity); |
|
| - | 1142 | if (fabs(tdiff)<0.2 && fabs(dt) < 0.05) SetCtrlVal(ph,PANEL_LED, 1); |
|
| - | 1143 | else SetCtrlVal(ph,PANEL_LED, 0); |
|
| - | 1144 | } |
|
| - | 1145 | break; |
|
| - | 1146 | case TCP_DISCONNECT: |
|
| - | 1147 | MessagePopup ("TCP Client", "Server has closed connection!"); |
|
| - | 1148 | ||
| - | 1149 | g_connected = 0; |
|
| - | 1150 | ||
| - | 1151 | break; |
|
| - | 1152 | } |
|
| - | 1153 | return 0; |
|
| 586 | } |
1154 | } |