Rev 212 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 212 | f9daq | 1 | #include <formatio.h> | 
        
| 2 | #include <cvirte.h> | 
        ||
| 3 | #include <userint.h> | 
        ||
| 4 | #include "AitGui.h" | 
        ||
| 5 | #include "XYSCAN.h" | 
        ||
| 6 | |||
| 7 | #include <stdbool.h> | 
        ||
| 8 | #include "AitInterface.h" | 
        ||
| 9 | #include "AitMduManager_DEF.h" | 
        ||
| 10 | |||
| 11 | #include "H1D.h" | 
        ||
| 12 | #include "H2D.h" | 
        ||
| 13 | #include "H3D.h" | 
        ||
| 14 | |||
| 292 | f9daq | 15 | static int node[3];  | 
        
| 212 | f9daq | 16 | typedef unsigned short ushort;  | 
        
| 17 | typedef unsigned int uint;  | 
        ||
| 18 | |||
| 19 | static int ait;  | 
        ||
| 20 | static int xyscan;  | 
        ||
| 21 | //#define MIKRO | 
        ||
| 22 | |||
| 23 | #ifdef MIKRO | 
        ||
| 24 | #include "MIKRO.h" | 
        ||
| 25 | #endif | 
        ||
| 26 | |||
| 292 | f9daq | 27 | #define uSMC_USB | 
        
| 28 | #ifdef uSMC_USB | 
        ||
| 29 | #  include "uSMC.h" | 
        ||
| 30 | #  define uSMC_SERIAL_X "0000000000004925" | 
        ||
| 31 | #  define uSMC_SERIAL_Y "0000000000006030" | 
        ||
| 32 | #  define uSMC_SERIAL_Z "0000000000002894" | 
        ||
| 33 | const char serials[3][16]= {uSMC_SERIAL_X,uSMC_SERIAL_Y,uSMC_SERIAL_Z};  | 
        ||
| 34 | #endif /* uSMC_USB */ | 
        ||
| 35 | |||
| 212 | f9daq | 36 | static int daq_on;  | 
        
| 37 | static int plothandle[4]= {0,0,0, 0};  | 
        ||
| 38 | static int tfID;  | 
        ||
| 39 | static int controlID;  | 
        ||
| 40 | static int verbose;  | 
        ||
| 41 | |||
| 42 | #define MAX_THREADS 10 | 
        ||
| 43 | |||
| 44 | static CmtThreadPoolHandle poolHandle = 0;  | 
        ||
| 45 | |||
| 46 | |||
| 47 | /* | 
        ||
| 48 | |||
| 49 | x: 140000 280000 | 
        ||
| 50 | |||
| 51 | */ | 
        ||
| 52 | |||
| 53 | //**************************** missing declarations in the library | 
        ||
| 54 | char strbuf[0xFF];  | 
        ||
| 55 | |||
| 56 | int gLog=0;  | 
        ||
| 57 | |||
| 58 | int printf(const char *format, ...) {  | 
        ||
| 59 |   va_list aptr; | 
        ||
| 60 | int ret;  | 
        ||
| 61 | FILE *flog;  | 
        ||
| 62 | |||
| 63 | va_start(aptr, format);  | 
        ||
| 64 | ret = vsprintf(strbuf, format, aptr);  | 
        ||
| 65 | va_end(aptr);  | 
        ||
| 66 | SetCtrlVal(ait,AIT_STDIO,strbuf);  | 
        ||
| 67 | |||
| 68 | if (gLog) {  | 
        ||
| 69 | flog = fopen ("stdio.log", "a");  | 
        ||
| 70 | fprintf (flog, "%s", strbuf);  | 
        ||
| 71 | fclose (flog);  | 
        ||
| 72 |   } | 
        ||
| 73 | return(ret);  | 
        ||
| 74 | } | 
        ||
| 75 | |||
| 76 | |||
| 77 | |||
| 78 | static int timeout=0;  | 
        ||
| 79 | int CVICALLBACK SetTimeoutCB (int panel, int control, int event,  | 
        ||
| 80 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 81 | switch (event) {  | 
        ||
| 82 | case EVENT_TIMER_TICK:  | 
        ||
| 83 | timeout=1;  | 
        ||
| 84 | printf("#### Timeout\n");  | 
        ||
| 85 | break;  | 
        ||
| 86 |         } | 
        ||
| 87 | return 0;  | 
        ||
| 88 | } | 
        ||
| 89 | |||
| 90 | |||
| 91 | |||
| 92 | static void start_timer (double tout) {  | 
        ||
| 93 | timeout = 0;  | 
        ||
| 94 | SetCtrlAttribute (ait, AIT_TIMER, ATTR_INTERVAL, tout);  | 
        ||
| 95 | SetCtrlAttribute (ait, AIT_TIMER, ATTR_ENABLED, 1);  | 
        ||
| 96 | } | 
        ||
| 97 | |||
| 98 | static void stop_timer ( void ) {  | 
        ||
| 99 | SetCtrlAttribute (ait, AIT_TIMER, ATTR_ENABLED, 0);  | 
        ||
| 100 |   //DRSSetTimeout(); | 
        ||
| 101 | } | 
        ||
| 102 | |||
| 103 | |||
| 104 | |||
| 105 | void CVICALLBACK EndOfThread ( CmtThreadPoolHandle poolhandle,  | 
        ||
| 106 | CmtThreadFunctionID functionID, unsigned int event,  | 
        ||
| 107 | int value, void *callbackData ) {  | 
        ||
| 108 | |||
| 109 | daq_on=0;  | 
        ||
| 110 |   //SetDimming(0); | 
        ||
| 111 | printf("End of Thread \n");  | 
        ||
| 112 | return ;  | 
        ||
| 113 | |||
| 114 | } | 
        ||
| 115 | |||
| 116 | int AitInit() {  | 
        ||
| 117 | InitializeConnection();  | 
        ||
| 118 | return 0;  | 
        ||
| 119 | } | 
        ||
| 120 | |||
| 121 | |||
| 122 | int AitValidEvent() {  | 
        ||
| 123 | |||
| 124 | return 1;  | 
        ||
| 125 | };  | 
        ||
| 126 | |||
| 127 | int AitToFile(FILE *fp, int n) {  | 
        ||
| 128 | const int bsize=10000 ;  | 
        ||
| 129 | unsigned short a[bsize] ;  | 
        ||
| 130 | unsigned short buffer[2]={0x1};  | 
        ||
| 131 | buffer[1] = (unsigned short)(n*CHANNELS*2);  | 
        ||
| 132 | for (int eventNum = 0; eventNum < n; eventNum++) {  | 
        ||
| 133 | |||
| 134 | for (int channel = 0; channel < CHANNELS; channel++) {  | 
        ||
| 135 | int index = channel+ CHANNELS * eventNum;  | 
        ||
| 136 | if (index<bsize)  | 
        ||
| 137 | a[index] = ExtractAdcData(eventNum, channel);  | 
        ||
| 138 |                 } | 
        ||
| 139 |         } | 
        ||
| 140 | fwrite(buffer, 2*sizeof(short),1,fp);  | 
        ||
| 141 | return fwrite(a, 1,buffer[1],fp);  | 
        ||
| 142 | };  | 
        ||
| 143 | |||
| 144 | int AitFillHistograms(int events) {  | 
        ||
| 145 | ushort rawAdcData = 0;  | 
        ||
| 146 | ushort adcData = 0;  | 
        ||
| 147 | int channelReceived = 0;  | 
        ||
| 148 | int channelExpected = 0;  | 
        ||
| 149 | bool includeSaturated = 0; // cbIncludeSaturated.Checked;  | 
        ||
| 150 | ushort max[CHANNELS];  | 
        ||
| 151 | ushort min[CHANNELS];  | 
        ||
| 152 | ushort average[CHANNELS];  | 
        ||
| 153 | int total[CHANNELS];  | 
        ||
| 154 | for (int i = 0; i < CHANNELS; i++) {  | 
        ||
| 155 | min[i] = 0xFFFF;  | 
        ||
| 156 | max[i] = 0;  | 
        ||
| 157 | total[i] = 0;  | 
        ||
| 158 |   } | 
        ||
| 159 | |||
| 160 | double threshold, xysumcut;  | 
        ||
| 161 | GetCtrlVal (ait, AIT_ADCTHRESHOLD, &threshold);  | 
        ||
| 162 | GetCtrlVal (ait, AIT_XYCUT, &xysumcut);  | 
        ||
| 163 | |||
| 164 | for (int eventNum = 0; eventNum < events; eventNum++) {  | 
        ||
| 165 | |||
| 166 | int sum = 0;  | 
        ||
| 167 | double a[4]= {0,0,0,0} ;  | 
        ||
| 168 | for (int channel = 0; channel < CHANNELS; channel++) {  | 
        ||
| 169 | |||
| 170 | rawAdcData = ExtractAdcData(eventNum, channel);  | 
        ||
| 171 | if (addChannelNum == true) {  | 
        ||
| 172 | channelReceived = (rawAdcData >> 12) & 0xF;  | 
        ||
| 173 | channelExpected = (channel & 0xF);  | 
        ||
| 174 | if (channelReceived != channelExpected) {  | 
        ||
| 175 | |||
| 176 | AddMessage("ERROR in Event %d : Expected channel %d, received %d -ANALYSIS STOPPED", eventNum, channelExpected, channelReceived);  | 
        ||
| 177 | |||
| 178 |           //EnableRegisterScanTimer(true); | 
        ||
| 179 | return eventNum;  | 
        ||
| 180 |         } | 
        ||
| 181 |       } | 
        ||
| 182 | adcData = (ushort)(rawAdcData & 0x0FFF); // remove channel number  | 
        ||
| 183 |       //if ((includeSaturated == true) || ((includeSaturated == false) && (adcData < (ADCMAX - 2)))) | 
        ||
| 184 | |||
| 185 | if (adcData>threshold) H1D_Fill(channel, adcData,1);  | 
        ||
| 186 | a[channel]=adcData;  | 
        ||
| 187 | total[channel] = total[channel] + adcData;  | 
        ||
| 188 | if (adcData > max[channel])  | 
        ||
| 189 | max[channel] = adcData;  | 
        ||
| 190 | else if (adcData < min[channel])  | 
        ||
| 191 | min[channel] = adcData;  | 
        ||
| 192 | |||
| 193 | sum += adcData;  | 
        ||
| 194 |     } | 
        ||
| 195 | if (sum>threshold) {  | 
        ||
| 196 | H1D_Fill(10, sum, 1 );  | 
        ||
| 197 | double x = a[0]/(a[0]+a[1]);  | 
        ||
| 198 | double y = a[2]/(a[2]+a[3]);  | 
        ||
| 199 | if (sum>xysumcut) H2D_Fill(0, x, y , 1 );  | 
        ||
| 200 |     } | 
        ||
| 201 |     histogramTotalEvents++; | 
        ||
| 202 |   } | 
        ||
| 203 |   //tbAdcStatistics.Clear(); | 
        ||
| 204 | for (int channel = 0; channel < CHANNELS; channel++) {  | 
        ||
| 205 | average[channel] = (ushort)(total[channel] / events);  | 
        ||
| 206 | |||
| 207 | if (verbose) AddMessage(" {channel:%d} : {min:0x%d} {max:0x%d} {max-min:%d} {average:%d}\n", channel + 1, min[channel], max[channel], max[channel] - min[channel], average[channel]);  | 
        ||
| 208 |     //if (channel < (CHANNELS - 1)) | 
        ||
| 209 |     //    tbAdcStatistics.AppendText(Environment.NewLine); | 
        ||
| 210 | |||
| 211 |   } | 
        ||
| 212 |   //SetTextboxToTop(tbAdcStatistics); | 
        ||
| 213 | return 1;  | 
        ||
| 214 | };  | 
        ||
| 215 | |||
| 216 | |||
| 217 | int CVICALLBACK RefreshGraphs (int panel, int control, int event,  | 
        ||
| 218 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 219 | switch (event) {  | 
        ||
| 220 | case EVENT_TIMER_TICK:  | 
        ||
| 221 | //      if (!daq_on ) return 0; | 
        ||
| 222 | case EVENT_COMMIT: {  | 
        ||
| 223 | |||
| 224 | int ch=0;  | 
        ||
| 225 | int logy=0;  | 
        ||
| 226 | int updateplots=0;  | 
        ||
| 227 | GetCtrlVal(ait,AIT_CH, &ch);  | 
        ||
| 228 | GetCtrlVal(ait,AIT_LOGY, &logy);  | 
        ||
| 229 | GetCtrlVal(ait,AIT_UPDATEPLOTS, &updateplots);  | 
        ||
| 230 | if (!updateplots) return 0;  | 
        ||
| 231 | if (logy){  | 
        ||
| 232 | SetCtrlAttribute (ait, AIT_GRAPH, ATTR_YMAP_MODE, VAL_LOG);  | 
        ||
| 233 | SetCtrlAttribute (ait, AIT_GRAPHSUM, ATTR_YMAP_MODE, VAL_LOG);  | 
        ||
| 234 | |||
| 235 | } else {  | 
        ||
| 236 | SetCtrlAttribute (ait, AIT_GRAPH, ATTR_YMAP_MODE, VAL_LINEAR);  | 
        ||
| 237 | SetCtrlAttribute (ait, AIT_GRAPHSUM, ATTR_YMAP_MODE, VAL_LINEAR);  | 
        ||
| 238 | |||
| 239 |                         } | 
        ||
| 240 | H1D_Draw(ch,ait,AIT_GRAPH,&plothandle[0]);  | 
        ||
| 241 | H1D_Draw(10,ait,AIT_GRAPHSUM,&plothandle[1]);  | 
        ||
| 242 | H2D_Draw(0,ait,AIT_GRAPHXY,&plothandle[2]);  | 
        ||
| 243 | |||
| 244 | |||
| 245 |     } | 
        ||
| 246 | |||
| 247 | |||
| 248 | break;  | 
        ||
| 249 | |||
| 250 |   } | 
        ||
| 251 | return 0;  | 
        ||
| 252 | } | 
        ||
| 253 | |||
| 254 | |||
| 255 | |||
| 256 | int CVICALLBACK daq(void *functionData) {  | 
        ||
| 257 | |||
| 258 | |||
| 259 | int neve;  | 
        ||
| 260 | char filename[0xff];  | 
        ||
| 261 | char fname[0xff];  | 
        ||
| 262 | char pname[0xff];  | 
        ||
| 263 | |||
| 264 | |||
| 265 | |||
| 266 | int pfreq;  | 
        ||
| 267 | int enabledoutput;  | 
        ||
| 268 | int neveold = 0;  | 
        ||
| 269 | double rate;  | 
        ||
| 270 | int *args = (int *) functionData;  | 
        ||
| 271 | |||
| 272 | GetCtrlVal(ait, AIT_FILENAME, fname );  | 
        ||
| 273 | GetCtrlVal(ait, AIT_PATHNAME, pname );  | 
        ||
| 274 | sprintf(filename,"%s/%s", pname, fname);  | 
        ||
| 275 | |||
| 276 | GetCtrlVal(ait,AIT_NEVE, &neve);  | 
        ||
| 277 | GetCtrlVal(ait,AIT_DEBUG, &verbose);  | 
        ||
| 278 | GetCtrlVal(ait,AIT_PFREQ, &pfreq);  | 
        ||
| 279 | GetCtrlVal(ait,AIT_ENABLEDOUTPUT, &enabledoutput);  | 
        ||
| 280 | |||
| 281 | |||
| 282 | int range=0;  | 
        ||
| 283 | int nch = range;  | 
        ||
| 284 | GetCtrlVal(ait,AIT_MAX, &range);  | 
        ||
| 285 | if (range>512) nch = 512;  | 
        ||
| 286 | |||
| 287 | |||
| 288 | for (int i=0; i<4; i++) {  | 
        ||
| 289 | char name[0xFF];  | 
        ||
| 290 | sprintf(name,"adc%d", i);  | 
        ||
| 291 | |||
| 292 | H1D_Init(i, name,name, range, 0 , range);  | 
        ||
| 293 | H1D_SetTitleX(0,"ADC");  | 
        ||
| 294 | H1D_SetTitleY(0,"N");  | 
        ||
| 295 |   } | 
        ||
| 296 | H1D_Init(10, "adcsum","adcsum", range, 0 , 4*range);  | 
        ||
| 297 | H1D_SetTitleX(0,"ADC");  | 
        ||
| 298 | H1D_SetTitleY(0,"N");  | 
        ||
| 299 | |||
| 300 | H2D_Init(0, "cog","Center of gravity", 256, 0 ,1, 256, 0 ,1);  | 
        ||
| 301 | H2D_SetTitleX(0,"x");  | 
        ||
| 302 | H2D_SetTitleY(0,"y");  | 
        ||
| 303 | |||
| 304 | |||
| 305 | |||
| 306 | FILE *fp= NULL;  | 
        ||
| 307 | |||
| 308 | if (enabledoutput) {  | 
        ||
| 309 | if (args[0]) fp = fopen(filename,"wb");  | 
        ||
| 310 | else fp = fopen(filename,"ab");  | 
        ||
| 311 |   } | 
        ||
| 312 | |||
| 313 | |||
| 314 | |||
| 315 | |||
| 316 | |||
| 317 | time_t t=0,told=0, tstart=0;  | 
        ||
| 318 | |||
| 319 | if (!AitInit()) {  | 
        ||
| 320 | |||
| 321 | |||
| 322 | ReadRegisters();  | 
        ||
| 323 | |||
| 324 | |||
| 325 |       // Update UI | 
        ||
| 326 | int csrDetector = ReadSD4Register(ADDR_CSR_DETECTOR);  | 
        ||
| 327 | |||
| 328 | int value = ((GetBit(csrDetector, BIT_CSR_DET_ADCGAIN2) ? 1 : 0) << 1) |  | 
        ||
| 329 | ((GetBit(csrDetector, BIT_CSR_DET_ADCGAIN1) ? 1 : 0) << 0);  | 
        ||
| 330 | SetCtrlVal (ait, AIT_GETADCGAIN, value);  | 
        ||
| 331 | double valued = GetThreshold();  | 
        ||
| 332 | SetCtrlVal (ait, AIT_GETADCTHRESHOLD, valued);  | 
        ||
| 333 | valued = GetIntegrationTime();  | 
        ||
| 334 | SetCtrlVal (ait, AIT_GETADCINTEGRATIONTIME, valued);  | 
        ||
| 335 | valued = GetHvVoltage(ADDR_HV_VMON);  | 
        ||
| 336 | SetCtrlVal (ait, AIT_BIASMON, valued);  | 
        ||
| 337 | |||
| 338 |                         value = | 
        ||
| 339 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN4) ? 1 : 0) << 3) |  | 
        ||
| 340 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN3) ? 1 : 0) << 2) |  | 
        ||
| 341 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN2) ? 1 : 0) << 1) |  | 
        ||
| 342 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN1) ? 1 : 0) << 0);  | 
        ||
| 343 | SetCtrlVal (ait, AIT_GETADCSUMGAIN, value);  | 
        ||
| 344 | |||
| 345 | |||
| 346 | |||
| 347 | RefreshGraphs (ait, 0 , EVENT_COMMIT ,NULL, 0, 0 );  | 
        ||
| 348 | |||
| 349 | daq_on=1;  | 
        ||
| 350 |                 //RefreshGraphs (ait, 0 , EVENT_TIMER_TICK ,NULL, 0, 0 );     | 
        ||
| 351 | time(&tstart);  | 
        ||
| 352 | told=tstart;  | 
        ||
| 353 | int i=0;  | 
        ||
| 354 | for (i=0; i<neve; i++) {  | 
        ||
| 355 | start_timer(1);// 1 s timeout  | 
        ||
| 356 |       // Set ADC reset | 
        ||
| 357 | ResetAdc(true);  | 
        ||
| 358 |       // Clear ADC reset | 
        ||
| 359 | ResetAdc(false);  | 
        ||
| 360 | int eventsAcquired = Acquire(pfreq);  | 
        ||
| 361 | stop_timer();  | 
        ||
| 362 | if (!daq_on) break;  | 
        ||
| 363 | if (timeout) {  | 
        ||
| 364 |                            i--; | 
        ||
| 365 | printf("INFO Timeout\n");  | 
        ||
| 366 | continue;  | 
        ||
| 367 |                         } | 
        ||
| 368 | int isvalid =1;  | 
        ||
| 369 | if (eventsAcquired < 1) {  | 
        ||
| 370 | printf("Acquired events %d\n", eventsAcquired);  | 
        ||
| 371 | isvalid = 0;  | 
        ||
| 372 | } else {  | 
        ||
| 373 | AitFillHistograms(eventsAcquired);  | 
        ||
| 374 | if (verbose) ShowEvent(1);  | 
        ||
| 375 |       } | 
        ||
| 376 | |||
| 377 | int nb = ( isvalid && fp ) ? AitToFile( fp , pfreq ) : 0;  | 
        ||
| 378 | SetCtrlVal(ait,AIT_CEVE,i);  | 
        ||
| 379 | if (!isvalid) i--;  | 
        ||
| 380 | |||
| 381 | time(&t);  | 
        ||
| 382 | if (t!=told ) {  | 
        ||
| 383 | rate = (i-neveold);  | 
        ||
| 384 | printf("%d events in %2.2f min (%d s) Rate %f Hz %s ",i+1, (double)(t-tstart)/60.,(t-tstart), rate , ctime(&t));  | 
        ||
| 385 | neveold = i;  | 
        ||
| 386 | RefreshGraphs (ait, 0 , EVENT_COMMIT ,NULL, 0, 0 );  | 
        ||
| 387 | double daqBlocksize = GetAdcEventSize() * pfreq * 2.0;  | 
        ||
| 388 | double daqTimeMs = BlockTransferTime();  | 
        ||
| 389 | double daqTransferRate = daqBlocksize / daqTimeMs;  | 
        ||
| 390 | SetCtrlVal(ait,AIT_DAQBLOCKSIZE, daqBlocksize);  | 
        ||
| 391 | SetCtrlVal(ait,AIT_DAQTIMEMS,daqTimeMs);  | 
        ||
| 392 | SetCtrlVal(ait,AIT_DAQTRANSFERRATE,daqTransferRate);  | 
        ||
| 393 |       } | 
        ||
| 394 | told=t;  | 
        ||
| 395 | |||
| 396 | |||
| 397 | |||
| 398 |     } | 
        ||
| 399 | time(&t);  | 
        ||
| 400 | printf("%d events in %2.2f min (%d s) %s",i+1, (double)(t-tstart)/60.,t-tstart, ctime(&t));  | 
        ||
| 401 | |||
| 402 |   } | 
        ||
| 403 | |||
| 404 | if (fp) fclose(fp);  | 
        ||
| 405 | |||
| 406 | |||
| 407 | RefreshGraphs (ait, 0 , EVENT_TIMER_TICK ,NULL, 0, 0 );  | 
        ||
| 408 | return 0;  | 
        ||
| 409 | |||
| 410 | } | 
        ||
| 411 | |||
| 412 | |||
| 413 | int CVICALLBACK scan(void *functionData) {  | 
        ||
| 414 | |||
| 415 | int dx[3]={0,0,0};  | 
        ||
| 416 | int nx[3]={0,0,0};  | 
        ||
| 417 | int x0[3]={0,0,0};  | 
        ||
| 418 | int ix[3]={0,0,0};  | 
        ||
| 419 | int idx[3]={0,0,0};  | 
        ||
| 420 | unsigned short size;  | 
        ||
| 421 | unsigned short posrec={0x2};  | 
        ||
| 422 | unsigned short runbuf={0x3};  | 
        ||
| 423 | |||
| 424 | int n[3];  | 
        ||
| 425 | char filename[0xFF];  | 
        ||
| 426 | char fname[0xff];  | 
        ||
| 427 | char pname[0xff];  | 
        ||
| 428 | int enabledoutput;  | 
        ||
| 429 | |||
| 430 | FILE *fp;  | 
        ||
| 431 | GetCtrlVal(ait, AIT_FILENAME, fname );  | 
        ||
| 432 | GetCtrlVal(ait, AIT_PATHNAME, pname );  | 
        ||
| 433 | sprintf(filename,"%s/%s", pname, fname);  | 
        ||
| 434 | |||
| 435 | GetCtrlVal(ait,AIT_ENABLEDOUTPUT, &enabledoutput);  | 
        ||
| 436 | int fsize;  | 
        ||
| 437 | if ( GetFileInfo(filename,&fsize) ) {  | 
        ||
| 438 | MessagePopup ("Warning", "File exist. Remove it first or choose another file");  | 
        ||
| 439 | return 0;  | 
        ||
| 440 |         }         | 
        ||
| 441 | GetCtrlVal(xyscan, SCAN_STEPX, &dx[0]);  | 
        ||
| 442 | GetCtrlVal(xyscan, SCAN_STEPY, &dx[1]);  | 
        ||
| 443 | GetCtrlVal(xyscan, SCAN_NSTEPSX, &nx[0]);  | 
        ||
| 444 | GetCtrlVal(xyscan, SCAN_NSTEPSY, &nx[1]);  | 
        ||
| 445 | GetCtrlVal(xyscan, SCAN_STARTX, &x0[0]);  | 
        ||
| 446 | GetCtrlVal(xyscan, SCAN_STARTY, &x0[1]);  | 
        ||
| 447 | |||
| 448 | |||
| 449 | if (enabledoutput) {  | 
        ||
| 450 | fp = fopen(filename,"ab");  | 
        ||
| 451 | if (fp) {  | 
        ||
| 452 | size=36;  | 
        ||
| 453 | fwrite(&runbuf, sizeof(unsigned short),1 ,fp);  | 
        ||
| 454 | fwrite(&size , sizeof(unsigned short),1 ,fp);  | 
        ||
| 455 | fwrite(x0 , 1,4*3 ,fp);  | 
        ||
| 456 | fwrite(dx , 1,4*3 ,fp);  | 
        ||
| 457 | fwrite(nx , 1,4*3 ,fp);  | 
        ||
| 458 | fclose(fp);  | 
        ||
| 459 |                                 }     | 
        ||
| 460 |         }       | 
        ||
| 461 | |||
| 462 | for (int j=0; j<nx[1]; j++) {  | 
        ||
| 463 | |||
| 464 | SetCtrlVal (xyscan, SCAN_IY, j);  | 
        ||
| 465 | ix[1]= x0[1]+j*dx[1];  | 
        ||
| 466 | #ifdef MIKRO | 
        ||
| 467 | MIKRO_MoveTo(2,ix[1]);  | 
        ||
| 468 | MIKRO_GetPosition(2,&n[1]);  | 
        ||
| 292 | f9daq | 469 | SetCtrlVal (xyscan, SCAN_YP, n[1]);  | 
        
| 470 | #endif | 
        ||
| 471 | #ifdef uSMC_USB | 
        ||
| 472 | uSMC_MoveTo(node[1],ix[1]);  | 
        ||
| 473 | uSMC_GetPosition(node[1],&n[1]);  | 
        ||
| 474 | SetCtrlVal (xyscan, SCAN_YP, n[1]);  | 
        ||
| 475 | #endif | 
        ||
| 476 | |||
| 212 | f9daq | 477 | |
| 292 | f9daq | 478 | |
| 212 | f9daq | 479 | for (int i=0; i<nx[0]; i++) {  | 
        
| 480 | SetCtrlVal (xyscan, SCAN_IX, i);  | 
        ||
| 481 | ix[0]= x0[0]+i*dx[0];  | 
        ||
| 482 | #ifdef MIKRO | 
        ||
| 292 | f9daq | 483 | MIKRO_MoveTo(1,ix[0]);  | 
        
| 212 | f9daq | 484 | MIKRO_GetPosition(1,&n[0]);  | 
        
| 485 | SetCtrlVal (xyscan, SCAN_XP, n[0]);  | 
        ||
| 292 | f9daq | 486 | #endif           | 
        
| 487 | #ifdef uSMC_USB | 
        ||
| 488 | uSMC_MoveTo(node[0],ix[0]);  | 
        ||
| 489 | uSMC_GetPosition(node[0],&n[0]);  | 
        ||
| 490 | SetCtrlVal (xyscan, SCAN_XP, n[0]);  | 
        ||
| 491 | #endif                   | 
        ||
| 212 | f9daq | 492 | |
| 493 | if (enabledoutput) {  | 
        ||
| 494 | fp = fopen(filename,"ab");  | 
        ||
| 495 | if (fp) {  | 
        ||
| 496 |                                          time_t mtime; | 
        ||
| 497 | idx[0]=i;  | 
        ||
| 498 | idx[1]=j;  | 
        ||
| 499 | size=24+sizeof(mtime);  | 
        ||
| 500 | fwrite(&posrec, sizeof(unsigned short),1 ,fp);  | 
        ||
| 501 | fwrite(&size , sizeof(unsigned short),1 ,fp);  | 
        ||
| 502 | fwrite(n , 1,4*3 ,fp);  | 
        ||
| 503 | fwrite(idx , 1,4*3 ,fp);  | 
        ||
| 504 | time(&mtime);  | 
        ||
| 505 | fwrite(&mtime , sizeof(time_t),1 ,fp);  | 
        ||
| 506 | fclose(fp);  | 
        ||
| 507 |                                 }     | 
        ||
| 508 |                         }       | 
        ||
| 509 | |||
| 292 | f9daq | 510 | |
| 212 | f9daq | 511 | int newfile=0;  | 
        
| 512 | daq(&newfile);  | 
        ||
| 513 | if (!daq_on) break;  | 
        ||
| 514 |                 } | 
        ||
| 515 | if (!daq_on) break;  | 
        ||
| 516 |         } | 
        ||
| 517 | |||
| 518 | return 0;  | 
        ||
| 519 | } | 
        ||
| 520 | |||
| 521 | |||
| 522 | int main (int argc, char *argv[]) {  | 
        ||
| 292 | f9daq | 523 | |
| 212 | f9daq | 524 | if (InitCVIRTE (0, argv, 0) == 0)  | 
        
| 525 | return -1; /* out of memory */  | 
        ||
| 526 | if ((ait = LoadPanel (0, "AitGui.uir", AIT)) < 0)  | 
        ||
| 527 | return -1;  | 
        ||
| 528 | if ((xyscan = LoadPanel (0, "XYSCAN.uir", SCAN)) < 0)  | 
        ||
| 529 | return -1;  | 
        ||
| 530 | SetStdioPort (CVI_STDIO_WINDOW);  | 
        ||
| 531 | SetSleepPolicy(VAL_SLEEP_MORE);  | 
        ||
| 532 | CmtNewThreadPool (MAX_THREADS, &poolHandle);  | 
        ||
| 533 | DisplayPanel (ait);  | 
        ||
| 534 | DisplayPanel (xyscan);  | 
        ||
| 535 | AitInit();  | 
        ||
| 536 | |||
| 537 | |||
| 538 | #ifdef MIKRO | 
        ||
| 292 | f9daq | 539 | short port;  | 
        
| 540 | GetCtrlVal(xyscan, SCAN_PORT, &port);  | 
        ||
| 212 | f9daq | 541 | if (MIKRO_Open (port)) MessagePopup ("Error", "Mikro Port Not found !\n Change in the GUI") ;  | 
        
| 542 | MIKRO_Init(1,0);  | 
        ||
| 543 | MIKRO_Init(2,0);  | 
        ||
| 544 | #endif | 
        ||
| 292 | f9daq | 545 | #ifdef uSMC_USB | 
        
| 546 | uSMC_Open();  | 
        ||
| 547 | for (int i=0; i<3; i++) {  | 
        ||
| 548 | node[i]=uSMC_FindSerial(serials[i])+1;  | 
        ||
| 549 | uSMC_Init(node[i],1);  | 
        ||
| 550 |   } | 
        ||
| 551 | #endif /* uSMC_USB */    | 
        ||
| 212 | f9daq | 552 | |
| 553 | |||
| 554 | RunUserInterface ();  | 
        ||
| 555 | |||
| 556 | #ifdef MIKRO     | 
        ||
| 557 | MIKRO_Close ();  | 
        ||
| 292 | f9daq | 558 | #endif  | 
        
| 559 | #ifdef uSMC_USB | 
        ||
| 560 | for (int i=0; i<3; i++) uSMC_PowerOff(node[i]);  | 
        ||
| 561 | uSMC_Close();  | 
        ||
| 562 | #endif /* uSMC_USB */    | 
        ||
| 212 | f9daq | 563 | DiscardPanel (ait);  | 
        
| 564 | DiscardPanel (xyscan);  | 
        ||
| 565 | return 0;  | 
        ||
| 566 | } | 
        ||
| 567 | |||
| 568 | int CVICALLBACK StopCB (int panel, int control, int event,  | 
        ||
| 569 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 570 | switch (event) {  | 
        ||
| 571 | case EVENT_COMMIT:  | 
        ||
| 572 | daq_on=0;  | 
        ||
| 573 | break;  | 
        ||
| 574 |   } | 
        ||
| 575 | return 0;  | 
        ||
| 576 | } | 
        ||
| 577 | |||
| 578 | |||
| 579 | int CVICALLBACK StartCB (int panel, int control, int event,  | 
        ||
| 580 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 581 | ThreadFunctionPtr mythread = NULL;  | 
        ||
| 582 | switch (event) {  | 
        ||
| 583 | |||
| 584 | case EVENT_COMMIT:  | 
        ||
| 585 | |||
| 586 | controlID= control;  | 
        ||
| 587 | if (panel == ait && control == AIT_START) {  | 
        ||
| 588 | mythread = daq;  | 
        ||
| 589 | |||
| 590 |       } | 
        ||
| 591 | if (panel == xyscan && control == SCAN_SCAN) mythread = scan;  | 
        ||
| 592 | if (mythread!=NULL) {  | 
        ||
| 593 | printf("New Thread panel=%d button=%d\n", panel, control);  | 
        ||
| 594 | |||
| 595 |         // SetDimming(1); | 
        ||
| 596 | |||
| 597 | |||
| 598 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &controlID,  | 
        ||
| 599 |                                           DEFAULT_THREAD_PRIORITY, | 
        ||
| 600 |                                           EndOfThread, | 
        ||
| 601 |                                           EVENT_TP_THREAD_FUNCTION_END, | 
        ||
| 602 | NULL, RUN_IN_SCHEDULED_THREAD,  | 
        ||
| 603 | &tfID);  | 
        ||
| 604 |       } | 
        ||
| 605 | break;  | 
        ||
| 606 |   } | 
        ||
| 607 | return 0;  | 
        ||
| 608 | } | 
        ||
| 609 | |||
| 610 | |||
| 611 | |||
| 612 | int CVICALLBACK ExitCB (int panel, int control, int event,  | 
        ||
| 613 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 614 | switch (event) {  | 
        ||
| 615 | case EVENT_COMMIT:  | 
        ||
| 616 | QuitUserInterface (0);  | 
        ||
| 617 | break;  | 
        ||
| 618 |   } | 
        ||
| 619 | return 0;  | 
        ||
| 620 | } | 
        ||
| 621 | |||
| 622 | int CVICALLBACK ReadCB (int panel, int control, int event,  | 
        ||
| 623 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 624 | switch (event) {  | 
        ||
| 625 | case EVENT_COMMIT:  | 
        ||
| 626 | |||
| 627 | |||
| 628 | |||
| 629 | ReadRegisters();  | 
        ||
| 630 | break;  | 
        ||
| 631 |   } | 
        ||
| 632 | return 0;  | 
        ||
| 633 | } | 
        ||
| 634 | |||
| 635 | int CVICALLBACK ChangeChannelCB (int panel, int control, int event,  | 
        ||
| 636 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 637 | int ch=0;  | 
        ||
| 638 | switch (event) {  | 
        ||
| 639 | case EVENT_COMMIT:  | 
        ||
| 640 | |||
| 641 | int logy=0;  | 
        ||
| 642 | GetCtrlVal(ait,AIT_CH, &ch);  | 
        ||
| 643 | GetCtrlVal(ait,AIT_LOGY, &logy);  | 
        ||
| 644 | if (logy){  | 
        ||
| 645 | SetCtrlAttribute (ait, AIT_GRAPH, ATTR_YMAP_MODE, VAL_LOG);  | 
        ||
| 646 | SetCtrlAttribute (ait, AIT_GRAPHSUM, ATTR_YMAP_MODE, VAL_LOG);  | 
        ||
| 647 | |||
| 648 | } else {  | 
        ||
| 649 | SetCtrlAttribute (ait, AIT_GRAPH, ATTR_YMAP_MODE, VAL_LINEAR);  | 
        ||
| 650 | SetCtrlAttribute (ait, AIT_GRAPHSUM, ATTR_YMAP_MODE, VAL_LINEAR);  | 
        ||
| 651 | |||
| 652 |                         } | 
        ||
| 653 | H1D_Draw(ch,ait,AIT_GRAPH,&plothandle[0]);  | 
        ||
| 654 | break;  | 
        ||
| 655 |   } | 
        ||
| 656 | return 0;  | 
        ||
| 657 | } | 
        ||
| 658 | |||
| 659 | |||
| 660 | |||
| 661 | |||
| 662 | |||
| 663 | int CVICALLBACK InitCB (int panel, int control, int event,  | 
        ||
| 664 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 665 | switch (event) {  | 
        ||
| 666 | case EVENT_COMMIT:  | 
        ||
| 667 | AitInit();  | 
        ||
| 668 | break;  | 
        ||
| 669 |   } | 
        ||
| 670 | return 0;  | 
        ||
| 671 | } | 
        ||
| 672 | |||
| 673 | int CVICALLBACK QuickCB (int panel, int control, int event,  | 
        ||
| 674 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 675 | switch (event) {  | 
        ||
| 676 | case EVENT_COMMIT:  | 
        ||
| 677 | switch (control) {  | 
        ||
| 678 | case AIT_QUICKSETUP_1:  | 
        ||
| 679 | QuickSetupContinuous();  | 
        ||
| 680 | SetCtrlVal(ait,AIT_TRGTYPE, 0);  | 
        ||
| 681 | break;  | 
        ||
| 682 | case AIT_QUICKSETUP_2:  | 
        ||
| 683 | QuickSetupDiscriminator();  | 
        ||
| 684 | SetCtrlVal(ait,AIT_TRGTYPE, 2);  | 
        ||
| 685 | break;  | 
        ||
| 686 | case AIT_QUICKSETUP_3:  | 
        ||
| 687 | QuickSetupTriggerOff();  | 
        ||
| 688 | break;  | 
        ||
| 689 | |||
| 690 | |||
| 691 |       } | 
        ||
| 692 | float bias = GetHvVoltage(ADDR_HV_VMON);  | 
        ||
| 693 | SetCtrlVal (panel, AIT_BIASMON, bias);  | 
        ||
| 694 | double value = GetIntegrationTime();  | 
        ||
| 695 | SetCtrlVal (panel, AIT_GETADCINTEGRATIONTIME, value);  | 
        ||
| 696 | value = GetThreshold();  | 
        ||
| 697 | SetCtrlVal (panel, AIT_GETADCTHRESHOLD, value);  | 
        ||
| 698 | int csrDetector = ReadSD4Register(ADDR_CSR_DETECTOR);  | 
        ||
| 699 | |||
| 700 | int ivalue = ((GetBit(csrDetector, BIT_CSR_DET_ADCGAIN2) ? 1 : 0) << 1) |  | 
        ||
| 701 | ((GetBit(csrDetector, BIT_CSR_DET_ADCGAIN1) ? 1 : 0) << 0);  | 
        ||
| 702 | SetCtrlVal (panel, AIT_GETADCGAIN, ivalue);  | 
        ||
| 703 |                         ivalue = | 
        ||
| 704 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN4) ? 1 : 0) << 3) |  | 
        ||
| 705 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN3) ? 1 : 0) << 2) |  | 
        ||
| 706 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN2) ? 1 : 0) << 1) |  | 
        ||
| 707 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN1) ? 1 : 0) << 0);  | 
        ||
| 708 | SetCtrlVal (panel, AIT_GETADCSUMGAIN, ivalue);  | 
        ||
| 709 | break;  | 
        ||
| 710 |   } | 
        ||
| 711 | return 0;  | 
        ||
| 712 | } | 
        ||
| 713 | |||
| 714 | |||
| 715 | |||
| 716 | int CVICALLBACK MoveStageCB (int panel, int control, int event,  | 
        ||
| 717 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 718 | int axis=0, step=1000, direction=1;  | 
        ||
| 719 | switch (event) {  | 
        ||
| 720 | case EVENT_COMMIT:  | 
        ||
| 721 | |||
| 722 | if (panel == xyscan) {  | 
        ||
| 723 | switch (control) {  | 
        ||
| 724 | case SCAN_BR :  | 
        ||
| 725 | axis = 1;  | 
        ||
| 726 | direction = 1;  | 
        ||
| 727 | GetCtrlVal(panel, SCAN_STEPX, &step);  | 
        ||
| 728 | break;  | 
        ||
| 729 | case SCAN_BL :  | 
        ||
| 730 | axis = 1;  | 
        ||
| 731 | direction = -1;  | 
        ||
| 732 | GetCtrlVal(panel, SCAN_STEPX, &step);  | 
        ||
| 733 | break;  | 
        ||
| 734 | case SCAN_BU :  | 
        ||
| 735 | axis = 2;  | 
        ||
| 736 | direction = 1;  | 
        ||
| 737 | GetCtrlVal(panel, SCAN_STEPY, &step);  | 
        ||
| 738 | break;  | 
        ||
| 739 | case SCAN_BD :  | 
        ||
| 740 | axis = 2;  | 
        ||
| 741 | direction = -1;  | 
        ||
| 742 | GetCtrlVal(panel, SCAN_STEPY, &step);  | 
        ||
| 743 | break;  | 
        ||
| 744 |         } | 
        ||
| 745 | #ifdef MIKRO | 
        ||
| 746 |         { | 
        ||
| 747 | int n=0;  | 
        ||
| 748 | MIKRO_MoveFor(axis, direction*step );  | 
        ||
| 749 | MIKRO_GetPosition(axis,&n);  | 
        ||
| 750 | if (axis == 1) SetCtrlVal (panel, SCAN_XP, n);  | 
        ||
| 751 | if (axis == 2) SetCtrlVal (panel, SCAN_YP, n);  | 
        ||
| 752 |         } | 
        ||
| 292 | f9daq | 753 | #endif // MIKRO   | 
        
| 754 | |||
| 755 | #ifdef uSMC_USB | 
        ||
| 756 |         { | 
        ||
| 757 | int n=0;  | 
        ||
| 758 | uSMC_MoveFor(node[axis-1], direction*step );  | 
        ||
| 759 | uSMC_GetPosition(node[axis-1],&n);  | 
        ||
| 760 | if (axis == 1) SetCtrlVal (panel, SCAN_XP, n);  | 
        ||
| 761 | if (axis == 2) SetCtrlVal (panel, SCAN_YP, n);  | 
        ||
| 762 |         } | 
        ||
| 763 | #endif // MIKRO                  | 
        ||
| 212 | f9daq | 764 |       } | 
        
| 765 | |||
| 766 | break;  | 
        ||
| 767 |   } | 
        ||
| 768 | return 0;  | 
        ||
| 769 | } | 
        ||
| 770 | |||
| 771 | |||
| 772 | |||
| 773 | |||
| 774 | |||
| 775 | int CVICALLBACK GoXCB (int panel, int control, int event,  | 
        ||
| 776 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 777 | int n2;  | 
        ||
| 778 | switch (event) {  | 
        ||
| 779 | case EVENT_COMMIT:  | 
        ||
| 780 | GetCtrlVal (panel, SCAN_XG, &n2);  | 
        ||
| 781 | #ifdef MIKRO | 
        ||
| 782 | MIKRO_MoveTo(1,n2);  | 
        ||
| 783 | MIKRO_GetPosition(1,&n2);  | 
        ||
| 784 | #endif | 
        ||
| 292 | f9daq | 785 | #ifdef uSMC_USB   | 
        
| 786 | uSMC_MoveTo(node[0],n2);  | 
        ||
| 787 | uSMC_GetPosition(node[0],&n2);  | 
        ||
| 788 | #endif     | 
        ||
| 789 | |||
| 212 | f9daq | 790 | SetCtrlVal (panel, SCAN_XP, n2);  | 
        
| 791 | break;  | 
        ||
| 792 |   } | 
        ||
| 793 | return 0;  | 
        ||
| 794 | } | 
        ||
| 795 | |||
| 796 | int CVICALLBACK GoYCB (int panel, int control, int event,  | 
        ||
| 797 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 798 | int n2;  | 
        ||
| 799 | switch (event) {  | 
        ||
| 800 | case EVENT_COMMIT:  | 
        ||
| 801 | GetCtrlVal (panel, SCAN_YG, &n2);  | 
        ||
| 802 | #ifdef MIKRO | 
        ||
| 803 | MIKRO_MoveTo(2,n2);  | 
        ||
| 804 | MIKRO_GetPosition(2,&n2);  | 
        ||
| 805 | |||
| 806 | #endif | 
        ||
| 292 | f9daq | 807 | #ifdef uSMC_USB   | 
        
| 808 | uSMC_MoveTo(node[1],n2);  | 
        ||
| 809 | uSMC_GetPosition(node[1],&n2);  | 
        ||
| 810 | #endif             | 
        ||
| 212 | f9daq | 811 | SetCtrlVal (panel, SCAN_YP, n2);  | 
        
| 812 | break;  | 
        ||
| 813 |   } | 
        ||
| 814 | return 0;  | 
        ||
| 815 | } | 
        ||
| 816 | |||
| 817 | int CVICALLBACK GetCurrentPositionCB (int panel, int control, int event,  | 
        ||
| 818 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 819 | |||
| 292 | f9daq | 820 | int n[2];  | 
        
| 212 | f9daq | 821 | switch (event) {  | 
        
| 822 | case EVENT_COMMIT: {  | 
        ||
| 823 | #ifdef MIKRO | 
        ||
| 824 | MIKRO_GetPosition(1,&n[0]);  | 
        ||
| 825 | SetCtrlVal (panel, SCAN_XP, n[0]);  | 
        ||
| 826 | MIKRO_GetPosition(2,&n[1]);  | 
        ||
| 827 | SetCtrlVal (panel, SCAN_YP, n[1]);  | 
        ||
| 828 | #endif | 
        ||
| 292 | f9daq | 829 | #ifdef uSMC_USB   | 
        
| 830 | uSMC_GetPosition(node[0],&n[0]);  | 
        ||
| 831 | SetCtrlVal (panel, SCAN_XP, n[0]);  | 
        ||
| 832 | uSMC_GetPosition(node[1],&n[1]);  | 
        ||
| 833 | SetCtrlVal (panel, SCAN_YP, n[1]);  | 
        ||
| 834 | #endif             | 
        ||
| 212 | f9daq | 835 | break;  | 
        
| 836 |     } | 
        ||
| 837 |   } | 
        ||
| 838 | return 0;  | 
        ||
| 839 | } | 
        ||
| 840 | |||
| 841 | int CVICALLBACK HomeCB (int panel, int control, int event,  | 
        ||
| 842 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 843 | switch (event) {  | 
        ||
| 844 | case EVENT_COMMIT:  | 
        ||
| 845 | #ifdef MIKRO | 
        ||
| 846 | MIKRO_ReferenceMove(1);  | 
        ||
| 847 | MIKRO_ReferenceMove(2);  | 
        ||
| 848 | GetCurrentPositionCB(panel, control, event, NULL, 0, 0);  | 
        ||
| 849 | #endif | 
        ||
| 292 | f9daq | 850 | #ifdef uSMC_USB | 
        
| 851 |         //SetCtrlVal(panel,P1_STAGELED,1); | 
        ||
| 852 | for (int i=0; i<3; i++) uSMC_ReferenceMove(node[i]);  | 
        ||
| 853 | GetCurrentPositionCB(panel, control, event, NULL, 0, 0);  | 
        ||
| 854 |         //SetCtrlVal(panel,P1_STAGELED,0); | 
        ||
| 855 | #endif /* uSMC_USB */      | 
        ||
| 212 | f9daq | 856 | break;  | 
        
| 857 |   } | 
        ||
| 858 | return 0;  | 
        ||
| 859 | } | 
        ||
| 860 | |||
| 861 | int CVICALLBACK SetBiasCB (int panel, int control, int event,  | 
        ||
| 862 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 863 | double bias=0;  | 
        ||
| 864 | switch (event) {  | 
        ||
| 865 | case EVENT_COMMIT:  | 
        ||
| 866 | GetCtrlVal (panel, AIT_BIAS, &bias);  | 
        ||
| 867 | SetHvVoltage(ADDR_HV_CTRL, bias);  | 
        ||
| 868 | bias = GetHvVoltage(ADDR_HV_VMON);  | 
        ||
| 869 | SetCtrlVal (panel, AIT_BIASMON, bias);  | 
        ||
| 870 | break;  | 
        ||
| 871 |   } | 
        ||
| 872 | return 0;  | 
        ||
| 873 | } | 
        ||
| 874 | |||
| 875 | int CVICALLBACK SetHvOnCB (int panel, int control, int event,  | 
        ||
| 876 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 877 | int state=0;  | 
        ||
| 878 | double bias;  | 
        ||
| 879 | switch (event) {  | 
        ||
| 880 | case EVENT_COMMIT:  | 
        ||
| 881 | GetCtrlVal (panel, control, &state);  | 
        ||
| 882 | if (state) SetHvOn(true);  | 
        ||
| 883 | else SetHvOn(false);  | 
        ||
| 884 | bias = GetHvVoltage(ADDR_HV_VMON);  | 
        ||
| 885 | SetCtrlVal (panel, AIT_BIASMON, bias);  | 
        ||
| 886 | break;  | 
        ||
| 887 |   } | 
        ||
| 888 | return 0;  | 
        ||
| 889 | } | 
        ||
| 890 | |||
| 891 | int CVICALLBACK SetAdcIntegrationTimeCB (int panel, int control, int event,  | 
        ||
| 892 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 893 | |||
| 894 | switch (event) {  | 
        ||
| 895 | case EVENT_COMMIT: {  | 
        ||
| 896 | double value;  | 
        ||
| 897 | GetCtrlVal (panel, AIT_ADCINTEGRATIONTIME, &value);  | 
        ||
| 898 | SetIntegrationTime(value);  | 
        ||
| 899 | value = GetIntegrationTime();  | 
        ||
| 900 | SetCtrlVal (panel, AIT_GETADCINTEGRATIONTIME, value);  | 
        ||
| 901 |     } | 
        ||
| 902 | break;  | 
        ||
| 903 |   } | 
        ||
| 904 | return 0;  | 
        ||
| 905 | } | 
        ||
| 906 | |||
| 907 | int CVICALLBACK SetAdcThresholdCB (int panel, int control, int event,  | 
        ||
| 908 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 909 | switch (event) {  | 
        ||
| 910 | case EVENT_COMMIT: {  | 
        ||
| 911 | double value;  | 
        ||
| 912 | GetCtrlVal (panel, AIT_ADCTHRESHOLD, &value);  | 
        ||
| 913 | SetThreshold(value);  | 
        ||
| 914 | value = GetThreshold();  | 
        ||
| 915 | SetCtrlVal (panel, AIT_GETADCTHRESHOLD, value);  | 
        ||
| 916 |     } | 
        ||
| 917 | break;  | 
        ||
| 918 |   } | 
        ||
| 919 | return 0;  | 
        ||
| 920 | } | 
        ||
| 921 | |||
| 922 | int CVICALLBACK SetAdcGainCB (int panel, int control, int event,  | 
        ||
| 923 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 924 | switch (event) {  | 
        ||
| 925 | case EVENT_COMMIT: {  | 
        ||
| 926 | int value;  | 
        ||
| 927 | GetCtrlVal (panel, AIT_ADCGAIN, &value);  | 
        ||
| 928 | SetAdcGain(value);  | 
        ||
| 929 | int csrDetector = ReadSD4Register(ADDR_CSR_DETECTOR);  | 
        ||
| 930 | |||
| 931 | value = ((GetBit(csrDetector, BIT_CSR_DET_ADCGAIN2) ? 1 : 0) << 1) |  | 
        ||
| 932 | ((GetBit(csrDetector, BIT_CSR_DET_ADCGAIN1) ? 1 : 0) << 0);  | 
        ||
| 933 | SetCtrlVal (panel, AIT_GETADCGAIN, value);  | 
        ||
| 934 |     } | 
        ||
| 935 | break;  | 
        ||
| 936 |   } | 
        ||
| 937 | return 0;  | 
        ||
| 938 | } | 
        ||
| 939 | |||
| 940 | int CVICALLBACK SetAdcSumGainCB (int panel, int control, int event,  | 
        ||
| 941 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 942 | switch (event) {  | 
        ||
| 943 | case EVENT_COMMIT:{  | 
        ||
| 944 | int value;  | 
        ||
| 945 | GetCtrlVal (panel, AIT_ADCSUMGAIN, &value);  | 
        ||
| 946 | SetSumGain(value);  | 
        ||
| 947 | int csrDetector = ReadSD4Register(ADDR_CSR_DETECTOR);  | 
        ||
| 948 |                         value = | 
        ||
| 949 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN4) ? 1 : 0) << 3) |  | 
        ||
| 950 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN3) ? 1 : 0) << 2) |  | 
        ||
| 951 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN2) ? 1 : 0) << 1) |  | 
        ||
| 952 | ((GetBit(csrDetector, BIT_CSR_DET_SUMGAIN1) ? 1 : 0) << 0);  | 
        ||
| 953 | SetCtrlVal (panel, AIT_GETADCSUMGAIN, value);  | 
        ||
| 954 |     } | 
        ||
| 955 | |||
| 956 | break;  | 
        ||
| 957 |         } | 
        ||
| 958 | return 0;  | 
        ||
| 959 | } | 
        ||
| 960 | |||
| 961 | int CVICALLBACK SetDiscriminatorTypeCB (int panel, int control, int event,  | 
        ||
| 962 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 963 | switch (event) {  | 
        ||
| 964 | case EVENT_COMMIT:{  | 
        ||
| 965 | int trgtype;  | 
        ||
| 966 | GetCtrlVal(ait,AIT_TRGTYPE, &trgtype);  | 
        ||
| 967 | EnableTrigger(trgtype);  | 
        ||
| 968 |                 }               | 
        ||
| 969 | break;  | 
        ||
| 970 |         } | 
        ||
| 971 | return 0;  | 
        ||
| 972 | } | 
        ||
| 973 | |||
| 974 | int CVICALLBACK ResetCB (int panel, int control, int event,  | 
        ||
| 975 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 976 | switch (event) {  | 
        ||
| 977 | case EVENT_COMMIT:  | 
        ||
| 978 | ReconfigureDevice() ;  | 
        ||
| 979 | ReconnectDevice();  | 
        ||
| 980 |                         //ResetDevice() ; | 
        ||
| 981 | break;  | 
        ||
| 982 |         } | 
        ||
| 983 | return 0;  | 
        ||
| 984 | } | 
        ||
| 985 | |||
| 986 | int CVICALLBACK OpenScanCB (int panel, int control, int event,  | 
        ||
| 987 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 988 | switch (event) {  | 
        ||
| 989 | case EVENT_COMMIT:  | 
        ||
| 990 | DisplayPanel (xyscan);  | 
        ||
| 991 | break;  | 
        ||
| 992 |         } | 
        ||
| 993 | return 0;  | 
        ||
| 994 | } | 
        ||
| 995 | |||
| 996 | int CVICALLBACK OpenMainCB (int panel, int control, int event,  | 
        ||
| 997 | void *callbackData, int eventData1, int eventData2) {  | 
        ||
| 998 | switch (event) {  | 
        ||
| 999 | case EVENT_COMMIT:  | 
        ||
| 1000 | DisplayPanel (ait);  | 
        ||
| 1001 | break;  | 
        ||
| 1002 |         } | 
        ||
| 1003 | return 0;  | 
        ||
| 1004 | } |