Rev 39 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 39 | Rev 90 | ||
|---|---|---|---|
| Line 22... | Line 22... | ||
| 22 | 22 | ||
| 23 | #include <userint.h> | 
            23 | #include <userint.h> | 
          
| 24 | #include <ansi_c.h> | 
            24 | #include <ansi_c.h> | 
          
| 25 | #include <utility.h> | 
            25 | #include <utility.h> | 
          
| 26 | #include <analysis.h> | 
            26 | #include <analysis.h> | 
          
| - | 27 | #include <time.h> | 
          |
| - | 28 | //#include <zlib.h> | 
          |
| 27 | 29 | ||
| 28 | #include "c:\HOME\dino\sipmScan\include\sipmScan_ui.h" | 
            30 | #include "c:\HOME\dino\sipmScan\include\sipmScan_ui.h" | 
          
| 29 | 31 | ||
| 30 | #ifdef USE_DAQ | 
            32 | #ifdef USE_DAQ | 
          
| 31 | #  define USE_CAMAC | 
            33 | #  define USE_CAMAC | 
          
| 32 | #  include "camac.h" | 
            34 | #  include "camac.h" | 
          
| 33 | #  define NDAC 1 | 
            35 | #  define NDAC 1 | 
          
| 34 | #    define ASD8 0 // channels | 
            36 | #    define ASD8 0 // channels | 
          
| 35 | #    define AMPDISSH 1 | 
            37 | #    define AMPDISSH 1 | 
          
| 36 | #    define SIPM  | 
            38 | #    define SIPM 15 | 
          
| 37 | //#  define CAEN_V673A   0x10110000 // FMF | 
            39 | //#  define CAEN_V673A   0x10110000 // FMF | 
          
| 38 | #  define CAEN_V673A   0x22220000 // IJS | 
            40 | #  define CAEN_V673A   0x22220000 // IJS | 
          
| 39 | #  define CAEN_V462    0x100300 | 
            41 | #  define CAEN_V462    0x100300 | 
          
| 40 | #endif | 
            42 | #endif | 
          
| 41 | 43 | ||
| 42 | #ifdef USE_MIKRO | 
            44 | #ifdef USE_MIKRO | 
          
| 43 | #  define MIKRO_COM  | 
            45 | #  define MIKRO_COM 3 | 
          
| 44 | #  define MIKRO_X 1 | 
            46 | #  define MIKRO_X 1 | 
          
| 45 | #  define USE_MIKRO_Y | 
            47 | #  define USE_MIKRO_Y | 
          
| 46 | #  define MIKRO_Y 2 | 
            48 | #  define MIKRO_Y 2 | 
          
| 47 | #  define USE_MIKRO_Z | 
            49 | #  define USE_MIKRO_Z | 
          
| 48 | #  define MIKRO_Z 3 | 
            50 | #  define MIKRO_Z 3 | 
          
| 49 | #  define STEP_TOLERANCE 1   | 
            51 | #  define STEP_TOLERANCE 1   | 
          
| 50 | #endif | 
            52 | #endif | 
          
| 51 | 53 | ||
| 52 | #define MAXCH  | 
            54 | #define MAXCH 128 | 
          
| 53 | #define MAX_THREADS 10 | 
            55 | #define MAX_THREADS 10 | 
          
| 54 | 56 | ||
| 55 | #define IWAIT 200 | 
            57 | #define IWAIT 200 | 
          
| 56 | 58 | ||
| 57 | #define POWERSUPPLY 66 // Power supply voltage for SiPM bias | 
            59 | #define POWERSUPPLY 66 // Power supply voltage for SiPM bias | 
          
| Line 63... | Line 65... | ||
| 63 | static int something[NCH][2][MAXCH];  | 
            65 | static int something[NCH][2][MAXCH];  | 
          
| 64 | 66 | ||
| 65 | static int daq_on;  | 
            67 | static int daq_on;  | 
          
| 66 | static int poolHandle = 0;  | 
            68 | static int poolHandle = 0;  | 
          
| 67 | static int ntics,dummy;  | 
            69 | static int ntics,dummy;  | 
          
| - | 70 | ||
| - | 71 | static int offsetX = 5600;  | 
          |
| - | 72 | static int offsetY = 5400;  | 
          |
| 68 | 73 | ||
| 69 | /************************************************************/ | 
            74 | /************************************************************/ | 
          
| 70 | void wait_loop(unsigned long iloop)  | 
            75 | void wait_loop(unsigned long iloop)  | 
          
| 71 | 76 | ||
| 72 | { | 
            77 | { | 
          
| Line 175... | Line 180... | ||
| 175 | 180 | ||
| 176 | int maxn = BSIZE-4; // 2 words x 2 headers  | 
            181 | int maxn = BSIZE-4; // 2 words x 2 headers  | 
          
| 177 | int tdcdata, edge_type, overflow, tdc_num, channel, ev_dat, last_dat, nval_dat;  | 
            182 | int tdcdata, edge_type, overflow, tdc_num, channel, ev_dat, last_dat, nval_dat;  | 
          
| 178 |         // end of declarations | 
            183 |         // end of declarations | 
          
| 179 |         // *** | 
            184 |         // *** | 
          
| 180 | 185 | ||
| 181 | runrec.id = RUNREC_ID;  | 
            186 | runrec.id = RUNREC_ID;  | 
          
| 182 | runrec.len = sizeof(runrec);  | 
            187 | runrec.len = sizeof(runrec);  | 
          
| 183 |         //runrec.fver = 0x10000; | 
            188 |         //runrec.fver = 0x10000; | 
          
| 184 | runrec.nch = NCH;  | 
            189 | runrec.nch = NCH;  | 
          
| 185 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);//runrec.xy = 1;  | 
            190 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);//runrec.xy = 1;  | 
          
| Line 188... | Line 193... | ||
| 188 | endrec.len = sizeof(endrec);  | 
            193 | endrec.len = sizeof(endrec);  | 
          
| 189 | posrec.id = POSREC_ID;  | 
            194 | posrec.id = POSREC_ID;  | 
          
| 190 | posrec.len = sizeof(posrec);  | 
            195 | posrec.len = sizeof(posrec);  | 
          
| 191 | evtrec.id = EVTREC_ID;  | 
            196 | evtrec.id = EVTREC_ID;  | 
          
| 192 | evtrec.len = sizeof(evtrec);  | 
            197 | evtrec.len = sizeof(evtrec);  | 
          
| 193 | 198 | ||
| 194 | 199 | ||
| 195 | cres = 0;  | 
            200 | cres = 0;  | 
          
| 196 | 201 | ||
| 197 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev);  | 
            202 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev);  | 
          
| 198 | GetCtrlVal (p1h, P1_PEDESTAL, &runrec.ped);  | 
            203 | GetCtrlVal (p1h, P1_PEDESTAL, &runrec.ped);  | 
          
| 199 | 204 | ||
| 200 | GetCtrlVal (p1h, P1_NX, &runrec.nx);  | 
            205 | GetCtrlVal (p1h, P1_NX, &runrec.nx);  | 
          
| 201 | GetCtrlVal (p1h, P1_XSTEP, &runrec.dx);  | 
            206 | GetCtrlVal (p1h, P1_XSTEP, &runrec.dx);  | 
          
| 202 | GetCtrlVal (p1h, P1_XMIN, &runrec.x0);  | 
            207 | GetCtrlVal (p1h, P1_XMIN, &runrec.x0);  | 
          
| 203 | GetCtrlVal (p1h, P1_NY, &runrec.ny);  | 
            208 | GetCtrlVal (p1h, P1_NY, &runrec.ny);  | 
          
| 204 | GetCtrlVal (p1h, P1_YSTEP, &runrec.dy);  | 
            209 | GetCtrlVal (p1h, P1_YSTEP, &runrec.dy);  | 
          
| Line 206... | Line 211... | ||
| 206 | 211 | ||
| 207 | GetCtrlVal (p1h, P1_NMIN, &step_minutes);  | 
            212 | GetCtrlVal (p1h, P1_NMIN, &step_minutes);  | 
          
| 208 | GetSystemTime(&start_hours, &start_minutes, &start_seconds);  | 
            213 | GetSystemTime(&start_hours, &start_minutes, &start_seconds);  | 
          
| 209 |         //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; | 
            214 |         //cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds; | 
          
| 210 | time(&cur_time_s);  | 
            215 | time(&cur_time_s);  | 
          
| 211 | end_time_s = cur_time_s +  | 
            216 | end_time_s = cur_time_s + (int) (runrec.nx * runrec.ny * runrec.nev/10000.0 * 4.5); // expected seconds  | 
          
| 212 | printf("START:%2d-%2d-%2d (cur_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, cur_time_s, end_time_s);  | 
            217 | printf("START:%2d-%2d-%2d (cur_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, cur_time_s, end_time_s);  | 
          
| - | 218 | SetCtrlAttribute(p1h, P1_EXPTIME, ATTR_DIMMED, 0);  | 
          |
| - | 219 | SetCtrlVal(p1h, P1_EXPTIME, ctime(&end_time_s));  | 
          |
| 213 | 220 | ||
| 214 |         //GetCtrlVal (p1h, P1_DSAVE, &dsave); | 
            221 |         //GetCtrlVal (p1h, P1_DSAVE, &dsave); | 
          
| 215 |   //if (dsave) { | 
            222 |   //if (dsave) { | 
          
| 216 | GetCtrlVal (p1h, P1_DFILE, dfile0);  | 
            223 | GetCtrlVal (p1h, P1_DFILE, dfile0);  | 
          
| 217 | 224 | ||
| 218 | fev=0;  | 
            225 | fev=0;  | 
          
| 219 | fcount=1;  | 
            226 | fcount=1;  | 
          
| 220 | GetCtrlVal (p1h, P1_NEWF, &fmax);  | 
            227 | GetCtrlVal (p1h, P1_NEWF, &fmax);  | 
          
| Line 223... | Line 230... | ||
| 223 | GetCtrlVal (p1h, P1_SUPR, &supr0);  | 
            230 | GetCtrlVal (p1h, P1_SUPR, &supr0);  | 
          
| 224 | if (supr0) {  | 
            231 | if (supr0) {  | 
          
| 225 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin);  | 
            232 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin);  | 
          
| 226 | GetCtrlVal (p1h, P1_FRAC, &frac);  | 
            233 | GetCtrlVal (p1h, P1_FRAC, &frac);  | 
          
| 227 |         } | 
            234 |         } | 
          
| 228 | 235 | ||
| 229 | #ifdef USE_DAQ | 
            236 | #ifdef USE_DAQ | 
          
| 230 | V673A_map(0,CAEN_V673A,0);  | 
            237 | V673A_map(0,CAEN_V673A,0);  | 
          
| 231 | V673A_init(0);  | 
            238 | V673A_init(0);  | 
          
| 232 | 239 | ||
| 233 | V462_map(0,CAEN_V462,0);  | 
            240 | V462_map(0,CAEN_V462,0);  | 
          
| 234 | V462_set0(0,1);  | 
            241 | V462_set0(0,1);  | 
          
| 235 | #endif | 
            242 | #endif | 
          
| 236 | 243 | ||
| 237 |   //if (dsave) { | 
            244 |   //if (dsave) { | 
          
| 238 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);  | 
            245 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);  | 
          
| - | 246 | SetCtrlVal(p1h, P1_FCOUNT,fcount);  | 
          |
| 239 | 247 | ||
| 240 | fp = fopen (dfile, "wb");  | 
            248 | fp = fopen (dfile, "wb");  | 
          
| 241 | time (&runrec.time);  | 
            249 | time (&runrec.time);  | 
          
| 242 | status = fwrite (&runrec, 1, runrec.len, fp);  | 
            250 | status = fwrite (&runrec, 1, runrec.len, fp);  | 
          
| 243 |         //} | 
            251 |         //} | 
          
| 244 | if (supr0) {  | 
            252 | if (supr0) {  | 
          
| 245 | fseed = runrec.time & 0x7fffffff;  | 
            253 | fseed = runrec.time & 0x7fffffff;  | 
          
| 246 | Uniform (1, fseed, &fracg);  | 
            254 | Uniform (1, fseed, &fracg);  | 
          
| 247 |         } | 
            255 |         } | 
          
| - | 256 |           // vertical moving stage loop | 
          |
| - | 257 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) {  | 
          |
| - | 258 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy;  | 
          |
| - | 259 | #ifdef USE_MIKRO_Y | 
          |
| - | 260 | if (print) printf("MIKRO_MoveTo (2, y);%d\n",posrec.yset);  | 
          |
| - | 261 | do {  | 
          |
| - | 262 | MIKRO_MoveTo (MIKRO_Y, offsetY + posrec.yset);  | 
          |
| - | 263 | MIKRO_GetPosition(MIKRO_Y, &mikroY);  | 
          |
| - | 264 | mikroY -= offsetY;  | 
          |
| - | 265 | if (print) printf("%d\n", abs(posrec.yset - mikroY));  | 
          |
| - | 266 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE);  | 
          |
| - | 267 | if (print) printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset);  | 
          |
| - | 268 | #endif | 
          |
| - | 269 | posrec.yset = mikroY;  | 
          |
| - | 270 | SetCtrlVal (p1h, P1_Y, posrec.yset);  | 
          |
| - | 271 | SetCtrlVal (p1h, P1_IY, posrec.iy);  | 
          |
| 248 | 272 | ||
| - | 273 |         // horizontal moving stage loop | 
          |
| 249 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) {  | 
            274 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) {  | 
          
| 250 | 
  | 
            275 | posrec.xset = runrec.x0 + posrec.ix*runrec.dx;  | 
          
| 251 | #ifdef USE_MIKRO | 
            276 | #ifdef USE_MIKRO | 
          
| 252 | do {  | 
            277 | do {  | 
          
| 253 | if (print) printf("MIKRO_MoveTo (1, x);%d\n",posrec.xset);  | 
            278 | if (print) printf("MIKRO_MoveTo (1, x);%d\n",posrec.xset);  | 
          
| 254 | MIKRO_MoveTo (MIKRO_X, posrec.xset);  | 
            279 | MIKRO_MoveTo (MIKRO_X, offsetX + posrec.xset);  | 
          
| 255 | MIKRO_GetPosition(MIKRO_X, &mikroX);  | 
            280 | MIKRO_GetPosition(MIKRO_X, &mikroX);  | 
          
| - | 281 | mikroX -= offsetX;  | 
          |
| 256 | if (print) printf("%d\n", abs(posrec.xset - mikroX));  | 
            282 | if (print) printf("%d\n", abs(posrec.xset - mikroX));  | 
          
| 257 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE);  | 
            283 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE);  | 
          
| 258 | #endif | 
            284 | #endif | 
          
| 259 | posrec.xset = mikroX; // true value  | 
            285 | posrec.xset = mikroX; // true value  | 
          
| 260 | SetCtrlVal (p1h, P1_X, posrec.xset);  | 
            286 | SetCtrlVal (p1h, P1_X, posrec.xset);  | 
          
| 261 | SetCtrlVal (p1h, P1_IX, posrec.ix);  | 
            287 | SetCtrlVal (p1h, P1_IX, posrec.ix);  | 
          
| 262 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) {  | 
            - | |
| 263 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy;  | 
            - | |
| 264 | #ifdef USE_MIKRO_Y | 
            - | |
| 265 | if (print) printf("MIKRO_MoveTo (2, y);%d\n",posrec.yset);  | 
            - | |
| 266 | do {  | 
            288 | |
| 267 | MIKRO_MoveTo (MIKRO_Y, posrec.yset);  | 
            - | |
| 268 | MIKRO_GetPosition(MIKRO_Y, &mikroY);  | 
            - | |
| 269 | if (print) printf("%d\n", abs(posrec.yset - mikroY));  | 
            - | |
| 270 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE);  | 
            - | |
| 271 | if (print) printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset);  | 
            - | |
| 272 | #endif | 
            289 | |
| 273 | posrec.yset = mikroY;  | 
            - | |
| 274 | SetCtrlVal (p1h, P1_Y, posrec.yset);  | 
            - | |
| 275 | SetCtrlVal (p1h, P1_IY, posrec.iy);  | 
            - | |
| 276 |       //if (dsave) { | 
            290 |         //if (dsave) { | 
          
| 277 | if (fmax && (ftell(fp) > fmax)) {  | 
            291 | if (fmax && (ftell(fp) > fmax)) {  | 
          
| 278 | fcount+=1;  | 
            292 | fcount+=1;  | 
          
| 279 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);  | 
            293 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);  | 
          
| 280 | fclose(fp);  | 
            294 | fclose(fp);  | 
          
| 281 | fp = fopen (dfile, "wb");  | 
            295 | fp = fopen (dfile, "wb");  | 
          
| 282 |       } | 
            296 |       } | 
          
| 283 | 297 | ||
| 284 | time (&posrec.time);  | 
            298 | time (&posrec.time);  | 
          
| 285 | status = fwrite (&posrec, 1, posrec.len, fp);  | 
            299 | status = fwrite (&posrec, 1, posrec.len, fp);  | 
          
| 286 | if (print) printf("POSREC status %d len %d\n", status, posrec.len);  | 
            300 | if (print) printf("POSREC status %d len %d\n", status, posrec.len);  | 
          
| 287 |                   //} | 
            301 |                   //} | 
          
| Line 304... | Line 318... | ||
| 304 | count=0;  | 
            318 | count=0;  | 
          
| 305 | ntics=0;  | 
            319 | ntics=0;  | 
          
| 306 | if (print) printf("Event counter: %d\n", evtrec.nev);  | 
            320 | if (print) printf("Event counter: %d\n", evtrec.nev);  | 
          
| 307 | 321 | ||
| 308 |                 //if (t!=told ) printf("%d in %2.2f min daq::event() %s\n",i, (double)(t-tstart)/60., ctime(&t));  | 
            322 |                 //if (t!=told ) printf("%d in %2.2f min daq::event() %s\n",i, (double)(t-tstart)/60., ctime(&t));  | 
          
| 309 | 323 | ||
| 310 | #ifdef USE_DAQ | 
            324 | #ifdef USE_DAQ | 
          
| 311 | #ifdef CAEN_V673A | 
            325 | #ifdef CAEN_V673A | 
          
| 312 | 326 | ||
| 313 | 327 | ||
| 314 | V462_start0(0);  | 
            328 | V462_start0(0);  | 
          
| 315 |                 //tmlnk (tout);  | 
            329 |                 //tmlnk (tout);  | 
          
| Line 368... | Line 382... | ||
| 368 |                   } | 
            382 |                   } | 
          
| 369 | if (print) printf("Received triggers: %d \n", ntrig);  | 
            383 | if (print) printf("Received triggers: %d \n", ntrig);  | 
          
| 370 | } else {  | 
            384 | } else {  | 
          
| 371 | if (ntrig==0) {  | 
            385 | if (ntrig==0) {  | 
          
| 372 | fprintf(stderr,"-----------------> no trigger");  | 
            386 | fprintf(stderr,"-----------------> no trigger");  | 
          
| 373 | 
  | 
            387 |                 //break; | 
          
| 374 | } else {  | 
            388 | } else {  | 
          
| 375 | if (print) fprintf(stderr,"-----------------> wrong number of triggers in chips V673a !!!\n");  | 
            389 | if (print) fprintf(stderr,"-----------------> wrong number of triggers in chips V673a !!!\n");  | 
          
| 376 |           } | 
            390 |           } | 
          
| 377 | V673A_clallb(0);  | 
            391 | V673A_clallb(0);  | 
          
| 378 | evtrec.nev--;  | 
            392 | evtrec.nev--;  | 
          
| Line 396... | Line 410... | ||
| 396 | if (fmax && (ftell(fp) > fmax)) {  | 
            410 | if (fmax && (ftell(fp) > fmax)) {  | 
          
| 397 | time (&endrec.time);  | 
            411 | time (&endrec.time);  | 
          
| 398 | status = fwrite (&endrec, 1, endrec.len, fp);  | 
            412 | status = fwrite (&endrec, 1, endrec.len, fp);  | 
          
| 399 | fcount+=1;  | 
            413 | fcount+=1;  | 
          
| 400 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);  | 
            414 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);  | 
          
| - | 415 | SetCtrlVal(p1h, P1_FCOUNT,fcount);  | 
          |
| 401 | fclose(fp);  | 
            416 | fclose(fp);  | 
          
| 402 | fp = fopen (dfile, "wb");  | 
            417 | fp = fopen (dfile, "wb");  | 
          
| 403 |             } | 
            418 |             } | 
          
| 404 |         } | 
            419 |         } | 
          
| 405 | 420 | ||
| Line 417... | Line 432... | ||
| 417 | 432 | ||
| 418 | GetCtrlVal(p1h, P1_DAQ, &daq_on);  | 
            433 | GetCtrlVal(p1h, P1_DAQ, &daq_on);  | 
          
| 419 | 434 | ||
| 420 | } while (evtrec.nev++<runrec.nev && daq_on);  | 
            435 | } while (evtrec.nev++<runrec.nev && daq_on);  | 
          
| 421 | if (!daq_on) break;  | 
            436 | if (!daq_on) break;  | 
          
| 422 | } //  | 
            437 | } // y loop  | 
          
| 423 | if (!daq_on) break;  | 
            438 | if (!daq_on) break;  | 
          
| 424 | } //  | 
            439 | } // x loop  | 
          
| 425 | 440 | ||
| 426 |   //if (dsave) { | 
            441 |   //if (dsave) { | 
          
| 427 | time (&endrec.time);  | 
            442 | time (&endrec.time);  | 
          
| 428 | status = fwrite (&endrec, 1, endrec.len, fp);  | 
            443 | status = fwrite (&endrec, 1, endrec.len, fp);  | 
          
| 429 | if (print) printf("ENDREC status %d len %d\n", status, endrec.len);  | 
            444 | if (print) printf("ENDREC status %d len %d\n", status, endrec.len);  | 
          
| Line 462... | Line 477... | ||
| 462 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,  | 
            477 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,  | 
          
| 463 | LPSTR lpszCmdLine, int nCmdShow)  | 
            478 | LPSTR lpszCmdLine, int nCmdShow)  | 
          
| 464 | { | 
            479 | { | 
          
| 465 | int i,j,status,refon;  | 
            480 | int i,j,status,refon;  | 
          
| 466 | long int xpos, ypos, zpos;  | 
            481 | long int xpos, ypos, zpos;  | 
          
| 467 | char dfile[  | 
            482 | char dfile[512];  | 
          
| - | 483 | char message[256];  | 
          |
| 468 | FILE *fp;  | 
            484 | FILE *fp;  | 
          
| 469 | 485 | ||
| 470 | typedef struct {  | 
            486 | typedef struct {  | 
          
| 471 | unsigned long id,len;  | 
            487 | unsigned long id,len;  | 
          
| 472 | unsigned long fver,time;  | 
            488 | unsigned long fver,time;  | 
          
| Line 501... | Line 517... | ||
| 501 | #endif | 
            517 | #endif | 
          
| 502 | 518 | ||
| 503 | if ((p1h = LoadPanel (0, "include/sipmScan_ui.uir", P1)) < 0) return -1;  | 
            519 | if ((p1h = LoadPanel (0, "include/sipmScan_ui.uir", P1)) < 0) return -1;  | 
          
| 504 | DisplayPanel (p1h);  | 
            520 | DisplayPanel (p1h);  | 
          
| 505 | SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1);  | 
            521 | SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1);  | 
          
| - | 522 | ||
| - | 523 | SetCtrlVal (p1h, P1_OFFSETX, offsetX);  | 
          |
| - | 524 | SetCtrlVal (p1h, P1_OFFSETY, offsetY);  | 
          |
| 506 | 525 | ||
| 507 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);  | 
            526 | GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);  | 
          
| 508 | SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2);  | 
            527 | SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2);  | 
          
| 509 | 528 | ||
| 510 | QueueUserEvent (1000, p1h, P1_RESET);  | 
            529 | QueueUserEvent (1000, p1h, P1_RESET);  | 
          
| 511 | QueueUserEvent (1000, p1h, P1_ASD8THR);  | 
            530 | QueueUserEvent (1000, p1h, P1_ASD8THR);  | 
          
| 512 | QueueUserEvent (1000, p1h, P1_AMPDISSHTHR);  | 
            531 | QueueUserEvent (1000, p1h, P1_AMPDISSHTHR);  | 
          
| 513 | QueueUserEvent (1000, p1h, P1_BIAS);  | 
            532 | QueueUserEvent (1000, p1h, P1_BIAS);  | 
          
| - | 533 | QueueUserEvent (1000, p1h, P1_OFFSETX);  | 
          |
| - | 534 | QueueUserEvent (1000, p1h, P1_OFFSETY);  | 
          |
| 514 | 535 | ||
| 515 | printf("BIAS offset set to: %d\n", POWERSUPPLY);  | 
            536 | printf("BIAS offset set to: %d\n", POWERSUPPLY);  | 
          
| 516 | 537 | ||
| 517 | do {  | 
            538 | do {  | 
          
| 518 | GetUserEvent (1, &pID, &rID);  | 
            539 | GetUserEvent (1, &pID, &rID);  | 
          
| 519 | switch (rID) {  | 
            540 | switch (rID) {  | 
          
| Line 528... | Line 549... | ||
| 528 | case P1_DAQ:  | 
            549 | case P1_DAQ:  | 
          
| 529 | GetCtrlVal (p1h, P1_DAQ, &daq_on);  | 
            550 | GetCtrlVal (p1h, P1_DAQ, &daq_on);  | 
          
| 530 | if (daq_on) {  | 
            551 | if (daq_on) {  | 
          
| 531 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID);  | 
            552 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID);  | 
          
| 532 | } else {  | 
            553 | } else {  | 
          
| 533 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID,  | 
            554 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, OPT_TP_PROCESS_EVENTS_WHILE_WAITING);  | 
          
| 534 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING);  | 
            - | |
| 535 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID);  | 
            555 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID);  | 
          
| 536 |             } | 
            556 |             } | 
          
| 537 | break;  | 
            557 | break;  | 
          
| - | 558 | case P1_XMIN:  | 
          |
| - | 559 | if (!daq_on) {  | 
          |
| - | 560 | GetCtrlVal (p1h, P1_XMIN, &xpos);  | 
          |
| - | 561 |                           //backlash | 
          |
| - | 562 | MIKRO_MoveTo(MIKRO_X, xpos+offsetX-1000);  | 
          |
| - | 563 | Delay(0.01);  | 
          |
| - | 564 | MIKRO_MoveTo(MIKRO_X, xpos+offsetX);  | 
          |
| 538 | 565 |                   } | 
          |
| - | 566 | break;  | 
          |
| - | 567 | case P1_YMIN:  | 
          |
| - | 568 | if (!daq_on) {  | 
          |
| - | 569 | GetCtrlVal(p1h, P1_YMIN, &ypos);  | 
          |
| - | 570 | MIKRO_MoveTo(MIKRO_Y, ypos+offsetY-1000);  | 
          |
| - | 571 | Delay(0.01);  | 
          |
| - | 572 | MIKRO_MoveTo(MIKRO_Y, ypos+offsetY);  | 
          |
| - | 573 |                   } | 
          |
| - | 574 | break;  | 
          |
| 539 | case P1_ZSET:  | 
            575 | case P1_ZSET:  | 
          
| 540 | if (!daq_on) {  | 
            576 | if (!daq_on) {  | 
          
| 541 | GetCtrlVal (p1h, P1_ZSET, &zpos);  | 
            577 | GetCtrlVal (p1h, P1_ZSET, &zpos);  | 
          
| 542 | #ifdef USE_MIKRO_Z | 
            578 | #ifdef USE_MIKRO_Z | 
          
| 543 | MIKRO_MoveTo (MIKRO_Z, zpos);  | 
            579 | MIKRO_MoveTo (MIKRO_Z, zpos);  | 
          
| Line 567... | Line 603... | ||
| 567 | break;  | 
            603 | break;  | 
          
| 568 | case P1_MGET:  | 
            604 | case P1_MGET:  | 
          
| 569 |           #ifdef USE_MIKRO | 
            605 |           #ifdef USE_MIKRO | 
          
| 570 | MIKRO_GetPosition(MIKRO_X,&xpos);  | 
            606 | MIKRO_GetPosition(MIKRO_X,&xpos);  | 
          
| 571 | Delay(0.01);  | 
            607 | Delay(0.01);  | 
          
| 572 | SetCtrlVal (p1h, P1_X, xpos);  | 
            608 | SetCtrlVal (p1h, P1_X, xpos-offsetX);  | 
          
| 573 |           #ifdef USE_MIKRO_Y     | 
            609 |           #ifdef USE_MIKRO_Y     | 
          
| 574 | MIKRO_GetPosition(MIKRO_Y,&ypos);  | 
            610 | MIKRO_GetPosition(MIKRO_Y,&ypos);  | 
          
| 575 | Delay(0.01);  | 
            611 | Delay(0.01);  | 
          
| 576 | SetCtrlVal (p1h, P1_Y, ypos);  | 
            612 | SetCtrlVal (p1h, P1_Y, ypos-offsetY);  | 
          
| 577 |           #endif | 
            613 |           #endif | 
          
| 578 |           #ifdef USE_MIKRO_Z     | 
            614 |           #ifdef USE_MIKRO_Z     | 
          
| 579 | MIKRO_GetPosition(MIKRO_Z,&zpos);  | 
            615 | MIKRO_GetPosition(MIKRO_Z,&zpos);  | 
          
| 580 | Delay(0.01);  | 
            616 | Delay(0.01);  | 
          
| 581 | SetCtrlVal (p1h, P1_Z, zpos);  | 
            617 | SetCtrlVal (p1h, P1_Z, zpos);  | 
          
| Line 639... | Line 675... | ||
| 639 | GetCtrlVal (p1h, P1_SBIAS, &value);  | 
            675 | GetCtrlVal (p1h, P1_SBIAS, &value);  | 
          
| 640 | value -= POWERSUPPLY;  | 
            676 | value -= POWERSUPPLY;  | 
          
| 641 | SetDac(SIPM, value);  | 
            677 | SetDac(SIPM, value);  | 
          
| 642 |                 } | 
            678 |                 } | 
          
| 643 | break;  | 
            679 | break;  | 
          
| - | 680 |                 // reset SiPM bias to initial power supply voltage | 
          |
| - | 681 | case P1_BIASOFF:  | 
          |
| - | 682 |                         { | 
          |
| - | 683 | SetDac(SIPM, 0);  | 
          |
| - | 684 | SetCtrlVal(p1h, P1_SBIAS, (double) POWERSUPPLY);  | 
          |
| - | 685 |                         } | 
          |
| - | 686 | case P1_OFFSETX:  | 
          |
| - | 687 |                         { | 
          |
| - | 688 | GetCtrlVal(p1h, P1_OFFSETX, &offsetX);  | 
          |
| - | 689 |                         } | 
          |
| - | 690 | case P1_OFFSETY:  | 
          |
| - | 691 |                         { | 
          |
| - | 692 | GetCtrlVal(p1h, P1_OFFSETY, &offsetY);  | 
          |
| - | 693 |                         } | 
          |
| 644 | 694 | ||
| 645 |         } | 
            695 |         } | 
          
| 646 | 696 | ||
| 647 | } while ((rID != P1_EXIT)||daq_on);  | 
            697 | } while ((rID != P1_EXIT)||daq_on);  | 
          
| 648 | 698 | ||