Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
289 | f9daq | 1 | #include <ansi_c.h> |
2 | /* Program qe2d.c za testiranje povrsinske obcutljivosti |
||
3 | |||
4 | Avtor: Samo Korpar |
||
5 | Verzija: |
||
6 | 1.00 28.9.2009 |
||
7 | - |
||
8 | */ |
||
9 | #include <utility.h> |
||
10 | #include <userint.h> |
||
11 | #include "K617.h" |
||
12 | #include <cvirte.h> |
||
13 | #include "qe2d_ui.h" |
||
14 | |||
15 | #define uSMC_USB |
||
16 | #ifdef uSMC_USB |
||
17 | # include "uSMC.h" |
||
18 | # define uSMC_SERIAL_X "0000000000004925" |
||
19 | # define uSMC_SERIAL_Y "0000000000006030" |
||
20 | # define uSMC_SERIAL_Z "0000000000002894" |
||
21 | const char serials[3][16]= {uSMC_SERIAL_X,uSMC_SERIAL_Y,uSMC_SERIAL_Z}; |
||
22 | #endif /* uSMC_USB */ |
||
23 | |||
24 | //#define MIKRO_COM 6 |
||
25 | #ifdef MIKRO_COM |
||
26 | # include "MIKRO.h" |
||
27 | #endif /* MIKRO_COM */ |
||
28 | |||
29 | #define SP2155_PORT 4 |
||
30 | #ifdef SP2155_PORT |
||
31 | # include "SP2155.h" |
||
32 | #endif /* SP2155_PORT */ |
||
33 | |||
34 | #define PROLOGIX_PORT 5 |
||
35 | #define K617_ADDR 3 |
||
36 | |||
37 | #define MAXXY 1000 |
||
38 | #define MAXWL 1000 |
||
39 | const int PosCtrl[3]= {P1_X,P1_Y,P1_Z}; |
||
40 | const int ncurroff=10; |
||
41 | const int ncurrmes=3; |
||
42 | |||
43 | static int node[3]; |
||
44 | static int CurPos[3]= {0,0,0}; |
||
45 | static int p1h,pID,rID,tfID,plh[MAXXY],plqeh[MAXXY]; |
||
46 | static int wl[MAXXY][MAXWL]; |
||
47 | static float tok[MAXXY][MAXWL],qe[MAXXY][MAXWL],tokoff[MAXXY]; |
||
48 | |||
49 | //static float |
||
50 | |||
51 | float getavg(int n) { |
||
52 | int i; |
||
53 | float tok; |
||
54 | |||
55 | tok=0; |
||
56 | for (i=0; i<n; i++) |
||
57 | tok+=K617_get(NULL, NULL); |
||
58 | return (tok/(float)n); |
||
59 | } |
||
60 | |||
61 | int CVICALLBACK cb_timer (int panel, int control, int event, void *callbackData, |
||
62 | int eventData1, int eventData2) { |
||
63 | QueueUserEvent (9000, p1h, P1_TIMER); |
||
64 | return (0); |
||
65 | } |
||
66 | |||
67 | |||
68 | int MDelay(double t) { |
||
69 | while (0.5<t) { |
||
70 | ProcessSystemEvents(); |
||
71 | GetUserEvent (0, &pID, &rID); |
||
72 | switch (rID) { |
||
73 | case P1_STOP: |
||
74 | return 1; |
||
75 | break; |
||
76 | } |
||
77 | |||
78 | Delay(0.5); |
||
79 | t-=0.5; |
||
80 | SetCtrlVal(p1h,P1_TOUT,t); |
||
81 | } |
||
82 | Delay(t); |
||
83 | SetCtrlVal(p1h,P1_TOUT,0.0); |
||
84 | return 0; |
||
85 | } |
||
86 | |||
87 | int qescan() { |
||
88 | int i; |
||
89 | int npos,nref; |
||
90 | float wait; |
||
91 | int icwl; |
||
92 | double rcurr; |
||
93 | |||
94 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_ENABLED, 0); |
||
95 | GetCtrlVal (p1h, P1_POSITION, &npos); |
||
96 | #ifdef MIKRO_COM |
||
97 | SetCtrlVal(p1h,P1_STAGELED,1); |
||
98 | for (i=0; i<2; i++) { |
||
99 | GetTableCellVal(p1h,P1_POINTS,MakePoint(i+1,npos+1),&CurPos[i]); |
||
100 | MIKRO_MoveTo(node[i],CurPos[i]); |
||
101 | MIKRO_GetPosition(node[i],&CurPos[i]); |
||
102 | SetCtrlVal(p1h,PosCtrl[i],CurPos[i]); |
||
103 | } |
||
104 | SetCtrlVal(p1h,P1_STAGELED,0); |
||
105 | #endif /* MIKRO_COM */ |
||
106 | #ifdef uSMC_USB |
||
107 | SetCtrlVal(p1h,P1_STAGELED,1); |
||
108 | for (i=0; i<2; i++) { |
||
109 | GetTableCellVal(p1h,P1_POINTS,MakePoint(i+1,npos+1),&CurPos[i]); |
||
110 | uSMC_MoveTo(node[i],CurPos[i]); |
||
111 | uSMC_GetPosition (node[i],&CurPos[i]); |
||
112 | SetCtrlVal(p1h,PosCtrl[i],CurPos[i]); |
||
113 | } |
||
114 | SetCtrlVal(p1h,P1_STAGELED,0); |
||
115 | #endif /* uSMC_USB */ |
||
116 | K617_trigger_mode(1); |
||
117 | #ifdef SP2155_PORT |
||
118 | SetCtrlVal (p1h, P1_GLED, 1); |
||
119 | SP2155_SetWavelength(1000); |
||
120 | SetCtrlVal (p1h, P1_GLED, 0); |
||
121 | #endif /* SP2155_PORT */ |
||
122 | |||
123 | |||
124 | GetCtrlVal (p1h, P1_WAIT0, &wait); |
||
125 | if (MDelay(wait*60.)) return 1; |
||
126 | |||
127 | GetCtrlVal (p1h, P1_WAIT, &wait); |
||
128 | tokoff[npos]=getavg(ncurroff); |
||
129 | SetCtrlVal (p1h, P1_BGRCUR1,tokoff[npos]); |
||
130 | GetCtrlVal (p1h, P1_NREF, &nref); |
||
131 | for (i=0; i<nref; i++) { |
||
132 | icwl=wl[0][i]; |
||
133 | #ifdef SP2155_PORT |
||
134 | SetCtrlVal (p1h, P1_GLED, 1); |
||
135 | SP2155_SetWavelength(icwl); |
||
136 | SetCtrlVal (p1h, P1_GLED, 0); |
||
137 | #endif /* SP2155_PORT */ |
||
138 | SetCtrlVal (p1h, P1_CWL, icwl); |
||
139 | if (MDelay(wait)) return 1; |
||
140 | rcurr=getavg(ncurrmes); |
||
141 | SetCtrlVal (p1h, P1_CURR, rcurr); |
||
142 | wl[npos][i]=icwl; |
||
143 | tok[npos][i]=-(rcurr-tokoff[npos]); |
||
144 | |||
145 | } |
||
146 | if (plh[npos]) DeleteGraphPlot (p1h, P1_GSAMPLE, plh[npos], VAL_IMMEDIATE_DRAW); |
||
147 | plh[npos] = PlotXY (p1h, P1_GSAMPLE, wl[npos], tok[npos], nref, VAL_INTEGER, VAL_FLOAT, |
||
148 | VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
||
149 | |||
150 | for (i=0; i<nref; i++) |
||
151 | if (tok[0][i]>1e-12) |
||
152 | qe[npos][i]=qe[0][i]*tok[npos][i]/tok[0][i]; |
||
153 | else |
||
154 | qe[npos][i]=0.; |
||
155 | |||
156 | if (plqeh[npos]) DeleteGraphPlot (p1h, P1_GQE, plqeh[npos], VAL_IMMEDIATE_DRAW); |
||
157 | plqeh[npos] = PlotXY (p1h, P1_GQE, wl[npos], qe[npos], nref, VAL_INTEGER, |
||
158 | VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE, |
||
159 | VAL_SOLID, 1, VAL_BLUE); |
||
160 | |||
161 | K617_trigger_mode(0); |
||
162 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_ENABLED, 1); |
||
163 | #ifdef MIKRO_COM |
||
164 | SetCtrlVal (p1h, P1_STAGELED, 1); |
||
165 | for (i=0; i<2; i++) { |
||
166 | MIKRO_GetPosition (node[i],&CurPos[i]); |
||
167 | SetCtrlVal (p1h,PosCtrl[i],CurPos[i]); |
||
168 | } |
||
169 | SetCtrlVal (p1h, P1_STAGELED, 0); |
||
170 | #endif /* MIKRO_COM */ |
||
171 | #ifdef uSMC_USB |
||
172 | SetCtrlVal(p1h,P1_STAGELED,1); |
||
173 | for (i=0; i<2; i++) { |
||
174 | uSMC_GetPosition(node[i],&CurPos[i]); |
||
175 | SetCtrlVal(p1h,PosCtrl[i],CurPos[i]); |
||
176 | } |
||
177 | SetCtrlVal (p1h, P1_STAGELED, 0); |
||
178 | #endif /* uSMC_USB */ |
||
179 | return 0; |
||
180 | |||
181 | } |
||
182 | |||
183 | |||
184 | int mcp_positions() { |
||
185 | |||
186 | FILE *fp=fopen("mcp_positions.txt","w"); |
||
187 | int i=0,j=0; |
||
188 | int nx=10; |
||
189 | int ny=10; |
||
190 | int minx=130000; |
||
191 | int maxx=280000; |
||
192 | int miny=115000; |
||
193 | int maxy=265000; |
||
194 | fprintf(fp,"30000 124000\n"); |
||
195 | for (i=0; i<nx+1; i++) for (j=0; j<ny+1; j++) |
||
196 | fprintf(fp,"%d %d\n",minx+i*(maxx-minx)/nx, miny+j*(maxy-miny)/ny); |
||
197 | fclose(fp); |
||
198 | return 0; |
||
199 | } |
||
200 | |||
201 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
||
202 | LPSTR lpszCmdLine, int nCmdShow) { |
||
203 | |||
204 | int i,j,iret,nb; |
||
205 | int npos,nref,nrows; |
||
206 | int igr,iwl0,idwl,inwl,ilwl,icwl; |
||
207 | int scan_on; |
||
208 | int irange,vsource; |
||
209 | float vout,wait; |
||
210 | double rcurr; |
||
211 | int hdr[10]; |
||
212 | float *fhdr; |
||
213 | float sdata[5]; |
||
214 | // char cpref[100]; |
||
215 | char pfile[300]; |
||
216 | FILE *fp; |
||
217 | |||
218 | scan_on=0; |
||
219 | fhdr=(float *)&hdr[0]; |
||
220 | |||
221 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
||
222 | |||
223 | mcp_positions(); |
||
224 | for (i=0; i<MAXXY; i++) { |
||
225 | tokoff[i]=0; |
||
226 | plh[i]=0; |
||
227 | plqeh[i]=0; |
||
228 | for (j=0; j<MAXWL; j++) { |
||
229 | tok[i][j]=0.; |
||
230 | wl[i][j]=0; |
||
231 | qe[i][j]=0.; |
||
232 | } |
||
233 | } |
||
234 | |||
235 | #ifdef MIKRO_COM |
||
236 | MIKRO_Open(MIKRO_COM); |
||
237 | for (i=0; i<3; i++) { |
||
238 | node[i]=i+1; |
||
239 | MIKRO_Init(node[i],0); |
||
240 | } |
||
241 | #endif /* MIKRO_COM */ |
||
242 | #ifdef uSMC_USB |
||
243 | uSMC_Open(); |
||
244 | for (i=0; i<3; i++) { |
||
245 | node[i]=uSMC_FindSerial(serials[i])+1; |
||
246 | uSMC_Init(node[i],1); |
||
247 | } |
||
248 | #endif /* uSMC_USB */ |
||
249 | #ifdef SP2155_PORT |
||
250 | SP2155_Open (SP2155_PORT); |
||
251 | #endif /* SP2155_PORT */ |
||
252 | |||
253 | if ((p1h = LoadPanel (0, "qe2d_ui.uir", P1)) < 0) return -1; |
||
254 | DisplayPanel (p1h); |
||
255 | |||
256 | K617_open(1,PROLOGIX_PORT,K617_ADDR,0,13); |
||
257 | K617_clear(); |
||
258 | GetCtrlVal(p1h,P1_RANGE_R,&irange); |
||
259 | K617_current_mode(irange); |
||
260 | K617_zero_correct(1); |
||
261 | K617_data_format(0); |
||
262 | K617_trigger_mode(1); |
||
263 | |||
264 | #ifdef SP2155_PORT |
||
265 | igr=SP2155_GetGrating(); |
||
266 | SetCtrlVal (p1h, P1_GRATING, igr); |
||
267 | icwl = SP2155_GetWavelength (); |
||
268 | SetCtrlVal (p1h, P1_CWL, icwl); |
||
269 | #endif /* SP2155_PORT */ |
||
270 | |||
271 | QueueUserEvent (1000, p1h, P1_VOUT); |
||
272 | QueueUserEvent (1000, p1h, P1_VSOURCE); |
||
273 | QueueUserEvent (1000, p1h, P1_TIMER); |
||
274 | QueueUserEvent (1000, p1h, P1_WL0); |
||
275 | QueueUserEvent (1000, p1h, P1_POSITION); |
||
276 | |||
277 | fp = fopen ("refqe.txt", "r"); |
||
278 | nref=0; |
||
279 | while(1) { |
||
280 | iret=fscanf (fp, " %d %f", &wl[0][nref], &qe[0][nref]); |
||
281 | if (iret==2) nref++; |
||
282 | else break; |
||
283 | } |
||
284 | fclose (fp); |
||
285 | SetCtrlVal (p1h, P1_NREF, nref); |
||
286 | plqeh[0] = PlotXY (p1h, P1_GQE, wl[0], qe[0], nref, VAL_INTEGER, |
||
287 | VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE, |
||
288 | VAL_SOLID, 1, VAL_BLACK); |
||
289 | |||
290 | #ifdef MIKRO_COM |
||
291 | SetCtrlVal(p1h, P1_STAGELED,1); |
||
292 | for (i=0; i<3; i++) { |
||
293 | MIKRO_GetPosition(node[i],&CurPos[i]); |
||
294 | SetCtrlVal(p1h,PosCtrl[i],CurPos[i]); |
||
295 | } |
||
296 | SetCtrlVal(p1h,P1_STAGELED,0); |
||
297 | #endif /* MIKRO_COM */ |
||
298 | #ifdef uSMC_USB |
||
299 | SetCtrlVal(p1h, P1_STAGELED,1); |
||
300 | for (i=0; i<3; i++) { |
||
301 | uSMC_GetPosition(node[i],&CurPos[i]); |
||
302 | SetCtrlVal(p1h,PosCtrl[i],CurPos[i]); |
||
303 | } |
||
304 | SetCtrlVal(p1h, P1_STAGELED,0); |
||
305 | #endif /* uSMC_USB */ |
||
306 | |||
307 | do { |
||
308 | GetUserEvent (1, &pID, &rID); |
||
309 | switch (rID) { |
||
310 | case P1_TIMER: |
||
311 | rcurr=K617_get(NULL, NULL); |
||
312 | SetCtrlVal (p1h, P1_CURR, rcurr); |
||
313 | K617_status (); |
||
314 | SetCtrlVal (p1h, P1_VSOURCE, K617Stat.vsource_operate); |
||
315 | break; |
||
316 | case P1_GRATING: |
||
317 | GetCtrlVal (p1h, P1_GRATING, &igr); |
||
318 | #ifdef SP2155_PORT |
||
319 | SetCtrlVal (p1h, P1_GLED, 1); |
||
320 | SP2155_SetGrating (igr); |
||
321 | SetCtrlVal (p1h, P1_GLED, 0); |
||
322 | #endif /* SP2155_PORT */ |
||
323 | MessagePopup ("Reminder", "1.Switch the light source!\n2.Adjust the slit!\n3.Load the range file!"); |
||
324 | break; |
||
325 | case P1_WL0: |
||
326 | case P1_DWL: |
||
327 | case P1_NWL: |
||
328 | GetCtrlVal (p1h, P1_WL0, &iwl0); |
||
329 | GetCtrlVal (p1h, P1_DWL, &idwl); |
||
330 | GetCtrlVal (p1h, P1_NWL, &inwl); |
||
331 | ilwl=iwl0+(inwl-1)*idwl; |
||
332 | SetCtrlVal (p1h, P1_LWL, ilwl); |
||
333 | break; |
||
334 | case P1_CWL: |
||
335 | GetCtrlVal (p1h, P1_CWL, &icwl); |
||
336 | #ifdef SP2155_PORT |
||
337 | SetCtrlVal (p1h, P1_GLED, 1); |
||
338 | SP2155_SetWavelength (icwl); |
||
339 | SetCtrlVal (p1h, P1_GLED, 0); |
||
340 | #endif /* SP2155_PORT */ |
||
341 | break; |
||
342 | case P1_SCAN: |
||
343 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_ENABLED, 0); |
||
344 | GetCtrlVal (p1h, P1_WL0, &iwl0); |
||
345 | GetCtrlVal (p1h, P1_DWL, &idwl); |
||
346 | GetCtrlVal (p1h, P1_NWL, &inwl); |
||
347 | GetCtrlVal (p1h, P1_WAIT, &wait); |
||
348 | K617_trigger_mode(1); |
||
349 | MDelay(2); |
||
350 | for (i=0; i<inwl; i++) { |
||
351 | icwl=iwl0+i*idwl; |
||
352 | #ifdef SP2155_PORT |
||
353 | SetCtrlVal (p1h, P1_GLED, 1); |
||
354 | SP2155_SetWavelength(icwl); |
||
355 | SetCtrlVal (p1h, P1_GLED, 0); |
||
356 | #endif /* SP2155_PORT */ |
||
357 | SetCtrlVal (p1h, P1_CWL, icwl); |
||
358 | MDelay(wait); |
||
359 | rcurr=K617_get(NULL, NULL); |
||
360 | SetCtrlVal (p1h, P1_CURR, rcurr); |
||
361 | wl[1][i]=icwl; |
||
362 | tok[1][i]=-rcurr; |
||
363 | } |
||
364 | if (plh[1]) DeleteGraphPlot (p1h, P1_GSAMPLE, plh[1], VAL_IMMEDIATE_DRAW); |
||
365 | plh[1] = PlotXY (p1h, P1_GSAMPLE, wl[1], tok[1], inwl, VAL_INTEGER, VAL_FLOAT, |
||
366 | VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
||
367 | |||
368 | K617_trigger_mode(0); |
||
369 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_ENABLED, 1); |
||
370 | break; |
||
371 | case P1_READREFCURR: |
||
372 | iret = FileSelectPopup ("", "*.dat", ".dat", |
||
373 | "Izberi binarno datoteko za meritve", |
||
374 | VAL_SELECT_BUTTON, 0, 0, 1, 1, pfile); |
||
375 | |||
376 | if (iret==1) { |
||
377 | fp = fopen (pfile, "rb"); |
||
378 | nb=fread(hdr,sizeof(int),5,fp); |
||
379 | //printf("[%d] %d %d %d %d %d\n",nb, hdr[0], hdr[1], hdr[2], hdr[3],hdr[4]); |
||
380 | switch (hdr[0]) { |
||
381 | case 3: { |
||
382 | nb=fread(&hdr[5],sizeof(int),5,fp); |
||
383 | //printf("x=%u y=%u | i0=%g i1=%g t=%u\t",hdr[5],hdr[6],fhdr[7],fhdr[8],hdr[9]); |
||
384 | } |
||
385 | case 2: |
||
386 | case 1: |
||
387 | nref=hdr[1]/sizeof(int)/5-1; |
||
388 | if (hdr[0]==3) nref--; |
||
389 | //printf("%d [%d] x=%d y=%d\n",hdr[2],nref, hdr[3],hdr[4]); |
||
390 | for (i=0; i<nref; i++) { |
||
391 | nb=fread(sdata,sizeof(float),5,fp); |
||
392 | wl[0][i]=sdata[0]; |
||
393 | tok[0][i]=sdata[1]; |
||
394 | qe[0][i]=sdata[3]; |
||
395 | } |
||
396 | SetCtrlVal (p1h, P1_NREF, nref); |
||
397 | if (plqeh[0]) DeleteGraphPlot (p1h, P1_GQE, plqeh[0], VAL_IMMEDIATE_DRAW); |
||
398 | plqeh[0] = PlotXY (p1h, P1_GQE, wl[0], qe[0], nref, VAL_INTEGER, |
||
399 | VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE, |
||
400 | VAL_SOLID, 1, VAL_BLACK); |
||
401 | if (plh[0]) DeleteGraphPlot (p1h, P1_GREF, plh[0], VAL_IMMEDIATE_DRAW); |
||
402 | plh[0] = PlotXY (p1h, P1_GREF, wl[0], tok[0], nref, VAL_INTEGER, VAL_FLOAT, |
||
403 | VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
||
404 | break; |
||
405 | } |
||
406 | fclose(fp); |
||
407 | } |
||
408 | break; |
||
409 | case P1_REFSCAN: |
||
410 | MessagePopup ("Reminder", "Switch the cable to measure the reference PMT current!"); |
||
411 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_ENABLED, 0); |
||
412 | #ifdef MIKRO_COM |
||
413 | SetCtrlVal (p1h, P1_STAGELED, 1); |
||
414 | for (i=0; i<2; i++) { |
||
415 | GetTableCellVal(p1h,P1_POINTS,MakePoint(i+1,1),&CurPos[i]); |
||
416 | MIKRO_MoveTo(node[i],CurPos[i]); |
||
417 | MIKRO_GetPosition (node[i],&CurPos[i]); |
||
418 | SetCtrlVal (p1h, PosCtrl[i],CurPos[i]); |
||
419 | } |
||
420 | SetCtrlVal (p1h, P1_STAGELED, 0); |
||
421 | #endif /* MIKRO_COM */ |
||
422 | #ifdef uSMC_USB |
||
423 | SetCtrlVal (p1h, P1_STAGELED, 1); |
||
424 | for (i=0; i<2; i++) { |
||
425 | GetTableCellVal(p1h,P1_POINTS,MakePoint(i+1,1),&CurPos[i]); |
||
426 | uSMC_MoveTo(node[i],CurPos[i]); |
||
427 | uSMC_GetPosition (node[i],&CurPos[i]); |
||
428 | SetCtrlVal (p1h, PosCtrl[i],CurPos[i]); |
||
429 | } |
||
430 | SetCtrlVal (p1h, P1_STAGELED, 0); |
||
431 | #endif /* uSMC_USB */ |
||
432 | K617_trigger_mode(1); |
||
433 | #ifdef SP2155_PORT |
||
434 | SetCtrlVal (p1h, P1_GLED, 1); |
||
435 | SP2155_SetWavelength(1000); |
||
436 | SetCtrlVal (p1h, P1_GLED, 0); |
||
437 | #endif /* SP2155_PORT */ |
||
438 | GetCtrlVal (p1h, P1_WAIT0, &wait); |
||
439 | if (MDelay(wait*60.)) break; |
||
440 | GetCtrlVal (p1h, P1_WAIT, &wait); |
||
441 | tokoff[0]=getavg(ncurroff); |
||
442 | SetCtrlVal (p1h, P1_BGRCUR0,tokoff[0]); |
||
443 | for (i=0; i<nref; i++) { |
||
444 | icwl=wl[0][i]; |
||
445 | #ifdef SP2155_PORT |
||
446 | SetCtrlVal (p1h, P1_GLED, 1); |
||
447 | SP2155_SetWavelength(icwl); |
||
448 | SetCtrlVal (p1h, P1_GLED, 0); |
||
449 | #endif /* SP2155_PORT */ |
||
450 | SetCtrlVal (p1h, P1_CWL, icwl); |
||
451 | if (MDelay(wait)) break; |
||
452 | rcurr=getavg(ncurrmes); |
||
453 | SetCtrlVal (p1h, P1_CURR, rcurr); |
||
454 | tok[0][i]=-(rcurr-tokoff[0]); |
||
455 | } |
||
456 | if (plh[0]) DeleteGraphPlot (p1h, P1_GREF, plh[0], VAL_IMMEDIATE_DRAW); |
||
457 | plh[0] = PlotXY (p1h, P1_GREF, wl[0], tok[0], nref, VAL_INTEGER, VAL_FLOAT, |
||
458 | VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); |
||
459 | |||
460 | K617_trigger_mode(0); |
||
461 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_ENABLED, 1); |
||
462 | break; |
||
463 | case P1_QESCAN: |
||
464 | MessagePopup ("Reminder", "Switch the cable to measure the sample detector current!"); |
||
465 | // moved the delay into qescan() |
||
466 | //GetCtrlVal (p1h, P1_WAIT0, &wait); |
||
467 | //if (MDelay(wait*60)) break; |
||
468 | |||
469 | // reset plots for new scan |
||
470 | for (i=1; i<MAXXY; i++) { |
||
471 | if(plqeh[i]) SetPlotAttribute (p1h, P1_GQE, plqeh[i], ATTR_TRACE_COLOR, VAL_LT_GRAY); |
||
472 | if(plh[i]) SetPlotAttribute (p1h, P1_GSAMPLE, plh[i], ATTR_TRACE_COLOR, VAL_LT_GRAY); |
||
473 | |||
474 | plh[i]=0; |
||
475 | plqeh[i]=0; |
||
476 | } |
||
477 | if(plqeh[0]) DeleteGraphPlot (p1h, P1_GQE, plqeh[0], VAL_IMMEDIATE_DRAW); |
||
478 | plqeh[0] = PlotXY (p1h, P1_GQE, wl[0], qe[0], nref, VAL_INTEGER, |
||
479 | VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE, |
||
480 | VAL_SOLID, 1, VAL_BLACK); |
||
481 | RefreshGraph (p1h, P1_GQE); |
||
482 | RefreshGraph (p1h, P1_GSAMPLE); |
||
483 | |||
484 | qescan(); |
||
485 | break; |
||
486 | case P1_QESCANALL: |
||
487 | MessagePopup ("Reminder", "Switch the cable to measure the sample detector current!"); |
||
488 | iret=FileSelectPopup ("", "*.dat", ".dat", |
||
489 | "Izberi binarno datoteko za meritve", |
||
490 | VAL_SAVE_BUTTON, 0, 0, 1, 1, pfile); |
||
491 | |||
492 | if (iret==1||(iret==2)) { |
||
493 | // moved the delay into qescan() |
||
494 | //GetCtrlVal (p1h, P1_WAIT0, &wait); |
||
495 | //if (MDelay(wait*60)) break; |
||
496 | |||
497 | // reset plots for new scan |
||
498 | /*DeleteGraphPlot (p1h, P1_GQE, -1, VAL_IMMEDIATE_DRAW); |
||
499 | plqeh[0] = PlotXY (p1h, P1_GQE, wl[0], qe[0], nref, VAL_INTEGER, |
||
500 | VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE, |
||
501 | VAL_SOLID, 1, VAL_BLACK); |
||
502 | DeleteGraphPlot (p1h, P1_GSAMPLE, -1, VAL_IMMEDIATE_DRAW); |
||
503 | for (i=0; i<MAXXY; i++) { |
||
504 | plh[i]=0; |
||
505 | plqeh[i]=0; |
||
506 | } |
||
507 | */ |
||
508 | for (i=1; i<MAXXY; i++) { |
||
509 | if(plqeh[i]) SetPlotAttribute (p1h, P1_GQE, plqeh[i], ATTR_TRACE_COLOR, VAL_LT_GRAY); |
||
510 | if(plh[i]) SetPlotAttribute (p1h, P1_GSAMPLE, plh[i], ATTR_TRACE_COLOR, VAL_LT_GRAY); |
||
511 | |||
512 | plh[i]=0; |
||
513 | plqeh[i]=0; |
||
514 | } |
||
515 | if(plqeh[0]) DeleteGraphPlot (p1h, P1_GQE, plqeh[0], VAL_IMMEDIATE_DRAW); |
||
516 | plqeh[0] = PlotXY (p1h, P1_GQE, wl[0], qe[0], nref, VAL_INTEGER, |
||
517 | VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE, |
||
518 | VAL_SOLID, 1, VAL_BLACK); |
||
519 | RefreshGraph (p1h, P1_GQE); |
||
520 | RefreshGraph (p1h, P1_GSAMPLE); |
||
521 | |||
522 | |||
523 | |||
524 | fp = fopen (pfile, "wb"); |
||
525 | |||
526 | GetNumTableRows(p1h, P1_POINTS, &nrows); |
||
527 | for (j=1; j<nrows; j++) { |
||
528 | SetCtrlVal (p1h, P1_POSITION, j); |
||
529 | SetTableSelection (p1h, P1_POINTS, MakeRect(j+1,1,1,2)); |
||
530 | GetTableCellVal (p1h, P1_POINTS, MakePoint (1,j+1), &CurPos[0]); |
||
531 | GetTableCellVal (p1h, P1_POINTS, MakePoint (2,j+1), &CurPos[1]); |
||
532 | if (CurPos[0] <= 0 && CurPos[1]<= 0) { |
||
533 | j=nrows ; |
||
534 | continue; |
||
535 | } |
||
536 | iret=qescan(); |
||
537 | if (iret) break; |
||
538 | GetCtrlVal (p1h, P1_X, &CurPos[0]); |
||
539 | GetCtrlVal (p1h, P1_Y, &CurPos[1]); |
||
540 | |||
541 | hdr[0]=3;//recid 1,2= hdr len=5, 3=hdr len=10 |
||
542 | hdr[1]=(nref*5+10)*sizeof(int); |
||
543 | hdr[2]=j; |
||
544 | hdr[3]=CurPos[0]; |
||
545 | hdr[4]=CurPos[1]; |
||
546 | GetTableCellVal (p1h, P1_POINTS, MakePoint (1,j+1), &CurPos[0]); |
||
547 | GetTableCellVal (p1h, P1_POINTS, MakePoint (2,j+1), &CurPos[1]); |
||
548 | hdr[5]=CurPos[0]; |
||
549 | hdr[6]=CurPos[1]; |
||
550 | fhdr[7]=tokoff[0]; |
||
551 | fhdr[8]=tokoff[j]; |
||
552 | hdr[9]=time(NULL); |
||
553 | //printf("--> %d %d %d %d %d\n", hdr[0],hdr[1],hdr[2],hdr[3],hdr[4]); |
||
554 | fwrite (hdr, sizeof(int), 10, fp); |
||
555 | for (i=0; i<nref; i++) { |
||
556 | sdata[0]=wl[0][i]; |
||
557 | sdata[1]=tok[0][i]; |
||
558 | sdata[2]=tok[j][i]; |
||
559 | sdata[3]=qe[0][i]; |
||
560 | sdata[4]=qe[j][i]; |
||
561 | |||
562 | fwrite (sdata, sizeof(float), 5, fp); |
||
563 | } |
||
564 | } |
||
565 | fclose (fp); |
||
566 | |||
567 | |||
568 | } |
||
569 | |||
570 | break; |
||
571 | case P1_HO: |
||
572 | // if (!daq_on) { |
||
573 | SetWaitCursor (1); |
||
574 | #ifdef MIKRO_COM |
||
575 | SetCtrlVal(p1h,P1_STAGELED,1); |
||
576 | for (i=0; i<3; i++) MIKRO_ReferenceMove(node[i]); |
||
577 | SetCtrlVal(p1h,P1_STAGELED,0); |
||
578 | #endif /* MIKRO_COM */ |
||
579 | #ifdef uSMC_USB |
||
580 | SetCtrlVal(p1h,P1_STAGELED,1); |
||
581 | for (i=0; i<3; i++)uSMC_ReferenceMove(node[i]); |
||
582 | SetCtrlVal(p1h,P1_STAGELED,0); |
||
583 | #endif /* uSMC_USB */ |
||
584 | SetWaitCursor (0); |
||
585 | // } |
||
586 | break; |
||
587 | case P1_GOXY: |
||
588 | GetCtrlVal(p1h,P1_POSITION,&npos); |
||
589 | #ifdef MIKRO_COM |
||
590 | SetCtrlVal(p1h,P1_STAGELED,1); |
||
591 | for (i=0; i<2; i++) { |
||
592 | GetTableCellVal(p1h,P1_POINTS,MakePoint(i+1,npos+1),&CurPos[i]); |
||
593 | MIKRO_MoveTo(node[i],CurPos[i]); |
||
594 | MIKRO_GetPosition (node[i],&CurPos[i]); |
||
595 | SetCtrlVal (p1h,PosCtrl[i],CurPos[i]); |
||
596 | } |
||
597 | SetCtrlVal(p1h,P1_STAGELED,0); |
||
598 | #endif /* MIKRO_COM */ |
||
599 | #ifdef uSMC_USB |
||
600 | SetCtrlVal(p1h,P1_STAGELED,1); |
||
601 | for (i=0; i<2; i++) { |
||
602 | GetTableCellVal(p1h,P1_POINTS,MakePoint(i+1,npos+1),&CurPos[i]); |
||
603 | uSMC_MoveTo(node[i],CurPos[i]); |
||
604 | uSMC_GetPosition (node[i],&CurPos[i]); |
||
605 | SetCtrlVal (p1h,PosCtrl[i],CurPos[i]); |
||
606 | } |
||
607 | SetCtrlVal(p1h,P1_STAGELED,0); |
||
608 | #endif /* uSMC_USB */ |
||
609 | break; |
||
610 | case P1_ZC: |
||
611 | K617_zero_correct(1); |
||
612 | break; |
||
613 | case P1_VOUT: |
||
614 | GetCtrlVal (p1h, P1_VOUT, &vout); |
||
615 | K617_vsource_set (vout); |
||
616 | break; |
||
617 | case P1_VSOURCE: |
||
618 | GetCtrlVal (p1h, P1_VSOURCE, &vsource); |
||
619 | K617_vsource_operate (vsource); |
||
620 | break; |
||
621 | case P1_RANGE_R: |
||
622 | GetCtrlVal(p1h,P1_RANGE_R,&irange); |
||
623 | K617_current_mode(irange); |
||
624 | break; |
||
625 | case P1_LOADPOINTS: |
||
626 | iret = FileSelectPopup ("", "*.txt", ".txt", |
||
627 | "Izberi datoteko s pozicijami", |
||
628 | VAL_LOAD_BUTTON, 0, 0, 1, 0, pfile); |
||
629 | if (iret==1) { |
||
630 | fp = fopen (pfile, "r"); |
||
631 | i=1; |
||
632 | while(1) { |
||
633 | iret=fscanf (fp, " %d %d", &CurPos[0], &CurPos[1]); |
||
634 | if (iret==2) { |
||
635 | SetTableCellVal (p1h, P1_POINTS, MakePoint (1,i), CurPos[0]); |
||
636 | SetTableCellVal (p1h, P1_POINTS, MakePoint (2,i), CurPos[1]); |
||
637 | i++; |
||
638 | } else |
||
639 | break; |
||
640 | } |
||
641 | fclose (fp); |
||
642 | } |
||
643 | break; |
||
644 | case P1_SAVEPOINTS: |
||
645 | iret=FileSelectPopup ("", "*.txt", ".txt", |
||
646 | "Izberi datoteko s pozicijami", |
||
647 | VAL_SAVE_BUTTON, 0, 0, 1, 1, pfile); |
||
648 | if ((iret==1)||(iret==2)) { |
||
649 | fp=fopen(pfile,"w"); |
||
650 | GetNumTableRows(p1h, P1_POINTS, &i); |
||
651 | for (j=0; j<i;) { |
||
652 | j++; |
||
653 | GetTableCellVal (p1h, P1_POINTS, MakePoint (1,j), &CurPos[0]); |
||
654 | GetTableCellVal (p1h, P1_POINTS, MakePoint (2,j), &CurPos[1]); |
||
655 | fprintf(fp,"%d %d\n", CurPos[0], CurPos[1]); |
||
656 | } |
||
657 | fclose (fp); |
||
658 | } |
||
659 | break; |
||
660 | case P1_SAVEQE: |
||
661 | iret=FileSelectPopup ("", "*.txt", ".txt", |
||
662 | "Izberi datoteko za meritve", |
||
663 | VAL_SAVE_BUTTON, 0, 0, 1, 1, pfile); |
||
664 | if (iret==1||(iret==2)) { |
||
665 | fp = fopen (pfile, "w"); |
||
666 | GetCtrlVal (p1h, P1_POSITION, &npos); |
||
667 | for (i=0; i<nref; i++) |
||
668 | fprintf(fp,"%d %g %g %g %g\n", |
||
669 | wl[0][i],tok[0][i],tok[npos][i],qe[0][i],qe[npos][i]); |
||
670 | fclose (fp); |
||
671 | } |
||
672 | break; |
||
673 | case P1_POSITION: |
||
674 | GetCtrlVal(p1h,P1_POSITION,&npos); |
||
675 | SetTableSelection (p1h, P1_POINTS, MakeRect(npos+1,1,1,2)); |
||
676 | break; |
||
677 | case P1_READQE: |
||
678 | iret = FileSelectPopup ("", "*.txt", ".txt", |
||
679 | "Izberi referencni QE", |
||
680 | VAL_LOAD_BUTTON, 0, 0, 1, 0, pfile); |
||
681 | if (iret==1) { |
||
682 | fp = fopen (pfile, "r"); |
||
683 | nref=0; |
||
684 | while(1) { |
||
685 | iret=fscanf (fp, " %d %f", &wl[0][nref], &qe[0][nref]); |
||
686 | if (iret==2) nref++; |
||
687 | else break; |
||
688 | } |
||
689 | fclose (fp); |
||
690 | SetCtrlVal (p1h, P1_NREF, nref); |
||
691 | if (plqeh[0]) DeleteGraphPlot (p1h, P1_GQE, plqeh[0], VAL_IMMEDIATE_DRAW); |
||
692 | plqeh[0] = PlotXY (p1h, P1_GQE, wl[0], qe[0], nref, VAL_INTEGER, |
||
693 | VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE, |
||
694 | VAL_SOLID, 1, VAL_BLACK); |
||
695 | } |
||
696 | break; |
||
697 | case P1_GLED: |
||
698 | break; |
||
699 | case P1_ZSET: |
||
700 | GetCtrlVal(p1h,P1_ZSETTO,&CurPos[2]); |
||
701 | #ifdef MIKRO_COM |
||
702 | SetCtrlVal(p1h,P1_STAGELED,1); |
||
703 | MIKRO_MoveTo(node[2],CurPos[2]); |
||
704 | MIKRO_GetPosition (node[2],&CurPos[2]); |
||
705 | SetCtrlVal (p1h,PosCtrl[2],CurPos[2]); |
||
706 | SetCtrlVal(p1h,P1_STAGELED,0); |
||
707 | #endif /* MIKRO_COM */ |
||
708 | #ifdef uSMC_USB |
||
709 | SetCtrlVal(p1h,P1_STAGELED,1); |
||
710 | uSMC_MoveTo(node[2],CurPos[2]); |
||
711 | uSMC_GetPosition (node[2],&CurPos[2]); |
||
712 | SetCtrlVal (p1h,PosCtrl[2],CurPos[2]); |
||
713 | SetCtrlVal(p1h,P1_STAGELED,0); |
||
714 | #endif /* uSMC_USB */ |
||
715 | break; |
||
716 | } |
||
717 | |||
718 | } while ((rID != P1_EXIT)||scan_on); |
||
719 | |||
720 | DiscardPanel (p1h); |
||
721 | |||
722 | K617_trigger_mode (0); |
||
723 | K617_close (); |
||
724 | #ifdef SP2155_PORT |
||
725 | SP2155_Close (); |
||
726 | #endif /* SP2155_PORT */ |
||
727 | #ifdef MIKRO_COM |
||
728 | MIKRO_Close (); |
||
729 | #endif /* MIKRO_COM */ |
||
730 | #ifdef uSMC_USB |
||
731 | for (i=0; i<3; i++) uSMC_PowerOff(node[i]); |
||
732 | uSMC_Close(); |
||
733 | #endif /* uSMC_USB */ |
||
734 | |||
735 | return 0; |
||
736 | } |