Rev 265 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 317 | f9daq | 1 | #include <tcpsupp.h> |
| 217 | f9daq | 2 | #include "H1D.h" |
| 3 | #include "H2D.h" |
||
| 203 | f9daq | 4 | #include <formatio.h> |
| 195 | f9daq | 5 | #include <utility.h> |
| 6 | #include <ansi_c.h> |
||
| 203 | f9daq | 7 | #include <cvirte.h> |
| 195 | f9daq | 8 | #include <userint.h> |
| 9 | #include "drs4.h" |
||
| 317 | f9daq | 10 | #include "scaler.h" |
| 203 | f9daq | 11 | #include "drsread.h" |
| 317 | f9daq | 12 | #include "K6517.h" |
| 195 | f9daq | 13 | |
| 317 | f9daq | 14 | K6517STATUS K6517Stat; |
| 15 | static int K6517_Interface,K6517_Port,K6517_Gdev; |
||
| 16 | //#define MIKRO |
||
| 203 | f9daq | 17 | |
| 18 | #ifdef MIKRO |
||
| 19 | #include "MIKRO.h" |
||
| 20 | #endif |
||
| 21 | |||
| 317 | f9daq | 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 | |||
| 32 | int daq_on; |
||
| 33 | int ph, p2,p3,p4, plothandle[4]= {0,0,0,0}; |
||
| 34 | static int qdcplothandle[4]= {0,0,0,0}; |
||
| 217 | f9daq | 35 | static int scanplothandle; |
| 195 | f9daq | 36 | static int tfID; |
| 317 | f9daq | 37 | static int rID; |
| 195 | f9daq | 38 | static int controlID; |
| 39 | |||
| 203 | f9daq | 40 | #define MAX_THREADS 10 |
| 195 | f9daq | 41 | |
| 203 | f9daq | 42 | static CmtThreadPoolHandle poolHandle = 0; |
| 195 | f9daq | 43 | |
| 217 | f9daq | 44 | static float gSum[4]={0,0,0,0}; |
| 317 | f9daq | 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 | |||
| 195 | f9daq | 52 | int main (int argc, char *argv[]) { |
| 203 | f9daq | 53 | short port; |
| 54 | if (InitCVIRTE (0, argv, 0) == 0) |
||
| 55 | return -1; /* out of memory */ |
||
| 56 | if ((ph = LoadPanel (0, "drs4.uir", PANEL)) < 0) |
||
| 57 | return -1; |
||
| 58 | if ((p2 = LoadPanel (0, "drs4.uir", SCAN)) < 0) |
||
| 59 | return -1; |
||
| 317 | f9daq | 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(); |
||
| 203 | f9daq | 66 | SetStdioPort (CVI_STDIO_WINDOW); |
| 67 | SetSleepPolicy(VAL_SLEEP_MORE); |
||
| 68 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
||
| 69 | |||
| 70 | DisplayPanel (ph); |
||
| 71 | DisplayPanel (p2); |
||
| 317 | f9daq | 72 | DisplayPanel (p3); |
| 73 | DisplayPanel (p4); |
||
| 203 | f9daq | 74 | #ifdef MIKRO |
| 75 | GetCtrlVal(p2, SCAN_PORT, &port); |
||
| 76 | if (MIKRO_Open (port)) MessagePopup ("Error", "Mikro Port Not found !\n Change in the GUI") ; |
||
| 77 | MIKRO_Init(1,0); |
||
| 78 | MIKRO_Init(2,0); |
||
| 79 | #endif |
||
| 80 | |||
| 317 | f9daq | 81 | K6517_open (1,4,3,0,13); |
| 82 | |||
| 203 | f9daq | 83 | RunUserInterface (); |
| 84 | DiscardPanel (ph); |
||
| 85 | DiscardPanel (p2); |
||
| 317 | f9daq | 86 | DiscardPanel (p3); |
| 87 | DiscardPanel (p4); |
||
| 203 | f9daq | 88 | CmtDiscardThreadPool (poolHandle); |
| 317 | f9daq | 89 | #ifdef MIKRO |
| 90 | MIKRO_Close (); |
||
| 91 | #endif |
||
| 203 | f9daq | 92 | return 0; |
| 195 | f9daq | 93 | } |
| 94 | |||
| 95 | |||
| 210 | f9daq | 96 | char strbuf[0xFF]; |
| 195 | f9daq | 97 | |
| 210 | f9daq | 98 | int gLog=0; |
| 195 | f9daq | 99 | |
| 210 | f9daq | 100 | int printf(const char *format, ...) { |
| 101 | va_list aptr; |
||
| 102 | int ret; |
||
| 103 | FILE *flog; |
||
| 195 | f9daq | 104 | |
| 210 | f9daq | 105 | va_start(aptr, format); |
| 106 | ret = vsprintf(strbuf, format, aptr); |
||
| 107 | va_end(aptr); |
||
| 108 | SetCtrlVal(ph,PANEL_STDIO,strbuf); |
||
| 109 | |||
| 110 | if (gLog) { |
||
| 111 | flog = fopen ("stdio.log", "a"); |
||
| 112 | fprintf (flog, "%s", strbuf); |
||
| 113 | fclose (flog); |
||
| 114 | } |
||
| 115 | return(ret); |
||
| 116 | } |
||
| 117 | |||
| 118 | |||
| 119 | |||
| 195 | f9daq | 120 | static void start_timer (double tout) { |
| 203 | f9daq | 121 | SetCtrlAttribute (ph, PANEL_TIMER, ATTR_INTERVAL, tout); |
| 122 | SetCtrlAttribute (ph, PANEL_TIMER, ATTR_ENABLED, 1); |
||
| 195 | f9daq | 123 | } |
| 124 | |||
| 125 | static void stop_timer ( void ) { |
||
| 203 | f9daq | 126 | SetCtrlAttribute (ph, PANEL_TIMER, ATTR_ENABLED, 0); |
| 127 | DRSSetTimeout(); |
||
| 195 | f9daq | 128 | } |
| 129 | |||
| 130 | |||
| 131 | |||
| 317 | f9daq | 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 ; |
||
| 195 | f9daq | 137 | |
| 317 | f9daq | 138 | } |
| 139 | |||
| 195 | f9daq | 140 | void CVICALLBACK EndOfThread ( CmtThreadPoolHandle poolhandle, |
| 203 | f9daq | 141 | CmtThreadFunctionID functionID, unsigned int event, |
| 142 | int value, void *callbackData ) { |
||
| 195 | f9daq | 143 | |
| 203 | f9daq | 144 | daq_on=0; |
| 145 | //SetDimming(0); |
||
| 146 | printf("End of Thread \n"); |
||
| 147 | return ; |
||
| 195 | f9daq | 148 | |
| 149 | } |
||
| 150 | |||
| 151 | |||
| 217 | f9daq | 152 | static float xs[4][1024]; |
| 317 | f9daq | 153 | |
| 203 | f9daq | 154 | int CVICALLBACK daq(void *functionData) { |
| 195 | f9daq | 155 | |
| 156 | |||
| 203 | f9daq | 157 | int neve; |
| 158 | char filename[0xff]; |
||
| 159 | int imask[4]; |
||
| 160 | unsigned long mask; |
||
| 161 | int frequency; |
||
| 162 | double trgdelay; |
||
| 163 | double trglevel; |
||
| 164 | int trgtype; |
||
| 165 | int trgchannel; |
||
| 166 | int trgpolarity; |
||
| 167 | int verbose; |
||
| 168 | double range; |
||
| 169 | int pfreq; |
||
| 170 | int enabledoutput; |
||
| 171 | int neveold = 0; |
||
| 172 | double rate; |
||
| 173 | int *args = (int *) functionData; |
||
| 265 | f9daq | 174 | |
| 317 | f9daq | 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 }; |
||
| 217 | f9daq | 179 | |
| 203 | f9daq | 180 | GetCtrlVal(ph, PANEL_CH0, &imask[0] ); |
| 181 | GetCtrlVal(ph, PANEL_CH1, &imask[1] ); |
||
| 182 | GetCtrlVal(ph, PANEL_CH2, &imask[2] ); |
||
| 183 | GetCtrlVal(ph, PANEL_CH3, &imask[3] ); |
||
| 317 | f9daq | 184 | GetCtrlVal(p3, QDC_WFM, &wfm ); |
| 203 | f9daq | 185 | mask = 0; |
| 186 | for (int i=0; i<4; i++) { |
||
| 317 | f9daq | 187 | if (imask[i]) { |
| 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 | } |
||
| 201 | f9daq | 193 | } |
| 317 | f9daq | 194 | LogScaleCB(p3, QDC_LOGY,EVENT_COMMIT,NULL, 0,0); |
| 203 | f9daq | 195 | |
| 265 | f9daq | 196 | |
| 203 | f9daq | 197 | GetCtrlVal(ph,PANEL_NEVE, &neve); |
| 198 | GetCtrlVal(ph,PANEL_DEBUG, &verbose); |
||
| 199 | GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
||
| 200 | GetCtrlVal(ph,PANEL_ENABLEDOUTPUT, &enabledoutput); |
||
| 201 | |||
| 202 | GetCtrlVal(ph,PANEL_FREQUENCY, &frequency); |
||
| 203 | GetCtrlVal(ph,PANEL_TRGDELAY, &trgdelay); |
||
| 204 | GetCtrlVal(ph,PANEL_TRGCHANNEL, &trgchannel); |
||
| 205 | |||
| 265 | f9daq | 206 | |
| 203 | f9daq | 207 | GetCtrlVal(ph,PANEL_TRGTYPE, &trgtype); |
| 208 | GetCtrlVal(ph,PANEL_TRGLEVEL, &trglevel); |
||
| 209 | GetCtrlVal(ph,PANEL_TRGPOLARITY, &trgpolarity); |
||
| 210 | GetCtrlVal(ph,PANEL_RANGE, &range); |
||
| 211 | |||
| 317 | f9daq | 212 | |
| 203 | f9daq | 213 | //printf("mask=0x%x\n",mask); |
| 214 | |||
| 215 | DRSSetMask( (unsigned char)( mask & 0xF ) ); |
||
| 216 | |||
| 217 | DRSSetFrequency( frequency ); |
||
| 218 | DRSSetTriggerDelay(trgdelay ); |
||
| 219 | DRSSetTriggerChannel(trgchannel ); |
||
| 220 | DRSSetTriggerType( trgtype ); |
||
| 221 | DRSSetTriggerLevel(trglevel); |
||
| 222 | DRSSetTriggerPolarity(trgpolarity); |
||
| 223 | |||
| 224 | DRSSetRange ( range ); |
||
| 225 | |||
| 226 | |||
| 227 | |||
| 228 | FILE *fp= NULL; |
||
| 229 | |||
| 230 | if (enabledoutput) { |
||
| 317 | f9daq | 231 | if (1==1) { |
| 217 | f9daq | 232 | GetCtrlVal(ph, PANEL_FILENAME, filename ); |
| 317 | f9daq | 233 | printf("%s\n", filename); |
| 217 | f9daq | 234 | fp = fopen(filename,"wb"); |
| 235 | } else { |
||
| 236 | GetCtrlVal(p2, SCAN_FILENAME, filename ); |
||
| 237 | fp = fopen(filename,"ab"); |
||
| 317 | f9daq | 238 | printf("%s\n", filename); |
| 217 | f9daq | 239 | } |
| 203 | f9daq | 240 | } |
| 241 | |||
| 242 | static unsigned char *buffer; |
||
| 243 | |||
| 244 | int buffer_size = 0; |
||
| 245 | const int nBoards=1; |
||
| 246 | const int waveDepth=1024; |
||
| 207 | f9daq | 247 | |
| 203 | f9daq | 248 | if (buffer_size == 0) { |
| 207 | f9daq | 249 | buffer_size = 8; // file header + time header |
| 250 | buffer_size += nBoards * (4 + 4*(4+waveDepth*4)); // bin widths |
||
| 251 | buffer_size += 24 + nBoards * (8 + 4*(8+waveDepth*2)); |
||
| 252 | buffer = (unsigned char *)malloc(buffer_size); |
||
| 253 | } |
||
| 254 | |||
| 203 | f9daq | 255 | time_t t=0,told=0, tstart=0; |
| 256 | |||
| 257 | if (!DRSInit()) { |
||
| 265 | f9daq | 258 | |
| 203 | f9daq | 259 | time(&tstart); |
| 260 | told=tstart; |
||
| 217 | f9daq | 261 | int nev=0; |
| 262 | for (int k = 0;k<4;k++){ |
||
| 263 | gSum[k]=0; |
||
| 264 | } |
||
| 265 | for (int i=0; i<neve; i++) { |
||
| 203 | f9daq | 266 | start_timer(1);// 1 s timeout |
| 267 | int retval = DRSRead(0); |
||
| 268 | stop_timer(); |
||
| 269 | int nb = ( retval == 0 && fp ) ? DRSToBuffer( buffer , i ) : 0; |
||
| 270 | SetCtrlVal(ph,PANEL_CEVE,i); |
||
| 271 | if (retval) i--; |
||
| 217 | f9daq | 272 | nev++; |
| 203 | f9daq | 273 | if (!daq_on) break; |
| 274 | time(&t); |
||
| 275 | if (t!=told ) { |
||
| 317 | f9daq | 276 | PlotQdcHistogramCB(0,0,EVENT_COMMIT,NULL, 0,0); |
| 203 | f9daq | 277 | rate = (i-neveold); |
| 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)); |
||
| 279 | GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
||
| 280 | neveold = i; |
||
| 281 | } |
||
| 282 | told=t; |
||
| 283 | // Save data |
||
| 317 | f9daq | 284 | |
| 203 | f9daq | 285 | if (nb>0 && fp) fwrite(buffer, 1,nb ,fp); |
| 286 | // Plot Data |
||
| 317 | f9daq | 287 | |
| 217 | f9daq | 288 | for (int k=0; k<4; k++) { |
| 289 | if ( (mask & ( 0x1<<k )) ){ |
||
| 317 | f9daq | 290 | double fSum= 0; |
| 217 | f9daq | 291 | float *t=DRSGetTime(k); |
| 292 | float *x=DRSGetWave(k); |
||
| 293 | ; |
||
| 294 | for (int j=0 ; j<1024 ; j++) { |
||
| 317 | f9daq | 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; |
||
| 217 | f9daq | 313 | |
| 314 | if (i % pfreq == 0) { |
||
| 315 | const int col[4]= {VAL_WHITE,VAL_RED,VAL_GREEN,VAL_BLUE}; |
||
| 316 | if (plothandle[k]) DeleteGraphPlot (ph, PANEL_GRAPH, plothandle[k], VAL_IMMEDIATE_DRAW); |
||
| 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]); |
||
| 318 | } |
||
| 203 | f9daq | 319 | } |
| 217 | f9daq | 320 | |
| 203 | f9daq | 321 | } |
| 322 | |||
| 323 | |||
| 324 | } |
||
| 325 | time(&t); |
||
| 217 | f9daq | 326 | printf("%d events in %2.2f min (%d s) %s",nev, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
| 203 | f9daq | 327 | DRSEnd(); |
| 328 | } |
||
| 329 | |||
| 330 | if (fp) fclose(fp); |
||
| 331 | |||
| 332 | free(buffer); |
||
| 333 | |||
| 334 | return 0; |
||
| 335 | |||
| 195 | f9daq | 336 | } |
| 337 | |||
| 338 | |||
| 317 | f9daq | 339 | void CVICALLBACK EndOfThrScan ( CmtThreadPoolHandle poolhandle, |
| 340 | CmtThreadFunctionID functionID, unsigned int event, |
||
| 341 | int value, void *callbackData ) { |
||
| 195 | f9daq | 342 | |
| 317 | f9daq | 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 | } |
||
| 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 | } |
||
| 598 | return 0; |
||
| 599 | } |
||
| 600 | |||
| 601 | |||
| 602 | |||
| 603 | |||
| 203 | f9daq | 604 | int CVICALLBACK scan(void *functionData) { |
| 195 | f9daq | 605 | |
| 207 | f9daq | 606 | int dx[3]={0,0,0}; |
| 607 | int nx[3]={0,0,0}; |
||
| 608 | int x0[3]={0,0,0}; |
||
| 609 | int ix[3]={0,0,0}; |
||
| 610 | int idx[3]={0,0,0}; |
||
| 203 | f9daq | 611 | int size; |
| 207 | f9daq | 612 | char posrec[4]="POSR"; |
| 613 | char runbuf[4]="PRUN"; |
||
| 203 | f9daq | 614 | |
| 207 | f9daq | 615 | int n[3]; |
| 203 | f9daq | 616 | char filename[0xFF]; |
| 617 | int enabledoutput; |
||
| 618 | |||
| 619 | FILE *fp; |
||
| 217 | f9daq | 620 | GetCtrlVal(p2, SCAN_FILENAME, filename ); |
| 203 | f9daq | 621 | |
| 622 | GetCtrlVal(ph,PANEL_ENABLEDOUTPUT, &enabledoutput); |
||
| 623 | |||
| 624 | if ( GetFileInfo(filename,&size) ) { |
||
| 217 | f9daq | 625 | MessagePopup ("Warning","File exist. Remove it first or choose another file"); |
| 626 | return 0; |
||
| 203 | f9daq | 627 | } |
| 628 | GetCtrlVal(p2, SCAN_STEPX, &dx[0]); |
||
| 629 | GetCtrlVal(p2, SCAN_STEPY, &dx[1]); |
||
| 630 | GetCtrlVal(p2, SCAN_NSTEPSX, &nx[0]); |
||
| 631 | GetCtrlVal(p2, SCAN_NSTEPSY, &nx[1]); |
||
| 632 | GetCtrlVal(p2, SCAN_STARTX, &x0[0]); |
||
| 633 | GetCtrlVal(p2, SCAN_STARTY, &x0[1]); |
||
| 217 | f9daq | 634 | for (int k=0;k<4;k++) { |
| 635 | H2D_Init(k, "charge","Induced charge", |
||
| 636 | nx[0], x0[0] - dx[0]*0.5 ,x0[0] + dx[0] * ( nx[0] - 0.5) , |
||
| 637 | nx[1], x0[1] - dx[1]*0.5 ,x0[1] + dx[1] * ( nx[1] - 0.5)); |
||
| 638 | H1D_Init(k, "charge","Induced charge projection x", |
||
| 639 | nx[0], x0[0] - dx[0]*0.5 ,x0[0] + dx[0] * ( nx[0] - 0.5) ); |
||
| 640 | H1D_Init(100 + k, "charge","Induced charge projection y", |
||
| 641 | nx[1], x0[1] - dx[1]*0.5 ,x0[1] + dx[1] * ( nx[1] - 0.5) ); |
||
| 642 | } |
||
| 207 | f9daq | 643 | if (enabledoutput) { |
| 644 | fp = fopen(filename,"ab"); |
||
| 645 | if (fp) { |
||
| 646 | size=36; |
||
| 647 | fwrite(runbuf, 1,4 ,fp); |
||
| 648 | fwrite(&size , 1,4 ,fp); |
||
| 649 | fwrite(x0 , 1,4*3 ,fp); |
||
| 650 | fwrite(dx , 1,4*3 ,fp); |
||
| 651 | fwrite(nx , 1,4*3 ,fp); |
||
| 652 | fclose(fp); |
||
| 653 | } |
||
| 654 | } |
||
| 655 | |||
| 203 | f9daq | 656 | for (int i=0; i<nx[0]; i++) { |
| 657 | |||
| 658 | ix[0]= x0[0]+i*dx[0]; |
||
| 659 | #ifdef MIKRO |
||
| 660 | MIKRO_MoveTo(1,ix[0]); |
||
| 661 | #endif |
||
| 662 | SetCtrlVal (p2, SCAN_IX, i); |
||
| 663 | for (int j=0; j<nx[1]; j++) { |
||
| 664 | |||
| 665 | SetCtrlVal (p2, SCAN_IY, j); |
||
| 666 | |||
| 667 | ix[1]= x0[1]+j*dx[1]; |
||
| 668 | #ifdef MIKRO |
||
| 669 | MIKRO_MoveTo(2,ix[1]); |
||
| 670 | |||
| 671 | MIKRO_GetPosition(1,&n[0]); |
||
| 672 | SetCtrlVal (p2, SCAN_XP, n[0]); |
||
| 673 | MIKRO_GetPosition(2,&n[1]); |
||
| 674 | SetCtrlVal (p2, SCAN_YP, n[1]); |
||
| 207 | f9daq | 675 | |
| 676 | if (enabledoutput) { |
||
| 203 | f9daq | 677 | fp = fopen(filename,"ab"); |
| 678 | if (fp) { |
||
| 207 | f9daq | 679 | idx[0]=i; |
| 680 | idx[1]=j; |
||
| 681 | size=24; |
||
| 682 | fwrite(posrec, 1,4 ,fp); |
||
| 683 | fwrite(&size , 1,4 ,fp); |
||
| 684 | fwrite(n , 1,4*3 ,fp); |
||
| 685 | fwrite(idx , 1,4*3 ,fp); |
||
| 203 | f9daq | 686 | fclose(fp); |
| 687 | } |
||
| 688 | } |
||
| 689 | |||
| 690 | #endif |
||
| 691 | daq(functionData); |
||
| 217 | f9daq | 692 | |
| 693 | for (int k=0;k<4;k++) { |
||
| 694 | H2D_Fill(k, ix[0], ix[1] , gSum[k] ); |
||
| 695 | H1D_Fill(k, ix[0] , gSum[k] ); |
||
| 696 | H1D_Fill(100+ k, ix[1] , gSum[k] ); |
||
| 697 | } |
||
| 698 | PlotScanHistogramCB(0,0,EVENT_COMMIT,NULL, 0,0); |
||
| 203 | f9daq | 699 | if (!daq_on) break; |
| 700 | } |
||
| 701 | if (!daq_on) break; |
||
| 702 | } |
||
| 703 | |||
| 704 | return 0; |
||
| 195 | f9daq | 705 | } |
| 706 | |||
| 203 | f9daq | 707 | |
| 317 | f9daq | 708 | |
| 709 | |||
| 195 | f9daq | 710 | int CVICALLBACK StartCB (int panel, int control, int event, |
| 203 | f9daq | 711 | void *callbackData, int eventData1, int eventData2) { |
| 712 | ThreadFunctionPtr mythread = NULL; |
||
| 713 | switch (event) { |
||
| 714 | |||
| 715 | case EVENT_COMMIT: |
||
| 716 | |||
| 717 | controlID=0; |
||
| 718 | if (panel == ph && control == PANEL_START) { |
||
| 719 | mythread = daq; |
||
| 720 | controlID= control; |
||
| 721 | } |
||
| 722 | if (panel == p2 && control == SCAN_SCAN) mythread = scan; |
||
| 317 | f9daq | 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 | |||
| 203 | f9daq | 729 | if (mythread!=NULL) { |
| 730 | printf("New Thread panel=%d button=%d\n", panel, control); |
||
| 731 | |||
| 732 | // SetDimming(1); |
||
| 733 | |||
| 734 | daq_on=1; |
||
| 735 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &controlID, |
||
| 736 | DEFAULT_THREAD_PRIORITY, |
||
| 737 | EndOfThread, |
||
| 738 | EVENT_TP_THREAD_FUNCTION_END, |
||
| 739 | NULL, RUN_IN_SCHEDULED_THREAD, |
||
| 740 | &tfID); |
||
| 741 | } |
||
| 742 | break; |
||
| 743 | } |
||
| 744 | return 0; |
||
| 195 | f9daq | 745 | } |
| 746 | |||
| 747 | int CVICALLBACK StopCB (int panel, int control, int event, |
||
| 203 | f9daq | 748 | void *callbackData, int eventData1, int eventData2) { |
| 749 | switch (event) { |
||
| 750 | case EVENT_COMMIT: |
||
| 751 | daq_on=0; |
||
| 752 | break; |
||
| 753 | } |
||
| 754 | return 0; |
||
| 195 | f9daq | 755 | } |
| 756 | |||
| 757 | int CVICALLBACK ExitCB (int panel, int control, int event, |
||
| 203 | f9daq | 758 | void *callbackData, int eventData1, int eventData2) { |
| 759 | switch (event) { |
||
| 760 | case EVENT_COMMIT: |
||
| 761 | QuitUserInterface (0); |
||
| 762 | break; |
||
| 763 | } |
||
| 764 | return 0; |
||
| 195 | f9daq | 765 | } |
| 203 | f9daq | 766 | |
| 767 | int CVICALLBACK MoveStageCB (int panel, int control, int event, |
||
| 768 | void *callbackData, int eventData1, int eventData2) { |
||
| 769 | int axis=0, step=1000, direction=1, n; |
||
| 770 | switch (event) { |
||
| 771 | case EVENT_COMMIT: |
||
| 772 | |||
| 773 | if (panel == p2) { |
||
| 774 | switch (control) { |
||
| 775 | case SCAN_BR : |
||
| 776 | axis = 1; |
||
| 777 | direction = 1; |
||
| 778 | GetCtrlVal(p2, SCAN_STEPX, &step); |
||
| 779 | break; |
||
| 780 | case SCAN_BL : |
||
| 781 | axis = 1; |
||
| 782 | direction = -1; |
||
| 783 | GetCtrlVal(p2, SCAN_STEPX, &step); |
||
| 784 | break; |
||
| 785 | case SCAN_BU : |
||
| 786 | axis = 2; |
||
| 787 | direction = 1; |
||
| 788 | GetCtrlVal(p2, SCAN_STEPY, &step); |
||
| 789 | break; |
||
| 790 | case SCAN_BD : |
||
| 791 | axis = 2; |
||
| 792 | direction = -1; |
||
| 793 | GetCtrlVal(p2, SCAN_STEPY, &step); |
||
| 794 | break; |
||
| 795 | } |
||
| 796 | #ifdef MIKRO |
||
| 797 | MIKRO_MoveFor(axis, direction*step ); |
||
| 798 | MIKRO_GetPosition(axis,&n); |
||
| 799 | if (axis == 1) SetCtrlVal (p2, SCAN_XP, n); |
||
| 800 | if (axis == 2) SetCtrlVal (p2, SCAN_YP, n); |
||
| 801 | #endif // MIKRO |
||
| 802 | } |
||
| 803 | |||
| 804 | break; |
||
| 805 | } |
||
| 806 | return 0; |
||
| 807 | } |
||
| 808 | |||
| 809 | |||
| 810 | |||
| 811 | |||
| 812 | |||
| 813 | int CVICALLBACK GoXCB (int panel, int control, int event, |
||
| 814 | void *callbackData, int eventData1, int eventData2) { |
||
| 815 | int n2; |
||
| 816 | switch (event) { |
||
| 817 | case EVENT_COMMIT: |
||
| 818 | GetCtrlVal (p2, SCAN_XG, &n2); |
||
| 819 | #ifdef MIKRO |
||
| 820 | MIKRO_MoveTo(1,n2); |
||
| 821 | MIKRO_GetPosition(1,&n2); |
||
| 822 | |||
| 823 | #endif |
||
| 824 | SetCtrlVal (p2, SCAN_XP, n2); |
||
| 825 | break; |
||
| 826 | } |
||
| 827 | return 0; |
||
| 828 | } |
||
| 829 | |||
| 830 | int CVICALLBACK GoYCB (int panel, int control, int event, |
||
| 831 | void *callbackData, int eventData1, int eventData2) { |
||
| 832 | int n2; |
||
| 833 | switch (event) { |
||
| 834 | case EVENT_COMMIT: |
||
| 835 | GetCtrlVal (p2, SCAN_YG, &n2); |
||
| 836 | #ifdef MIKRO |
||
| 837 | MIKRO_MoveTo(2,n2); |
||
| 838 | MIKRO_GetPosition(2,&n2); |
||
| 839 | |||
| 840 | #endif |
||
| 841 | SetCtrlVal (p2, SCAN_YP, n2); |
||
| 842 | break; |
||
| 843 | } |
||
| 844 | return 0; |
||
| 845 | } |
||
| 846 | |||
| 847 | int CVICALLBACK GetCurrentPositionCB (int panel, int control, int event, |
||
| 848 | void *callbackData, int eventData1, int eventData2) { |
||
| 849 | |||
| 850 | int n[2]; |
||
| 851 | switch (event) { |
||
| 852 | case EVENT_COMMIT: |
||
| 853 | #ifdef MIKRO |
||
| 854 | MIKRO_GetPosition(1,&n[0]); |
||
| 855 | SetCtrlVal (p2, SCAN_XP, n[0]); |
||
| 856 | MIKRO_GetPosition(2,&n[1]); |
||
| 857 | SetCtrlVal (p2, SCAN_YP, n[1]); |
||
| 858 | #endif |
||
| 859 | break; |
||
| 860 | } |
||
| 861 | return 0; |
||
| 862 | } |
||
| 863 | |||
| 864 | int CVICALLBACK HomeCB (int panel, int control, int event, |
||
| 865 | void *callbackData, int eventData1, int eventData2) { |
||
| 866 | switch (event) { |
||
| 867 | case EVENT_COMMIT: |
||
| 868 | #ifdef MIKRO |
||
| 869 | MIKRO_ReferenceMove(1); |
||
| 870 | MIKRO_ReferenceMove(2); |
||
| 871 | GetCurrentPositionCB(panel, control, event, NULL, 0, 0); |
||
| 872 | #endif |
||
| 873 | break; |
||
| 874 | } |
||
| 875 | return 0; |
||
| 876 | } |
||
| 217 | f9daq | 877 | |
| 317 | f9daq | 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 | |||
| 932 | |||
| 217 | f9daq | 933 | int CVICALLBACK PlotScanHistogramCB (int panel, int control, int event, |
| 934 | void *callbackData, int eventData1, int eventData2) { |
||
| 935 | int hid=0; |
||
| 936 | int nx; |
||
| 937 | int ny; |
||
| 938 | switch (event) { |
||
| 939 | case EVENT_COMMIT: |
||
| 940 | GetCtrlVal (p2, SCAN_CHANNEL, &hid); |
||
| 941 | GetCtrlVal(p2, SCAN_NSTEPSX, &nx); |
||
| 942 | GetCtrlVal(p2, SCAN_NSTEPSY, &ny); |
||
| 943 | if (nx>1 && ny>1) { |
||
| 944 | H2D_Draw(hid,p2,SCAN_GRAPH,&scanplothandle); |
||
| 945 | printf("redraw 2d\n"); |
||
| 946 | } else { |
||
| 947 | if (nx>1) { |
||
| 948 | printf("redraw 1d x\n"); |
||
| 949 | H1D_Draw(hid,p2,SCAN_GRAPH,&scanplothandle); |
||
| 950 | } |
||
| 951 | if (ny>1) { |
||
| 952 | printf("redraw 1d x\n"); |
||
| 953 | H1D_Draw(100+hid,p2,SCAN_GRAPH,&scanplothandle); |
||
| 954 | } |
||
| 955 | } |
||
| 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; |
||
| 968 | } |
||
| 969 | return 0; |
||
| 970 | } |
||
| 265 | f9daq | 971 | |
| 317 | f9daq | 972 | |
| 973 | int CVICALLBACK OpenQdcCB (int panel, int control, int event, |
||
| 974 | void *callbackData, int eventData1, int eventData2) { |
||
| 975 | switch (event) { |
||
| 976 | case EVENT_COMMIT: |
||
| 977 | DisplayPanel (ph); |
||
| 978 | DisplayPanel (p3); |
||
| 979 | break; |
||
| 980 | } |
||
| 981 | return 0; |
||
| 982 | } |
||
| 983 | |||
| 984 | |||
| 265 | f9daq | 985 | int CVICALLBACK CalibrateCB (int panel, int control, int event, |
| 986 | void *callbackData, int eventData1, int eventData2) { |
||
| 987 | int status = 0; |
||
| 988 | switch (event) { |
||
| 989 | case EVENT_COMMIT: |
||
| 990 | status = DRSCalibrateTiming(); |
||
| 991 | printf("DRSCalibrateTiming() status = %d\n", status); |
||
| 992 | break; |
||
| 993 | } |
||
| 994 | return 0; |
||
| 995 | } |
||
| 317 | f9daq | 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; |
||
| 1154 | } |