Rev 312 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
308 | f9daq | 1 | #include <userint.h> |
2 | #include "K2231A-ctrl.h" |
||
3 | #include <stdlib.h> |
||
4 | #include <stdio.h> |
||
5 | #include <windows.h> |
||
6 | #include <visa.h> |
||
7 | |||
310 | f9daq | 8 | static int debug = 0; |
308 | f9daq | 9 | static ViStatus istat; |
310 | f9daq | 10 | static ViSession DeviceHandle,RMHandle; |
308 | f9daq | 11 | |
12 | |||
310 | f9daq | 13 | char response[0xFF]= {0}; |
308 | f9daq | 14 | |
312 | f9daq | 15 | int K2231A_SetDebug(int x){ debug = x;return 0;}; |
310 | f9daq | 16 | |
17 | int K2231A_Write(const char *format, ... ) |
||
308 | f9daq | 18 | { |
310 | f9daq | 19 | char cmd[0xFF]; |
20 | va_list aptr; |
||
21 | va_start(aptr, format); |
||
22 | vsprintf(cmd, format, aptr); |
||
23 | va_end(aptr); |
||
24 | |||
25 | char str[0xFF]; |
||
26 | sprintf(str, "%s\r\n",cmd); |
||
27 | int istat = viPrintf (DeviceHandle, str); |
||
28 | if (debug) printf("K2231A_Write %s\n", cmd); |
||
29 | return istat; |
||
30 | } |
||
31 | |||
32 | const char * K2231A_Read(const char *format, ... ) |
||
33 | { |
||
308 | f9daq | 34 | |
310 | f9daq | 35 | char cmd[0xFF]; |
36 | va_list aptr; |
||
37 | va_start(aptr, format); |
||
38 | vsprintf(cmd, format, aptr); |
||
39 | va_end(aptr); |
||
40 | |||
41 | char str[0xFF]; |
||
42 | int istat=0; |
||
43 | |||
44 | sprintf(str, "%s\n",cmd); |
||
45 | istat = viPrintf (DeviceHandle, str); |
||
46 | |||
47 | int nb=0; |
||
48 | istat = viRead (DeviceHandle, response, 0xFF, &nb); |
||
49 | |||
50 | if (nb>0) response[nb-1]=0; |
||
51 | if (debug) printf("K2231A_Read %s : %s\n", cmd, response); |
||
52 | if (istat) return NULL; |
||
53 | |||
54 | return response; |
||
308 | f9daq | 55 | } |
56 | |||
310 | f9daq | 57 | int K2231A_QueryInt(const char *format, ... ) |
58 | { |
||
59 | char cmd[0xFF]; |
||
60 | va_list aptr; |
||
61 | va_start(aptr, format); |
||
62 | vsprintf(cmd, format, aptr); |
||
63 | va_end(aptr); |
||
314 | f9daq | 64 | char *p= K2231A_Read(cmd ); |
65 | if (p!= NULL) return atoi(p); |
||
66 | return 0; |
||
310 | f9daq | 67 | } |
308 | f9daq | 68 | |
310 | f9daq | 69 | |
70 | |||
71 | double K2231A_QueryDouble(const char *format, ...) { |
||
72 | char cmd[0xFF]; |
||
73 | va_list aptr; |
||
74 | va_start(aptr, format); |
||
75 | vsprintf(cmd, format, aptr); |
||
76 | va_end(aptr); |
||
314 | f9daq | 77 | char *p= K2231A_Read(cmd ); |
78 | if (p!= NULL) return atof(p); |
||
79 | return 0; |
||
310 | f9daq | 80 | } |
81 | |||
312 | f9daq | 82 | static int K2231A_Port=5; |
83 | int K2231A_SetPort(int x){K2231A_Port=x; return x;}; |
||
84 | |||
310 | f9daq | 85 | int K2231A_Initialize() |
86 | { |
||
87 | |||
88 | istat = viOpenDefaultRM (&RMHandle); |
||
312 | f9daq | 89 | char cport[0xFF]; |
90 | sprintf(cport,"ASRL%d::INSTR", K2231A_Port ); |
||
91 | if (RMHandle) istat = viOpen (RMHandle, cport , VI_NULL, VI_NULL, &DeviceHandle); |
||
310 | f9daq | 92 | if (DeviceHandle) |
93 | { |
||
94 | |||
95 | istat = viSetAttribute (DeviceHandle, VI_ATTR_TERMCHAR, '\n'); |
||
96 | istat = viSetAttribute (DeviceHandle, VI_ATTR_TERMCHAR_EN, VI_TRUE); |
||
314 | f9daq | 97 | int baud; |
98 | |||
99 | istat = viGetAttribute (DeviceHandle, VI_ATTR_ASRL_BAUD, &baud ); |
||
100 | printf("baudrate1 = %d\n", baud); |
||
101 | |||
102 | istat = viSetAttribute (DeviceHandle, VI_ATTR_TMO_VALUE, 1000); |
||
310 | f9daq | 103 | |
104 | |||
105 | printf("\n"); |
||
106 | } |
||
107 | else |
||
108 | { |
||
109 | MessagePopup("Error","Cannot open handle"); |
||
110 | } |
||
111 | |||
112 | |||
113 | return 0; |
||
114 | } |
||
115 | |||
116 | |||
117 | |||
118 | |||
308 | f9daq | 119 | int K2231A_Test() |
120 | { |
||
310 | f9daq | 121 | char response[0xFF]= {0}; |
122 | int i; |
||
123 | for ( i=0; i<255; i++) response[i]=0; |
||
124 | |||
125 | K2231A_Read("*IDN?"); |
||
126 | K2231A_Read("SYSTem:VERSion?"); |
||
127 | K2231A_Read("VOLT?"); |
||
128 | K2231A_Read("CURR?"); |
||
129 | K2231A_Read("MEAS:VOLT?"); |
||
130 | K2231A_Read("MEAS:CURR?"); |
||
131 | K2231A_Read("FETC:VOLT?"); |
||
132 | K2231A_Read("FETC:CURR?"); |
||
133 | K2231A_Write("SYSTem:BEEPer"); |
||
308 | f9daq | 134 | return TRUE; |
135 | } |
||
136 | |||
137 | int K2231A_Close() |
||
138 | { |
||
310 | f9daq | 139 | K2231A_Write("syst:loc"); |
308 | f9daq | 140 | return 0; |
141 | } |
||
142 | |||
143 | int K2231A_Open() |
||
144 | { |
||
310 | f9daq | 145 | K2231A_Initialize(); |
146 | K2231A_Write("syst:rem"); |
||
308 | f9daq | 147 | return TRUE; |
310 | f9daq | 148 | } |
308 | f9daq | 149 | |
310 | f9daq | 150 | int K2231A_RecallFromMemory(int preset){ |
151 | return K2231A_Write("*rcl %d",preset); |
||
152 | } |
||
308 | f9daq | 153 | |
310 | f9daq | 154 | double K2231A_GetSetCurrent(){ |
155 | return K2231A_QueryDouble("CURR?"); |
||
156 | } |
||
308 | f9daq | 157 | |
310 | f9daq | 158 | double K2231A_GetSetVoltage(){ |
159 | return K2231A_QueryDouble("VOLT?"); |
||
160 | } |
||
308 | f9daq | 161 | |
310 | f9daq | 162 | double K2231A_SetCurrent(double x){ |
312 | f9daq | 163 | return K2231A_Write("CURR %f", x); |
310 | f9daq | 164 | } |
308 | f9daq | 165 | |
310 | f9daq | 166 | double K2231A_SetVoltage(double x){ |
312 | f9daq | 167 | return K2231A_Write("VOLT %f", x); |
310 | f9daq | 168 | } |
308 | f9daq | 169 | |
310 | f9daq | 170 | double K2231A_GetCurrentMonitor(){ |
171 | return K2231A_QueryDouble("MEAS:CURR?"); |
||
172 | } |
||
308 | f9daq | 173 | |
310 | f9daq | 174 | double K2231A_GetVoltageMonitor(){ |
175 | return K2231A_QueryDouble("MEAS:VOLT?"); |
||
176 | } |
||
177 | |||
178 | |||
179 | int K2231A_SelectChannel(int ch){ |
||
180 | return K2231A_Write( "INST CH%d",ch); |
||
181 | } |
||
182 | |||
183 | |||
184 | int K2231A_GetOperationMode(){ |
||
185 | /* |
||
186 | //cv_cc = K2231A_QueryInt("Stat:ques:inst?"); |
||
187 | sprintf(cmd, "Stat:ques:inst:isum%d?",ch+1); |
||
188 | */ |
||
189 | return K2231A_QueryInt("Stat:ques:inst?"); |
||
190 | } |
||
191 | |||
192 | |||
193 | int K2231A_SetSwitch(int state){ |
||
194 | K2231A_Write("Outp:enab %d",state); |
||
195 | K2231A_Write("Outp %d",state); |
||
196 | return 0; |
||
197 | } |
||
198 | int K2231A_GetSwitch(){ |
||
199 | return K2231A_QueryInt("CHAN:OUTP?"); |
||
200 | } |
||
201 | |||
202 | |||
203 | |||
204 | void K2231A_ReadMonitorValues(double * I , double * V, unsigned char * mode, unsigned char *onoff) |
||
205 | { |
||
206 | int iRet; |
||
207 | char ch=0; |
||
208 | double Voltage; |
||
209 | double Current; |
||
210 | char cv_cc; |
||
211 | |||
212 | for (ch=0; ch<3; ch++) |
||
213 | { |
||
214 | |||
215 | |||
216 | K2231A_SelectChannel(ch+1); |
||
217 | cv_cc = K2231A_GetOperationMode(); |
||
218 | I[ch]= K2231A_GetCurrentMonitor(); |
||
219 | V[ch]= K2231A_GetVoltageMonitor(); |
||
220 | int onoff=K2231A_QueryInt("OUTP?"); |
||
221 | if (debug) printf("[%d] %g V %g A CVCC %d ONOFF %d\t",ch, V[ch], I[ch], cv_cc, onoff ); |
||
222 | |||
223 | |||
224 | |||
225 | } |
||
226 | |||
227 | |||
228 | |||
308 | f9daq | 229 | return; |
230 | |||
310 | f9daq | 231 | |
308 | f9daq | 232 | } |
233 | |||
310 | f9daq | 234 | void K2231A_ReadSetValues(double * I , double * V, unsigned char *onoff) |
235 | { |
||
236 | int iRet; |
||
237 | char ch=0; |
||
238 | double Voltage; |
||
239 | double Current; |
||
240 | char cv_cc; |
||
308 | f9daq | 241 | |
310 | f9daq | 242 | for (ch=0; ch<3; ch++) |
243 | { |
||
308 | f9daq | 244 | |
310 | f9daq | 245 | |
246 | K2231A_SelectChannel(ch+1); |
||
247 | cv_cc = K2231A_GetOperationMode(); |
||
248 | I[ch]= K2231A_GetSetCurrent(); |
||
249 | V[ch]= K2231A_GetSetVoltage(); |
||
250 | int onoff=K2231A_GetSwitch(); |
||
251 | if (debug) printf("[%d] %g V %g A CVCC %d ONOFF %d\t",ch, V[ch], I[ch], cv_cc, onoff ); |
||
252 | |||
253 | } |
||
254 | |||
255 | return; |
||
256 | } |
||
257 | |||
258 | |||
259 | #ifdef MAIN |
||
260 | |||
308 | f9daq | 261 | #include <ansi_c.h> |
262 | #include <utility.h> |
||
263 | |||
264 | |||
265 | #define RSTREG(a,x) (a&=(~(x))) |
||
266 | #define SETREG(a,x) (a|=x) |
||
267 | |||
268 | int gLogToFile; |
||
310 | f9daq | 269 | int vmon[3]= {P1_VMON_1,P1_VMON_2,P1_VMON_3 }; |
270 | int imon[3]= {P1_IMON_1,P1_IMON_2,P1_IMON_3 }; |
||
271 | int vset[3]= {P1_U_1,P1_U_2,P1_U_3 }; |
||
272 | int iset[3]= {P1_I_1,P1_I_2,P1_I_3 }; |
||
273 | int radiob[3]= {P1_BOX_1,P1_BOX_2,P1_BOX_3 }; |
||
308 | f9daq | 274 | |
310 | f9daq | 275 | int cvcc[3]= {P1_CVCC_1,P1_CVCC_2,P1_CVCC_3 }; |
276 | |||
308 | f9daq | 277 | int gMask=0xF; |
278 | |||
279 | int pnl; |
||
280 | FILE *gFp; |
||
281 | int main (int argc, char *argv[]) |
||
282 | { |
||
310 | f9daq | 283 | int DeviceId=0; |
284 | unsigned char MainOutput=0, preset=0; |
||
285 | double Voltage=0, Current=0, tinterval=1; |
||
286 | char str[0xFF]; |
||
287 | int i=0; |
||
288 | char response[0xFF]; |
||
308 | f9daq | 289 | if (InitCVIRTE (0, argv, 0) == 0) |
290 | return -1; /* out of memory */ |
||
310 | f9daq | 291 | SetStdioPort (CVI_STDIO_WINDOW); |
292 | SetStdioWindowOptions (1000, 1, 0); |
||
293 | SetStdioWindowSize (150, 600); |
||
294 | SetStdioWindowPosition (825, 20); |
||
308 | f9daq | 295 | |
310 | f9daq | 296 | |
308 | f9daq | 297 | if ((pnl = LoadPanel (0, "K2231A-ctrl.uir", P1)) < 0) return -1; |
298 | |||
310 | f9daq | 299 | if (K2231A_Open()== 0) MessagePopup("Error","Cannot open USB device"); |
300 | |||
301 | if (K2231A_Test() == 0 )MessagePopup("DLL error","Dll Error"); |
||
302 | |||
303 | |||
304 | |||
305 | SetCtrlVal(pnl, P1_ONOFF, MainOutput); |
||
306 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
||
307 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
||
308 | |||
309 | SetCtrlVal(pnl, P1_PRESET, preset); |
||
310 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 1, ATTR_TRACE_LG_TEXT, "CH 30V"); |
||
308 | f9daq | 311 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 2, ATTR_TRACE_LG_TEXT, "CH 30V"); |
312 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 3, ATTR_TRACE_LG_TEXT, "CH 5V"); |
||
310 | f9daq | 313 | |
314 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 1, ATTR_TRACE_LG_TEXT, "CH 30V"); |
||
308 | f9daq | 315 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 2, ATTR_TRACE_LG_TEXT, "CH 30V"); |
316 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 3, ATTR_TRACE_LG_TEXT, "CH 5V"); |
||
310 | f9daq | 317 | int ison; |
318 | for (unsigned char ch=0; ch<3; ch++) |
||
319 | { |
||
320 | |||
321 | K2231A_SelectChannel(ch+1); |
||
322 | |||
323 | Voltage =K2231A_GetSetVoltage(); |
||
324 | Current =K2231A_GetSetCurrent(); |
||
325 | ison =K2231A_GetSwitch(); |
||
326 | |||
327 | |||
328 | |||
329 | SetCtrlVal(pnl, vset[ch], Voltage); |
||
330 | SetCtrlVal(pnl, iset[ch], Current); |
||
331 | SetCtrlVal(pnl, radiob[ch], ison); |
||
332 | if (ison) SETREG(gMask,(1<<ch)); |
||
333 | else RSTREG(gMask,(1<<ch)); |
||
334 | } |
||
335 | |||
336 | DisplayPanel (pnl); |
||
308 | f9daq | 337 | RunUserInterface (); |
338 | DiscardPanel (pnl); |
||
310 | f9daq | 339 | K2231A_Close(); |
308 | f9daq | 340 | |
310 | f9daq | 341 | if (gFp) fclose(gFp); |
308 | f9daq | 342 | return 0; |
343 | } |
||
344 | |||
345 | |||
346 | |||
347 | |||
348 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
||
310 | f9daq | 349 | void *callbackData, int eventData1, int eventData2) |
308 | f9daq | 350 | { |
310 | f9daq | 351 | unsigned char state; |
352 | switch (event) |
||
353 | { |
||
354 | case EVENT_COMMIT: |
||
355 | GetCtrlVal(panel, control, &state); |
||
356 | |||
357 | |||
358 | K2231A_SetSwitch(state); |
||
359 | |||
360 | break; |
||
361 | } |
||
362 | return 0; |
||
308 | f9daq | 363 | } |
364 | |||
365 | int CVICALLBACK SetCB (int panel, int control, int event, |
||
310 | f9daq | 366 | void *callbackData, int eventData1, int eventData2) |
308 | f9daq | 367 | { |
310 | f9daq | 368 | |
369 | |||
370 | switch (event) |
||
371 | { |
||
372 | case EVENT_COMMIT: |
||
373 | { |
||
374 | unsigned char preset=0; |
||
375 | |||
376 | SetCtrlVal(pnl, P1_PRESET, preset); |
||
377 | for (unsigned char ch = 0; ch<3; ch++) |
||
378 | { |
||
379 | //printf("ch %d %x\n", ch, gMask); |
||
380 | if (gMask & (1<<ch)) |
||
381 | { |
||
382 | double Voltage; |
||
383 | double Current; |
||
384 | |||
385 | GetCtrlVal(panel, vset[ch], &Voltage); |
||
386 | GetCtrlVal(panel, iset[ch], &Current); |
||
308 | f9daq | 387 | |
310 | f9daq | 388 | |
389 | char cmd[0xFF]; |
||
390 | |||
391 | K2231A_SelectChannel(ch+1); |
||
392 | |||
393 | Voltage =K2231A_GetVoltageMonitor(); |
||
394 | Current =K2231A_GetCurrentMonitor(); |
||
395 | |||
396 | |||
397 | printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
398 | |||
399 | } |
||
400 | } |
||
308 | f9daq | 401 | } |
310 | f9daq | 402 | break; |
403 | } |
||
404 | return 0; |
||
308 | f9daq | 405 | } |
406 | |||
407 | int CVICALLBACK ReadCB (int panel, int control, int event, |
||
310 | f9daq | 408 | void *callbackData, int eventData1, int eventData2) |
308 | f9daq | 409 | { |
310 | f9daq | 410 | |
411 | int iRet; |
||
412 | char ch=0; |
||
413 | double Voltage=0; |
||
414 | double Current=0; |
||
415 | char cv_cc=0; |
||
416 | switch (event) |
||
417 | { |
||
418 | case EVENT_COMMIT: |
||
419 | |||
420 | for (ch = 0; ch<3; ch++) |
||
421 | { |
||
422 | if (gMask & (1<<ch)) |
||
423 | { |
||
424 | K2231A_SelectChannel(ch+1); |
||
425 | |||
426 | Voltage =K2231A_GetVoltageMonitor(); |
||
427 | Current =K2231A_GetCurrentMonitor(); |
||
428 | |||
429 | cv_cc = K2231A_GetOperationMode(); |
||
430 | |||
431 | printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
432 | SetCtrlVal(panel, vmon[ch], Voltage); |
||
433 | SetCtrlVal(panel, imon[ch], Current); |
||
434 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
||
435 | } |
||
436 | } |
||
437 | break; |
||
438 | } |
||
439 | return 0; |
||
308 | f9daq | 440 | } |
441 | |||
442 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
||
310 | f9daq | 443 | void *callbackData, int eventData1, int eventData2) |
444 | { |
||
445 | double tinterval; |
||
446 | switch (event) |
||
447 | { |
||
448 | case EVENT_COMMIT: |
||
449 | GetCtrlVal(panel, control, &tinterval); |
||
450 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
||
451 | break; |
||
452 | } |
||
453 | return 0; |
||
308 | f9daq | 454 | } |
455 | |||
456 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
||
310 | f9daq | 457 | void *callbackData, int eventData1, int eventData2) |
308 | f9daq | 458 | { |
310 | f9daq | 459 | int state; |
460 | switch (event) |
||
461 | { |
||
462 | case EVENT_COMMIT: |
||
463 | GetCtrlVal(panel, control, &state); |
||
464 | if (state) |
||
465 | { |
||
466 | SetCtrlAttribute (panel, P1_TIMER, ATTR_ENABLED, 1); |
||
467 | ResumeTimerCallbacks(); |
||
468 | } |
||
469 | else |
||
470 | { |
||
471 | SuspendTimerCallbacks (); |
||
472 | printf ("Disabling timer....\n"); |
||
473 | } |
||
474 | break; |
||
475 | } |
||
476 | return 0; |
||
308 | f9daq | 477 | } |
478 | |||
479 | int CVICALLBACK ExitCB (int panel, int control, int event, |
||
310 | f9daq | 480 | void *callbackData, int eventData1, int eventData2) |
308 | f9daq | 481 | { |
310 | f9daq | 482 | switch (event) |
483 | { |
||
484 | case EVENT_COMMIT: |
||
485 | QuitUserInterface(0); |
||
486 | break; |
||
487 | } |
||
488 | return 0; |
||
308 | f9daq | 489 | } |
490 | |||
491 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
||
310 | f9daq | 492 | void *callbackData, int eventData1, int eventData2) |
493 | { |
||
494 | int ison; |
||
495 | switch (event) |
||
496 | { |
||
497 | int i=0; |
||
498 | case EVENT_COMMIT: |
||
499 | GetCtrlVal(panel, control, &ison); |
||
500 | for (i=0; i<3; i++) if (control == radiob[i]) break; |
||
501 | if (ison) SETREG(gMask,(1<<i)); |
||
502 | else RSTREG(gMask,(1<<i)); |
||
503 | break; |
||
504 | } |
||
505 | return 0; |
||
308 | f9daq | 506 | } |
507 | |||
508 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
||
310 | f9daq | 509 | void *callbackData, int eventData1, int eventData2) |
308 | f9daq | 510 | { |
310 | f9daq | 511 | |
512 | switch (event) |
||
513 | { |
||
514 | case EVENT_COMMIT: |
||
515 | GetCtrlVal(panel, control, &gLogToFile); |
||
516 | |||
517 | break; |
||
518 | } |
||
519 | return 0; |
||
308 | f9daq | 520 | } |
521 | |||
522 | int CVICALLBACK TimerCB (int panel, int control, int event, |
||
310 | f9daq | 523 | void *callbackData, int eventData1, int eventData2) |
308 | f9daq | 524 | { |
310 | f9daq | 525 | switch (event) |
526 | { |
||
527 | |||
528 | unsigned char ch; |
||
529 | double current[3]= {0,0,0}; |
||
530 | double voltage[3]= {0,0,0}; |
||
531 | char cv_cc=0; |
||
532 | case EVENT_TIMER_TICK: |
||
533 | for (ch = 0; ch<3; ch++) |
||
534 | { |
||
535 | if (gMask & (1<<ch)) |
||
536 | { |
||
537 | |||
538 | K2231A_SelectChannel(ch+1); |
||
539 | |||
540 | voltage[ch] =K2231A_GetVoltageMonitor(); |
||
541 | current[ch] =K2231A_GetCurrentMonitor(); |
||
542 | cv_cc = K2231A_GetOperationMode(); |
||
543 | int onoff=K2231A_GetSwitch(); |
||
544 | |||
545 | |||
546 | |||
547 | SetCtrlVal(panel, vmon[ch], voltage[ch]); |
||
548 | SetCtrlVal(panel, imon[ch], current[ch]); |
||
549 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
||
550 | SetCtrlVal(panel, P1_ONOFFLED, onoff); |
||
551 | if (gLogToFile) |
||
552 | { |
||
553 | if (!gFp) |
||
554 | { |
||
555 | gFp= fopen("pw18-1.8aq.log","w"); |
||
556 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
||
557 | } |
||
558 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage[ch], current[ch], cv_cc); |
||
559 | } |
||
560 | } |
||
561 | } |
||
562 | PlotStripChart (panel, P1_GRAPH_IMON, current, 3, 0, 0, VAL_DOUBLE); |
||
563 | PlotStripChart (panel, P1_GRAPH_VMON, voltage, 3, 0, 0, VAL_DOUBLE); |
||
564 | break; |
||
565 | } |
||
566 | return 0; |
||
308 | f9daq | 567 | } |
568 | |||
569 | int CVICALLBACK SetPresetCB (int panel, int control, int event, |
||
310 | f9daq | 570 | void *callbackData, int eventData1, int eventData2) |
571 | { |
||
572 | char cmd[0xFF]; |
||
573 | switch (event) |
||
574 | { |
||
575 | case EVENT_COMMIT: |
||
576 | { |
||
308 | f9daq | 577 | unsigned char preset; |
578 | double Voltage, Current; |
||
310 | f9daq | 579 | GetCtrlVal(panel, control, &preset); |
308 | f9daq | 580 | |
310 | f9daq | 581 | K2231A_RecallFromMemory(preset); |
582 | for (unsigned char ch=0; ch<3; ch++) |
||
583 | { |
||
584 | int ison; |
||
585 | K2231A_SelectChannel(ch+1); |
||
586 | Voltage =K2231A_GetSetVoltage(); |
||
587 | Current =K2231A_GetSetCurrent(); |
||
588 | ison =K2231A_GetSwitch(); |
||
589 | |||
590 | SetCtrlVal(pnl, vset[ch], Voltage); |
||
591 | SetCtrlVal(pnl, iset[ch], Current); |
||
592 | GetCtrlVal(pnl, radiob[ch], &ison); |
||
593 | if (ison) SETREG(gMask,(1<<ch)); |
||
594 | else RSTREG(gMask,(1<<ch)); |
||
595 | } |
||
308 | f9daq | 596 | break; |
597 | } |
||
598 | } |
||
599 | return 0; |
||
600 | } |
||
601 | |||
310 | f9daq | 602 | int CVICALLBACK DebugCB (int panel, int control, int event, |
603 | void *callbackData, int eventData1, int eventData2) |
||
604 | { |
||
605 | switch (event) |
||
606 | { |
||
607 | case EVENT_COMMIT: |
||
608 | GetCtrlVal(panel, control, &debug); |
||
609 | break; |
||
610 | } |
||
611 | return 0; |
||
612 | } |
||
308 | f9daq | 613 | |
614 | |||
310 | f9daq | 615 | #endif MAIN |
616 |