Rev 304 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
281 | f9daq | 1 | #include <formatio.h> |
2 | #include <userint.h> |
||
3 | #include <ansi_c.h> |
||
4 | #include <utility.h> |
||
5 | #include <gpib.h> |
||
6 | #include "toolbox.h" |
||
7 | #include "prologix.h" |
||
8 | #include "K6517.h" |
||
9 | |||
10 | K6517STATUS K6517Stat; |
||
11 | static int K6517_Interface,K6517_Port,K6517_Gdev; |
||
12 | static int iret; |
||
13 | static int stop; |
||
14 | int _VI_FUNC K6517_status_print (void); |
||
15 | void GpibError(char *msg) { |
||
16 | |||
17 | printf ("%s\n", msg); |
||
18 | |||
19 | printf ("ibsta = &H%x <", ibsta); |
||
20 | if (ibsta & ERR ) printf (" ERR"); |
||
21 | if (ibsta & TIMO) printf (" TIMO"); |
||
22 | if (ibsta & END ) printf (" END"); |
||
23 | if (ibsta & SRQI) printf (" SRQI"); |
||
24 | if (ibsta & RQS ) printf (" RQS"); |
||
25 | if (ibsta & CMPL) printf (" CMPL"); |
||
26 | if (ibsta & LOK ) printf (" LOK"); |
||
27 | if (ibsta & REM ) printf (" REM"); |
||
28 | if (ibsta & CIC ) printf (" CIC"); |
||
29 | if (ibsta & ATN ) printf (" ATN"); |
||
30 | if (ibsta & TACS) printf (" TACS"); |
||
31 | if (ibsta & LACS) printf (" LACS"); |
||
32 | if (ibsta & DTAS) printf (" DTAS"); |
||
33 | if (ibsta & DCAS) printf (" DCAS"); |
||
34 | printf (" >\n"); |
||
35 | |||
36 | printf ("iberr = %d", iberr); |
||
37 | if (iberr == EDVR) printf (" EDVR <DOS Error>\n"); |
||
38 | if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n"); |
||
39 | if (iberr == ENOL) printf (" ENOL <No Listener>\n"); |
||
40 | if (iberr == EADR) printf (" EADR <Address error>\n"); |
||
41 | if (iberr == EARG) printf (" EARG <Invalid argument>\n"); |
||
42 | if (iberr == ESAC) printf (" ESAC <Not System Controller>\n"); |
||
43 | if (iberr == EABO) printf (" EABO <Operation aborted>\n"); |
||
44 | if (iberr == ENEB) printf (" ENEB <No GPIB board>\n"); |
||
45 | if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n"); |
||
46 | if (iberr == ECAP) printf (" ECAP <No capability>\n"); |
||
47 | if (iberr == EFSO) printf (" EFSO <File system error>\n"); |
||
48 | if (iberr == EBUS) printf (" EBUS <Command error>\n"); |
||
49 | if (iberr == ESTB) printf (" ESTB <Status byte lost>\n"); |
||
50 | if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n"); |
||
51 | if (iberr == ETAB) printf (" ETAB <Table Overflow>\n"); |
||
52 | |||
53 | printf ("ibcntl = %ld\n", ibcntl); |
||
54 | printf ("\n"); |
||
55 | |||
56 | /* Call ibonl to take the device and interface offline */ |
||
57 | ibonl (K6517_Gdev,0); |
||
58 | |||
59 | exit(1); |
||
60 | } |
||
61 | |||
62 | void _VI_FUNC K6517_open (int interface, int port, int primary_addr, |
||
63 | int secondary_addr, int timeout) |
||
64 | { |
||
65 | char cmd[100]; |
||
66 | int status; |
||
67 | /* |
||
68 | K6517_Gdev = OpenDev ("GPIB0", ""); |
||
69 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
70 | iret = ibpad (K6517_Gdev, 0); |
||
71 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
72 | iret = ibsad (K6517_Gdev, NO_SAD); |
||
73 | iret = ibtmo (K6517_Gdev, T10s); |
||
74 | iret = ibeot (K6517_Gdev, 1); |
||
75 | iret = ibeos (K6517_Gdev, 0); |
||
76 | */ |
||
77 | K6517_Interface=interface; |
||
78 | K6517_Port=port; |
||
79 | switch (K6517_Interface){ |
||
80 | case 1: |
||
81 | status = PROLOGIX_Open (K6517_Port); |
||
82 | printf("K6517_open %d\n", status); |
||
83 | sprintf(cmd,"++addr %0d",primary_addr); |
||
84 | PROLOGIX_Send (cmd); |
||
85 | PROLOGIX_Send ("++auto 0"); |
||
86 | PROLOGIX_Send ("++eoi 1"); |
||
87 | PROLOGIX_Send ("++eot_enable 0"); |
||
88 | PROLOGIX_Send ("++read_tmo_ms 1000"); |
||
89 | break; |
||
90 | default: |
||
91 | K6517_Gdev = ibdev(K6517_Port,primary_addr,secondary_addr,timeout,1,0); |
||
92 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
93 | } |
||
94 | printf("Interface %d\n", interface); |
||
95 | K6517_send("*RST",0); |
||
96 | K6517_send("*IDN?", 5); |
||
97 | char cres[100]; |
||
98 | cres[0]= 0; |
||
99 | int len = K6517_receive (cres, 50); |
||
100 | printf("[%d] %s\n", len, cres); |
||
101 | |||
102 | Delay(GDELAY); |
||
103 | return; |
||
104 | } |
||
105 | |||
106 | void _VI_FUNC K6517_clear (void) |
||
107 | { |
||
108 | switch (K6517_Interface){ |
||
109 | case 1: |
||
110 | PROLOGIX_Send("++clr"); |
||
111 | break; |
||
112 | default: |
||
113 | iret = ibclr (K6517_Gdev); // Clear the device |
||
114 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
115 | } |
||
116 | // Delay(GDELAY); |
||
117 | Delay(2.); |
||
118 | return; |
||
119 | } |
||
120 | |||
121 | void _VI_FUNC K6517_send (char *cmd, int len) |
||
122 | { |
||
123 | printf("-> %s\n", cmd); |
||
124 | if (!len) len = strlen(cmd); |
||
125 | switch (K6517_Interface){ |
||
126 | case 1: |
||
127 | PROLOGIX_Send(cmd); |
||
128 | break; |
||
129 | default: |
||
130 | iret = ibwrt (K6517_Gdev, cmd, len); |
||
131 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
132 | } |
||
133 | Delay(GDELAY); |
||
134 | return; |
||
135 | } |
||
136 | |||
137 | int _VI_FUNC K6517_receive (char *response, int maxbyt) |
||
138 | { |
||
139 | int ierr=0; |
||
140 | switch (K6517_Interface){ |
||
141 | case 1: |
||
142 | PROLOGIX_Send("++read eoi"); |
||
143 | ierr= PROLOGIX_Receive (response,maxbyt); |
||
144 | printf("<---Read [%d] %s\n", ierr, response); |
||
145 | return ierr; |
||
146 | break; |
||
147 | default: |
||
148 | iret = ibrd (K6517_Gdev, response, maxbyt); |
||
149 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
150 | response[ibcntl]=0; |
||
151 | return ibcntl; |
||
152 | } |
||
153 | } |
||
154 | |||
155 | void _VI_FUNC K6517_status (void) |
||
156 | { |
||
157 | int len; |
||
158 | char cres[100]; |
||
159 | |||
160 | K6517_send ("U0X", 3); |
||
161 | len = K6517_receive (cres, 90); |
||
162 | sscanf(cres," 617%1d%2d%1d%1d%1d%1d%1d%1d%1d%1d%1d%2d%1d%2c", |
||
163 | &K6517Stat.function,&K6517Stat.range,&K6517Stat.zero_check, |
||
164 | &K6517Stat.zero_correct,&K6517Stat.suppress,&K6517Stat.trigger, |
||
165 | &K6517Stat.vsource_operate,&K6517Stat.read_mode, |
||
166 | &K6517Stat.data_prefix,&K6517Stat.display, |
||
167 | &K6517Stat.data_store,&K6517Stat.srq,&K6517Stat.eoi,K6517Stat.terminator); |
||
168 | printf("617FRRCZNTOBGDQMMKYY\n"); |
||
169 | printf("%s\n",cres); |
||
170 | // K6517_send ("X", 1); |
||
171 | return; |
||
172 | } |
||
173 | |||
174 | void _VI_FUNC K6517_data_format (int mode) |
||
175 | { |
||
176 | int len; |
||
177 | char cmd[100]; |
||
178 | |||
179 | len=sprintf(cmd,"G%0dX",mode); |
||
180 | K6517_send (cmd, len); |
||
181 | return; |
||
182 | } |
||
183 | |||
184 | double _VI_FUNC K6517_get (char *prefix, int *loc) |
||
185 | { |
||
186 | |||
187 | double value; |
||
188 | char cres[100]; |
||
189 | |||
190 | K6517_send ("SENS:FUNC 'curr'",0); |
||
191 | // K6517_send (":SENS:CURR:RANG:UPP 21e-3",0); |
||
192 | // K6517_send ("SYST:ZCH 0",0); |
||
193 | K6517_send ("READ?",0); |
||
194 | |||
195 | cres[0]= 0; |
||
196 | int len = K6517_receive (cres, 50); |
||
197 | printf("current >%d, %s\n",len,cres); |
||
198 | |||
199 | return atof(cres); |
||
200 | /* |
||
201 | K6517_send ("X", 1); |
||
202 | len = K6517_receive (cres, 50); |
||
203 | if (loc) { |
||
204 | *loc=-1; |
||
205 | sscanf(cres,"%4c%lg,%d",prefix, &value, loc); |
||
206 | prefix[4]=0; |
||
207 | } else { |
||
208 | sscanf(cres,"%*4c%lg,%*d",&value); |
||
209 | } |
||
210 | |||
211 | return value; |
||
212 | */ |
||
213 | |||
214 | } |
||
215 | |||
216 | void _VI_FUNC K6517_current_mode (double range) |
||
217 | { |
||
218 | int len; |
||
219 | char cmd[100]; |
||
220 | |||
221 | if (range > 0) { |
||
222 | len=sprintf(cmd,":SENS:CURR:RANG:AUTO OFF"); |
||
223 | len=sprintf(cmd,":SENS:CURR:RANG:UPP %g",range); |
||
224 | } |
||
225 | else len=sprintf(cmd,":SENS:CURR:RANG:AUTO ON"); |
||
226 | // printf("%d, %s\n",len,cmd); |
||
227 | K6517_send (cmd, len); |
||
228 | Delay(1); |
||
229 | K6517_send ("SYST:ZCH 0",0); |
||
230 | return; |
||
231 | } |
||
232 | |||
233 | void _VI_FUNC K6517_zero_correct (int zcorrect) |
||
234 | { |
||
235 | K6517_send ("C0X", 3); |
||
236 | K6517_send ("Z0X", 3); |
||
237 | if (zcorrect) { |
||
238 | K6517_send ("C1X", 3); |
||
239 | Delay(2); |
||
240 | K6517_send ("Z1X", 3); |
||
241 | K6517_send ("C0X", 3); |
||
242 | } |
||
243 | return; |
||
244 | } |
||
245 | |||
246 | void _VI_FUNC K6517_trigger_mode (int mode) |
||
247 | { |
||
248 | int len; |
||
249 | char cmd[100]; |
||
250 | |||
251 | //len=sprintf(cmd,"T%0dX",mode); |
||
252 | //K6517_send (cmd, len); |
||
253 | return; |
||
254 | } |
||
255 | |||
256 | void _VI_FUNC K6517_reading_mode (int mode) |
||
257 | { |
||
258 | int len; |
||
259 | char cmd[100]; |
||
260 | |||
261 | //len=sprintf(cmd,"B%0dX",mode); |
||
262 | //K6517_send (cmd, len); |
||
263 | return; |
||
264 | } |
||
265 | |||
266 | void _VI_FUNC K6517_vsource_set (float value) |
||
267 | { |
||
268 | int len; |
||
269 | char cmd[100]; |
||
270 | len=sprintf(cmd,":SOURCE:VOLTAGE %f",value); |
||
271 | K6517_send (cmd, len); |
||
272 | return; |
||
273 | } |
||
274 | |||
275 | double _VI_FUNC K6517_vsource_get (void) |
||
276 | { |
||
277 | double value; |
||
278 | |||
279 | /* |
||
280 | K6517_send ("SENS:FUNC 'volt'",0); |
||
281 | K6517_send ("SENS:VOLT:RANG:AUTO ON",0); |
||
282 | K6517_send ("SYST:ZCH 0",0); |
||
283 | K6517_send ("READ?",0); |
||
284 | */ |
||
285 | K6517_send (":MEASure:VOLTage?",0); |
||
286 | char cres[100]; |
||
287 | cres[0]= 0; |
||
288 | int len = K6517_receive (cres, 50); |
||
289 | |||
290 | |||
291 | return atof(cres); |
||
292 | } |
||
293 | |||
294 | void _VI_FUNC K6517_vsource_operate (int operate) |
||
295 | { |
||
296 | |||
297 | if (operate){ |
||
298 | // K6517_send (":SOURCE:VOLTAGE:MCONNECT 1", 0); |
||
299 | // K6517_send (":SENS:VOLTAGE:MANual:VSOurce:OPERate 1", 0); |
||
300 | //K6517_send (":MCONNECT 1", 0); |
||
301 | K6517_send (":OUTP ON", 0); |
||
302 | |||
303 | // K6517_send (":SOURCE:VOLTAGE:RANGE 99", 0); |
||
304 | // K6517_send (":SOURCE:VOLTAGE 22", 0); |
||
305 | } else { |
||
306 | //K6517_send (":SOURCE:VOLTAGE 0", 0); |
||
307 | // K6517_send (":SENSe:VOLTAGE:MANual:VSOurce:OPERate 0", 0); |
||
308 | // K6517_send (":SOURCE:VOLTAGE:MCONNECT 0", 0); |
||
309 | K6517_send (":OUTP OFF", 0); |
||
310 | //K6517_send (":MCONNECT 0", 0); |
||
311 | |||
312 | } |
||
313 | K6517_send (":STATUS:OPER?",0); |
||
314 | char cres[100]; |
||
315 | cres[0]= 0; |
||
316 | int len = K6517_receive (cres, 50); |
||
317 | |||
318 | |||
319 | // return atoi(cres); |
||
320 | } |
||
321 | |||
322 | void _VI_FUNC K6517_close (void) |
||
323 | { |
||
324 | // iret = CloseDev (K6517_Gdev); |
||
325 | switch (K6517_Interface){ |
||
326 | case 1: |
||
327 | PROLOGIX_Close(); |
||
328 | break; |
||
329 | default: |
||
330 | iret = ibonl(K6517_Gdev, 0);// Take the device offline |
||
331 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
332 | } |
||
333 | return; |
||
334 | } |
||
335 | |||
336 | void _VI_FUNC K6517_test (void) |
||
337 | { |
||
338 | int i; |
||
339 | double value; |
||
340 | char cres[100]; |
||
341 | |||
342 | K6517_clear (); |
||
343 | K6517_current_mode (0); |
||
344 | K6517_zero_correct (1); |
||
345 | K6517_data_format (0); |
||
346 | K6517_trigger_mode (1); |
||
347 | K6517_vsource_set (-100.); |
||
348 | K6517_vsource_operate (1); |
||
349 | |||
350 | K6517_status(); |
||
351 | |||
352 | value=K6517_get(cres,&i); |
||
353 | printf("%s, %lg, %d\n",cres,value,i); |
||
354 | value=K6517_vsource_get(); |
||
355 | printf("%lg\n",value); |
||
356 | value=K6517_get(cres,&i); |
||
357 | printf("%s, %lg, %d\n",cres,value,i); |
||
358 | value=K6517_get(cres,&i); |
||
359 | printf("%s, %lg, %d\n",cres,value,i); |
||
360 | value=K6517_get(cres,&i); |
||
361 | printf("%s, %lg, %d\n",cres,value,i); |
||
362 | value=K6517_get(cres,&i); |
||
363 | printf("%s, %lg, %d\n",cres,value,i); |
||
364 | Delay(5); |
||
365 | K6517_vsource_operate (0); |
||
366 | |||
367 | |||
368 | } |
||
369 | |||
370 | #ifdef K6517_MAIN |
||
371 | |||
372 | #include <cvirte.h> |
||
373 | #include <userint.h> |
||
374 | #include "K6517-ctrl.h" |
||
375 | int pnl; int gLogToFile; |
||
376 | int pn2; |
||
377 | int gLogToFile; |
||
378 | int vmon[4]={P1_VMON_1}; |
||
379 | int imon[4]={P1_IMON_1 }; |
||
380 | int vset[4]={P1_U_1 }; |
||
381 | int iset[4]={P1_I_1 }; |
||
382 | int radiob[4]={P1_BOX_1 }; |
||
383 | |||
384 | int cvcc[4]={P1_CVCC_1 }; |
||
385 | const unsigned char Pre_1 = 1; |
||
386 | int gMask=0xF; |
||
387 | |||
388 | int pnl; |
||
389 | FILE *gFp; |
||
390 | |||
391 | |||
392 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
||
393 | void *callbackData, int eventData1, int eventData2) |
||
394 | { |
||
395 | int state; |
||
396 | switch (event) |
||
397 | { |
||
398 | case EVENT_COMMIT: |
||
399 | GetCtrlVal(panel, control, &state); |
||
400 | if (state){ |
||
401 | ResumeTimerCallbacks(); |
||
402 | } else { |
||
403 | SuspendTimerCallbacks (); |
||
404 | printf ("Disabling timer....\n"); |
||
405 | } |
||
406 | break; |
||
407 | } |
||
408 | return 0; |
||
409 | } |
||
410 | |||
411 | // reads the run number from the first line in the file |
||
412 | int GetRunNumberFromFile(char *fname) { |
||
413 | char line[MAX_PATHNAME_LEN]; |
||
414 | int ndim= MAX_PATHNAME_LEN; |
||
415 | int current_run = -1; |
||
416 | FILE *fp = NULL; |
||
417 | ssize_t size; |
||
418 | |||
419 | if ( GetFileInfo(fname,&size) ) fp = fopen(fname,"r"); |
||
420 | |||
421 | if (fp) { |
||
422 | if (fgets(line,ndim,fp)!= NULL) current_run = atoi(line); |
||
423 | fclose(fp); |
||
424 | } |
||
425 | return current_run; |
||
426 | |||
427 | } |
||
428 | |||
429 | int IncreaseRunNumberInFile(char *fname) { |
||
430 | |||
431 | int current_run = GetRunNumberFromFile(fname); |
||
432 | FILE *fp = fopen(fname,"w"); |
||
433 | |||
434 | if (fp) { |
||
435 | fprintf(fp,"%d", current_run+1 ); |
||
436 | fclose(fp); |
||
437 | } |
||
438 | return current_run+1; |
||
439 | } |
||
440 | |||
441 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
||
442 | LPSTR lpszCmdLine, int nCmdShow) |
||
443 | { |
||
444 | char cres[100]; |
||
445 | double Voltage, Current, tinterval; |
||
446 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
||
447 | SetStdioPort (CVI_STDIO_WINDOW); |
||
448 | if ((pnl = LoadPanel (0, "K6517-ctrl.uir", P1)) < 0) return -1; |
||
449 | if ((pn2 = LoadPanel (0, "K6517-ctrl.uir", P2)) < 0) return -1; |
||
450 | |||
451 | K6517_open (1,4,3,0,13); |
||
452 | |||
453 | |||
454 | SetCtrlVal(pnl, P1_ONOFF, 0); |
||
455 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
||
456 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
||
457 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT,NULL,0,0); |
||
458 | for (unsigned char ch=0;ch<1;ch++){ |
||
459 | int ison,i; |
||
460 | Voltage =K6517_vsource_get(); |
||
461 | Current =K6517_get(cres,&i); |
||
462 | SetCtrlVal(pnl, vset[ch], Voltage); |
||
463 | SetCtrlVal(pnl, iset[ch], Current); |
||
464 | GetCtrlVal(pnl, radiob[ch], &ison); |
||
465 | gMask = ison; |
||
466 | } |
||
467 | |||
468 | DisplayPanel (pnl); |
||
469 | DisplayPanel (pn2); |
||
470 | RunUserInterface (); |
||
471 | DiscardPanel (pn2); |
||
472 | DiscardPanel (pnl); |
||
473 | K6517_close(); |
||
474 | |||
475 | if (gFp) fclose(gFp); |
||
476 | |||
477 | |||
478 | return 0; |
||
479 | } |
||
480 | |||
481 | |||
482 | |||
483 | |||
484 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
||
485 | void *callbackData, int eventData1, int eventData2) |
||
486 | { |
||
487 | unsigned char state; |
||
488 | switch (event) |
||
489 | { |
||
490 | case EVENT_COMMIT: |
||
491 | GetCtrlVal(panel, control, &state); |
||
492 | K6517_vsource_operate (state); |
||
493 | break; |
||
494 | } |
||
495 | return 0; |
||
496 | } |
||
497 | |||
498 | int CVICALLBACK SetCB (int panel, int control, int event, |
||
499 | void *callbackData, int eventData1, int eventData2) |
||
500 | { |
||
501 | |||
502 | char cres[100]; |
||
503 | int i; |
||
504 | switch (event) |
||
505 | { |
||
506 | case EVENT_COMMIT: |
||
507 | |||
508 | for (unsigned char ch = 0; ch<1;ch++){ |
||
509 | //printf("ch %d %x\n", ch, gMask); |
||
510 | if (gMask){ |
||
511 | double Voltage; |
||
512 | double Current; |
||
513 | GetCtrlVal(panel, vset[ch], &Voltage); |
||
514 | GetCtrlVal(panel, iset[ch], &Current); |
||
515 | printf("->ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
516 | |||
517 | K6517_vsource_set (Voltage); |
||
518 | Voltage=K6517_vsource_get(); |
||
519 | |||
520 | // TMI_Current(TMI_DeviceId, ch+1, Pre_1, Current); |
||
521 | Current=K6517_get(cres,&i); |
||
522 | printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
523 | |||
524 | } |
||
525 | } |
||
526 | break; |
||
527 | } |
||
528 | return 0; |
||
529 | } |
||
530 | |||
531 | int CVICALLBACK ReadCB (int panel, int control, int event, |
||
532 | void *callbackData, int eventData1, int eventData2) |
||
533 | { |
||
534 | |||
535 | int iRet; |
||
536 | char ch=0; |
||
537 | double Voltage; |
||
538 | double Current; |
||
539 | char cv_cc; |
||
540 | char cres[100]; |
||
541 | |||
542 | switch (event) |
||
543 | { |
||
544 | case EVENT_COMMIT: |
||
545 | for (ch = 0; ch<1;ch++){ |
||
546 | if (gMask){ |
||
547 | int ison,i; |
||
548 | Voltage =K6517_vsource_get(); |
||
549 | Current =K6517_get(cres,&i); |
||
550 | cv_cc = 1; |
||
551 | printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
552 | SetCtrlVal(panel, vmon[ch], Voltage); |
||
553 | SetCtrlVal(panel, imon[ch], Current); |
||
554 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
||
555 | } |
||
556 | } |
||
557 | break; |
||
558 | } |
||
559 | return 0; |
||
560 | } |
||
561 | |||
562 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
||
563 | void *callbackData, int eventData1, int eventData2) { |
||
564 | double tinterval; |
||
565 | switch (event) { |
||
566 | case EVENT_COMMIT: |
||
567 | GetCtrlVal(panel, control, &tinterval); |
||
568 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
||
569 | break; |
||
570 | } |
||
571 | return 0; |
||
572 | } |
||
573 | |||
574 | |||
575 | |||
576 | int CVICALLBACK ExitCB (int panel, int control, int event, |
||
577 | void *callbackData, int eventData1, int eventData2) |
||
578 | { |
||
579 | switch (event) |
||
580 | { |
||
581 | case EVENT_COMMIT: |
||
582 | K6517_send (":OUTP OFF", 0); |
||
583 | QuitUserInterface(0); |
||
584 | break; |
||
585 | } |
||
586 | return 0; |
||
587 | } |
||
588 | |||
589 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
||
590 | void *callbackData, int eventData1, int eventData2) |
||
591 | { int ison; |
||
592 | switch (event) |
||
593 | { |
||
594 | case EVENT_COMMIT: |
||
595 | GetCtrlVal(panel, control, &ison); |
||
596 | for (int i=0;i<1;i++) if (control == radiob[i]) break; |
||
597 | gMask = ison; |
||
598 | break; |
||
599 | } |
||
600 | return 0; |
||
601 | } |
||
602 | |||
603 | |||
604 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
||
605 | void *callbackData, int eventData1, int eventData2) |
||
606 | { |
||
607 | |||
608 | switch (event) |
||
609 | { |
||
610 | case EVENT_COMMIT: |
||
611 | GetCtrlVal(panel, control, &gLogToFile); |
||
612 | |||
613 | break; |
||
614 | } |
||
615 | return 0; |
||
616 | } |
||
617 | |||
618 | int CVICALLBACK TimerCB (int panel, int control, int event, |
||
619 | void *callbackData, int eventData1, int eventData2) |
||
620 | { |
||
621 | switch (event) |
||
622 | { |
||
623 | |||
624 | unsigned char ch; |
||
625 | double current[4]; |
||
626 | double voltage; |
||
627 | char cv_cc = 0; |
||
628 | char cres[100]; |
||
629 | int i=0; |
||
630 | case EVENT_TIMER_TICK: |
||
631 | for (ch = 0; ch<1;ch++){ |
||
632 | if (gMask){ |
||
633 | voltage =K6517_vsource_get(); |
||
634 | current[ch] =K6517_get(cres,&i); |
||
635 | |||
636 | if (gLogToFile){ |
||
637 | if (!gFp) { |
||
638 | gFp= fopen("K6517.log","w"); |
||
639 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
||
640 | } |
||
641 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage, current[ch], cv_cc); |
||
642 | } |
||
643 | } |
||
644 | } |
||
645 | PlotStripChart (panel, P1_GRAPH, current, 1, 0, 0, VAL_DOUBLE); |
||
646 | PlotStripChart (panel, P1_GRAPH_1, &voltage, 1, 0, 0, VAL_DOUBLE); |
||
647 | break; |
||
648 | } |
||
649 | return 0; |
||
650 | } |
||
651 | |||
652 | int CVICALLBACK TestCB (int panel, int control, int event, |
||
653 | void *callbackData, int eventData1, int eventData2) { |
||
654 | switch (event) { |
||
655 | case EVENT_COMMIT: |
||
656 | K6517_test(); |
||
657 | break; |
||
658 | } |
||
659 | return 0; |
||
660 | } |
||
661 | |||
662 | |||
663 | int CVICALLBACK IVSCANCB (int panel, int control, int event, |
||
664 | void *callbackData, int eventData1, int eventData2) { |
||
665 | int nsteps; |
||
666 | double umin, umax, u; |
||
667 | double *xpoints; |
||
668 | double *ypoints; |
||
669 | static int plivhandle=0; |
||
670 | double current; |
||
671 | double voltage; |
||
672 | char cv_cc = 0; |
||
673 | char cres[100]; |
||
674 | char fileName[100]; |
||
675 | char fname[100]; |
||
676 | char path[100]; |
||
677 | double range; |
||
678 | int k=0; |
||
679 | int state; |
||
680 | int overflow; |
||
681 | char ovf[10]; |
||
682 | FILE *fp; |
||
683 | time_t mtime; |
||
684 | ssize_t size; |
||
685 | |||
686 | switch (event) { |
||
687 | case EVENT_COMMIT: |
||
688 | K6517_send (":OUTP ON", 0); |
||
689 | // GetCtrlVal(panel, P2_UMIN, &umin); |
||
690 | // GetCtrlVal(panel, P2_UMAX, &umax); |
||
691 | // GetCtrlVal(panel, P2_NSTEPS, &nsteps); |
||
692 | SetCtrlVal(pnl, P1_TIMERON, 0); |
||
693 | GetCtrlVal(panel, P2_FILENAME, fileName); |
||
694 | GetCtrlVal(panel, P2_PATH, path); |
||
695 | // GetCtrlVal(panel, P2_RANGE, &range); |
||
696 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT, NULL, 0, 0); |
||
697 | sprintf(fname, "%s/%s.dat", path, fileName); |
||
698 | if ( !GetFileInfo(fname,&size) ) |
||
699 | fp = fopen(fname,"w"); |
||
700 | else { |
||
701 | sprintf(cres, "File %s exist\n Remove it first",fname); |
||
702 | MessagePopup ("Info", cres); |
||
703 | return 0; |
||
704 | } |
||
705 | time(&mtime); |
||
706 | printf("#%s %s\n",DateStr(), TimeStr()); |
||
707 | if (fp) fprintf(fp, "#%s %s\n",DateStr(), TimeStr()); |
||
708 | // K6517_current_mode (range); |
||
709 | stop = 0; |
||
710 | LogScaleCB (panel, P2_LOGSCALE, EVENT_COMMIT,NULL, 0, 0); |
||
711 | int voltageMax[4]={P2_UMAX_1,P2_UMAX_2,P2_UMAX_3,P2_UMAX_4}; |
||
712 | int voltageMin[4]={P2_UMIN_1,P2_UMIN_2,P2_UMIN_3,P2_UMIN_4}; |
||
713 | int numberOfSteps[4]={P2_NSTEPS_1,P2_NSTEPS_2,P2_NSTEPS_3,P2_NSTEPS_4}; |
||
714 | int selectRange[4]={P2_RANGE_1,P2_RANGE_2,P2_RANGE_3,P2_RANGE_4}; |
||
715 | int intervals[4]={P2_SLCT_1,P2_SLCT_2,P2_SLCT_3,P2_SLCT_4}; |
||
716 | int nrOfInt; |
||
717 | int nrOfSteps; |
||
718 | int N=0; |
||
719 | int K=0; |
||
720 | for (int j=0;j<4;j++){ |
||
721 | GetCtrlVal(panel, intervals[j], &nrOfInt); |
||
722 | N = N + nrOfInt; |
||
723 | GetCtrlVal(panel, numberOfSteps[j], &nrOfSteps); |
||
724 | K = K + nrOfSteps; |
||
725 | } |
||
726 | xpoints = (double *) malloc ((K-N+2)*sizeof(double)); |
||
727 | ypoints = (double *) malloc ((K-N+2)*sizeof(double)); |
||
728 | int tockaK=0; |
||
729 | for (int i=0;i<N;i++){ |
||
730 | GetCtrlVal(panel, voltageMin[i], &umin); |
||
731 | GetCtrlVal(panel, voltageMax[i], &umax); |
||
732 | GetCtrlVal(panel, numberOfSteps[i], &nsteps); |
||
733 | GetCtrlVal(panel, selectRange[i], &range); |
||
734 | K6517_current_mode (range); |
||
735 | for (int n=0;n<nsteps+1;n++){ |
||
736 | if (i>0) { |
||
737 | if(n==0) n++; |
||
738 | }; |
||
739 | u= umin+ n*(umax-umin)/nsteps; |
||
740 | K6517_vsource_set (u); |
||
741 | // voltage =K6517_vsource_get(); |
||
742 | current =K6517_get(cres,&k); |
||
743 | if (current > range) printf("Overflow +\n"); |
||
744 | if (current < -range) printf("Overflow -\n"); |
||
745 | voltage = u; |
||
746 | xpoints[tockaK]= voltage; |
||
747 | ypoints[tockaK]= current; |
||
748 | SetCtrlVal(panel, P2_VMON, voltage); |
||
749 | if (fp) fprintf(fp, "%d %g %g %g\n",tockaK, u, voltage,current); |
||
750 | printf("n=%d u=%g voltage=%g current=%g\n",tockaK, u, voltage,current); |
||
751 | if (plivhandle) DeleteGraphPlot (panel, P2_GRAPHIV, plivhandle, VAL_IMMEDIATE_DRAW); |
||
752 | plivhandle = PlotXY (panel, P2_GRAPHIV, xpoints, ypoints, tockaK+1, VAL_DOUBLE, VAL_DOUBLE, VAL_CONNECTED_POINTS, VAL_BOLD_X, VAL_SOLID, 1, VAL_RED); |
||
753 | ProcessSystemEvents(); |
||
754 | tockaK++; |
||
755 | if (stop) break; |
||
756 | } |
||
757 | } |
||
758 | fclose(fp); |
||
759 | free(xpoints); |
||
760 | free(ypoints); |
||
761 | break; |
||
762 | } |
||
763 | return 0; |
||
764 | } |
||
765 | |||
766 | int CVICALLBACK SETVOLTCB (int panel, int control, int event, |
||
767 | void *callbackData, int eventData1, int eventData2) { |
||
768 | double voltage; |
||
769 | switch (event) { |
||
770 | case EVENT_COMMIT: |
||
771 | GetCtrlVal(panel, P2_VOLT, &voltage); |
||
772 | K6517_vsource_set (voltage); |
||
773 | break; |
||
774 | } |
||
775 | return 0; |
||
776 | } |
||
777 | |||
778 | |||
779 | int CVICALLBACK StopCB (int panel, int control, int event, |
||
780 | void *callbackData, int eventData1, int eventData2) { |
||
781 | switch (event) { |
||
782 | case EVENT_COMMIT: |
||
783 | stop = 1; |
||
784 | break; |
||
785 | } |
||
786 | return 0; |
||
787 | } |
||
788 | |||
789 | int CVICALLBACK LogScaleCB (int panel, int control, int event, |
||
790 | void *callbackData, int eventData1, int eventData2) { |
||
791 | int selected; |
||
792 | switch (event) { |
||
793 | case EVENT_COMMIT: |
||
794 | GetCtrlVal(panel, control, &selected); |
||
795 | if(selected) SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LOG); |
||
796 | else SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LINEAR); |
||
797 | break; |
||
798 | } |
||
799 | return 0; |
||
800 | } |
||
801 | |||
802 | |||
803 | //**************************** |
||
804 | int EscapeString(const char *i, char *o) { |
||
805 | int iptr=0, optr = 0; |
||
806 | // walk though the input string |
||
807 | for (iptr = 0; iptr < strlen(i); iptr++, optr++) { |
||
808 | // search for |
||
809 | if ( (i[iptr]=='\\') ) { |
||
810 | printf("Escape String %d %d \n",i[iptr] , i[iptr]==92 ) ; |
||
811 | //sa02Printf("Escape String %d %d \n",i[iptr] , ( (i[iptr] == 92) || (i[iptr] == 42) )) ; |
||
812 | o[optr] = i[iptr]; |
||
813 | optr++; |
||
814 | } |
||
815 | o[optr] = i[iptr]; |
||
816 | } |
||
817 | o[optr] = '\0'; |
||
818 | return 0; |
||
819 | } |
||
820 | |||
821 | |||
822 | int CVICALLBACK DrawCB (int panel, int control, int event, |
||
823 | void *callbackData, int eventData1, int eventData2) { |
||
824 | switch (event) { |
||
825 | case EVENT_COMMIT:{ |
||
826 | char fileName[100]; |
||
827 | char fname[100]; |
||
828 | char path[100]; |
||
829 | GetCtrlVal(panel, P2_FILENAME, fileName); |
||
830 | GetCtrlVal(panel, P2_PATH, path); |
||
831 | sprintf(fname, "%s/%s.dat", path, fileName); |
||
832 | int status; |
||
833 | char name[MAX_PATHNAME_LEN]; |
||
834 | // char dfile[MAX_PATHNAME_LEN]; |
||
835 | // char efile[MAX_PATHNAME_LEN]; |
||
836 | // status = FileSelectPopup ("dat", "*.dat", ".dat", |
||
837 | // "Izberi datoteko s podatki", |
||
838 | // VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
||
839 | // EscapeString(efile,dfile); |
||
840 | sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx(\\\"%s\\\")", fname); |
||
841 | // sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx"); |
||
842 | printf("%s\n",name); |
||
843 | LaunchExecutable(name); |
||
844 | break; |
||
845 | } |
||
846 | } |
||
847 | return 0; |
||
848 | } |
||
849 | |||
850 | |||
851 | int CVICALLBACK Print (int panel, int control, int event, |
||
852 | void *callbackData, int eventData1, int eventData2) { |
||
853 | char dfile[MAX_PATHNAME_LEN]; |
||
854 | char name[MAX_PATHNAME_LEN]; |
||
855 | int h2=0; |
||
856 | switch (event) { |
||
857 | case EVENT_COMMIT: { |
||
858 | int hours, minutes, seconds; |
||
859 | int month, day, year; |
||
860 | int id=-1; |
||
861 | //int bitmap = 0; |
||
862 | |||
863 | GetSystemDate (&month,&day ,&year ); |
||
864 | GetSystemTime(&hours, &minutes, &seconds); |
||
865 | sprintf(name,"IV"); |
||
866 | sprintf(dfile ,"%d_%d_%d_%d_%d_%s.bmp",year,month,day,hours,minutes, name ); |
||
867 | SaveCtrlDisplayToFile (panel,P2_GRAPHIV, 0, -1, -1, dfile); |
||
868 | printf("bmp image saved as %s\n", dfile); |
||
869 | |||
870 | //PrintCtrl (p1h, P1_GRAPH2D, "sa02_CVI", 1, 1); |
||
871 | } |
||
872 | break; |
||
873 | } |
||
874 | return 0; |
||
875 | } |
||
876 | |||
877 | int CVICALLBACK DebugCB (int panel, int control, int event, |
||
878 | void *callbackData, int eventData1, int eventData2) { |
||
879 | int selected; |
||
880 | int debugCode; |
||
881 | switch (event) { |
||
882 | case EVENT_COMMIT: |
||
883 | GetCtrlVal(panel, control, &selected); |
||
884 | if(selected) debugCode = 1; |
||
885 | else debugCode = 0; |
||
886 | break; |
||
887 | } |
||
888 | return 0; |
||
889 | } |
||
890 | |||
891 | int CVICALLBACK Exit2CB (int panel, int control, int event, |
||
892 | void *callbackData, int eventData1, int eventData2) { |
||
893 | switch (event) { |
||
894 | case EVENT_COMMIT: |
||
895 | K6517_send (":OUTP OFF", 0); |
||
896 | QuitUserInterface(0); |
||
897 | break; |
||
898 | } |
||
899 | return 0; |
||
900 | } |
||
901 | #endif |