Rev 281 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
304 | f9daq | 1 | #include <tcpsupp.h> |
281 | f9daq | 2 | #include <formatio.h> |
3 | #include <userint.h> |
||
4 | #include <ansi_c.h> |
||
5 | #include <utility.h> |
||
6 | #include <gpib.h> |
||
7 | #include "toolbox.h" |
||
8 | #include "prologix.h" |
||
9 | #include "K6517.h" |
||
10 | |||
11 | K6517STATUS K6517Stat; |
||
12 | static int K6517_Interface,K6517_Port,K6517_Gdev; |
||
13 | static int iret; |
||
14 | static int stop; |
||
304 | f9daq | 15 | static int debugCode; |
281 | f9daq | 16 | int _VI_FUNC K6517_status_print (void); |
17 | void GpibError(char *msg) { |
||
18 | |||
19 | printf ("%s\n", msg); |
||
20 | |||
21 | printf ("ibsta = &H%x <", ibsta); |
||
22 | if (ibsta & ERR ) printf (" ERR"); |
||
23 | if (ibsta & TIMO) printf (" TIMO"); |
||
24 | if (ibsta & END ) printf (" END"); |
||
25 | if (ibsta & SRQI) printf (" SRQI"); |
||
26 | if (ibsta & RQS ) printf (" RQS"); |
||
27 | if (ibsta & CMPL) printf (" CMPL"); |
||
28 | if (ibsta & LOK ) printf (" LOK"); |
||
29 | if (ibsta & REM ) printf (" REM"); |
||
30 | if (ibsta & CIC ) printf (" CIC"); |
||
31 | if (ibsta & ATN ) printf (" ATN"); |
||
32 | if (ibsta & TACS) printf (" TACS"); |
||
33 | if (ibsta & LACS) printf (" LACS"); |
||
34 | if (ibsta & DTAS) printf (" DTAS"); |
||
35 | if (ibsta & DCAS) printf (" DCAS"); |
||
36 | printf (" >\n"); |
||
37 | |||
38 | printf ("iberr = %d", iberr); |
||
39 | if (iberr == EDVR) printf (" EDVR <DOS Error>\n"); |
||
40 | if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n"); |
||
41 | if (iberr == ENOL) printf (" ENOL <No Listener>\n"); |
||
42 | if (iberr == EADR) printf (" EADR <Address error>\n"); |
||
43 | if (iberr == EARG) printf (" EARG <Invalid argument>\n"); |
||
44 | if (iberr == ESAC) printf (" ESAC <Not System Controller>\n"); |
||
45 | if (iberr == EABO) printf (" EABO <Operation aborted>\n"); |
||
46 | if (iberr == ENEB) printf (" ENEB <No GPIB board>\n"); |
||
47 | if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n"); |
||
48 | if (iberr == ECAP) printf (" ECAP <No capability>\n"); |
||
49 | if (iberr == EFSO) printf (" EFSO <File system error>\n"); |
||
50 | if (iberr == EBUS) printf (" EBUS <Command error>\n"); |
||
51 | if (iberr == ESTB) printf (" ESTB <Status byte lost>\n"); |
||
52 | if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n"); |
||
53 | if (iberr == ETAB) printf (" ETAB <Table Overflow>\n"); |
||
54 | |||
55 | printf ("ibcntl = %ld\n", ibcntl); |
||
56 | printf ("\n"); |
||
57 | |||
58 | /* Call ibonl to take the device and interface offline */ |
||
59 | ibonl (K6517_Gdev,0); |
||
60 | |||
61 | exit(1); |
||
62 | } |
||
63 | |||
64 | void _VI_FUNC K6517_open (int interface, int port, int primary_addr, |
||
65 | int secondary_addr, int timeout) |
||
66 | { |
||
67 | char cmd[100]; |
||
68 | int status; |
||
69 | /* |
||
70 | K6517_Gdev = OpenDev ("GPIB0", ""); |
||
71 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
72 | iret = ibpad (K6517_Gdev, 0); |
||
73 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
74 | iret = ibsad (K6517_Gdev, NO_SAD); |
||
75 | iret = ibtmo (K6517_Gdev, T10s); |
||
76 | iret = ibeot (K6517_Gdev, 1); |
||
77 | iret = ibeos (K6517_Gdev, 0); |
||
78 | */ |
||
79 | K6517_Interface=interface; |
||
80 | K6517_Port=port; |
||
81 | switch (K6517_Interface){ |
||
82 | case 1: |
||
83 | status = PROLOGIX_Open (K6517_Port); |
||
84 | printf("K6517_open %d\n", status); |
||
85 | sprintf(cmd,"++addr %0d",primary_addr); |
||
86 | PROLOGIX_Send (cmd); |
||
87 | PROLOGIX_Send ("++auto 0"); |
||
88 | PROLOGIX_Send ("++eoi 1"); |
||
89 | PROLOGIX_Send ("++eot_enable 0"); |
||
90 | PROLOGIX_Send ("++read_tmo_ms 1000"); |
||
91 | break; |
||
92 | default: |
||
93 | K6517_Gdev = ibdev(K6517_Port,primary_addr,secondary_addr,timeout,1,0); |
||
94 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
95 | } |
||
96 | printf("Interface %d\n", interface); |
||
97 | K6517_send("*RST",0); |
||
98 | K6517_send("*IDN?", 5); |
||
99 | char cres[100]; |
||
100 | cres[0]= 0; |
||
101 | int len = K6517_receive (cres, 50); |
||
102 | printf("[%d] %s\n", len, cres); |
||
103 | |||
104 | Delay(GDELAY); |
||
105 | return; |
||
106 | } |
||
107 | |||
108 | void _VI_FUNC K6517_clear (void) |
||
109 | { |
||
110 | switch (K6517_Interface){ |
||
111 | case 1: |
||
112 | PROLOGIX_Send("++clr"); |
||
113 | break; |
||
114 | default: |
||
115 | iret = ibclr (K6517_Gdev); // Clear the device |
||
116 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
117 | } |
||
118 | // Delay(GDELAY); |
||
119 | Delay(2.); |
||
120 | return; |
||
121 | } |
||
122 | |||
123 | void _VI_FUNC K6517_send (char *cmd, int len) |
||
124 | { |
||
304 | f9daq | 125 | if (debugCode) printf("-> %s\n", cmd); |
281 | f9daq | 126 | if (!len) len = strlen(cmd); |
127 | switch (K6517_Interface){ |
||
128 | case 1: |
||
129 | PROLOGIX_Send(cmd); |
||
130 | break; |
||
131 | default: |
||
132 | iret = ibwrt (K6517_Gdev, cmd, len); |
||
133 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
134 | } |
||
135 | Delay(GDELAY); |
||
136 | return; |
||
137 | } |
||
138 | |||
139 | int _VI_FUNC K6517_receive (char *response, int maxbyt) |
||
140 | { |
||
141 | int ierr=0; |
||
142 | switch (K6517_Interface){ |
||
143 | case 1: |
||
144 | PROLOGIX_Send("++read eoi"); |
||
145 | ierr= PROLOGIX_Receive (response,maxbyt); |
||
304 | f9daq | 146 | if (debugCode) printf("<---Read [%d] %s\n", ierr, response); |
281 | f9daq | 147 | return ierr; |
148 | break; |
||
149 | default: |
||
150 | iret = ibrd (K6517_Gdev, response, maxbyt); |
||
151 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
152 | response[ibcntl]=0; |
||
153 | return ibcntl; |
||
154 | } |
||
155 | } |
||
156 | |||
157 | void _VI_FUNC K6517_status (void) |
||
158 | { |
||
159 | int len; |
||
160 | char cres[100]; |
||
161 | |||
162 | K6517_send ("U0X", 3); |
||
163 | len = K6517_receive (cres, 90); |
||
164 | sscanf(cres," 617%1d%2d%1d%1d%1d%1d%1d%1d%1d%1d%1d%2d%1d%2c", |
||
165 | &K6517Stat.function,&K6517Stat.range,&K6517Stat.zero_check, |
||
166 | &K6517Stat.zero_correct,&K6517Stat.suppress,&K6517Stat.trigger, |
||
167 | &K6517Stat.vsource_operate,&K6517Stat.read_mode, |
||
168 | &K6517Stat.data_prefix,&K6517Stat.display, |
||
169 | &K6517Stat.data_store,&K6517Stat.srq,&K6517Stat.eoi,K6517Stat.terminator); |
||
170 | printf("617FRRCZNTOBGDQMMKYY\n"); |
||
171 | printf("%s\n",cres); |
||
172 | // K6517_send ("X", 1); |
||
173 | return; |
||
174 | } |
||
175 | |||
176 | void _VI_FUNC K6517_data_format (int mode) |
||
177 | { |
||
178 | int len; |
||
179 | char cmd[100]; |
||
180 | |||
181 | len=sprintf(cmd,"G%0dX",mode); |
||
182 | K6517_send (cmd, len); |
||
183 | return; |
||
184 | } |
||
185 | |||
186 | double _VI_FUNC K6517_get (char *prefix, int *loc) |
||
187 | { |
||
188 | |||
189 | double value; |
||
190 | char cres[100]; |
||
191 | |||
192 | K6517_send ("SENS:FUNC 'curr'",0); |
||
193 | // K6517_send (":SENS:CURR:RANG:UPP 21e-3",0); |
||
194 | // K6517_send ("SYST:ZCH 0",0); |
||
195 | K6517_send ("READ?",0); |
||
196 | |||
197 | cres[0]= 0; |
||
198 | int len = K6517_receive (cres, 50); |
||
304 | f9daq | 199 | if (debugCode) printf("current >%d, %s\n",len,cres); |
281 | f9daq | 200 | |
201 | return atof(cres); |
||
202 | /* |
||
203 | K6517_send ("X", 1); |
||
204 | len = K6517_receive (cres, 50); |
||
205 | if (loc) { |
||
206 | *loc=-1; |
||
207 | sscanf(cres,"%4c%lg,%d",prefix, &value, loc); |
||
208 | prefix[4]=0; |
||
209 | } else { |
||
210 | sscanf(cres,"%*4c%lg,%*d",&value); |
||
211 | } |
||
212 | |||
213 | return value; |
||
214 | */ |
||
215 | |||
216 | } |
||
217 | |||
218 | void _VI_FUNC K6517_current_mode (double range) |
||
219 | { |
||
220 | int len; |
||
221 | char cmd[100]; |
||
222 | |||
223 | if (range > 0) { |
||
224 | len=sprintf(cmd,":SENS:CURR:RANG:AUTO OFF"); |
||
225 | len=sprintf(cmd,":SENS:CURR:RANG:UPP %g",range); |
||
226 | } |
||
227 | else len=sprintf(cmd,":SENS:CURR:RANG:AUTO ON"); |
||
228 | // printf("%d, %s\n",len,cmd); |
||
229 | K6517_send (cmd, len); |
||
230 | Delay(1); |
||
231 | K6517_send ("SYST:ZCH 0",0); |
||
232 | return; |
||
233 | } |
||
234 | |||
235 | void _VI_FUNC K6517_zero_correct (int zcorrect) |
||
236 | { |
||
237 | K6517_send ("C0X", 3); |
||
238 | K6517_send ("Z0X", 3); |
||
239 | if (zcorrect) { |
||
240 | K6517_send ("C1X", 3); |
||
241 | Delay(2); |
||
242 | K6517_send ("Z1X", 3); |
||
243 | K6517_send ("C0X", 3); |
||
244 | } |
||
245 | return; |
||
246 | } |
||
247 | |||
248 | void _VI_FUNC K6517_trigger_mode (int mode) |
||
249 | { |
||
250 | int len; |
||
251 | char cmd[100]; |
||
252 | |||
253 | //len=sprintf(cmd,"T%0dX",mode); |
||
254 | //K6517_send (cmd, len); |
||
255 | return; |
||
256 | } |
||
257 | |||
258 | void _VI_FUNC K6517_reading_mode (int mode) |
||
259 | { |
||
260 | int len; |
||
261 | char cmd[100]; |
||
262 | |||
263 | //len=sprintf(cmd,"B%0dX",mode); |
||
264 | //K6517_send (cmd, len); |
||
265 | return; |
||
266 | } |
||
267 | |||
268 | void _VI_FUNC K6517_vsource_set (float value) |
||
269 | { |
||
270 | int len; |
||
271 | char cmd[100]; |
||
272 | len=sprintf(cmd,":SOURCE:VOLTAGE %f",value); |
||
273 | K6517_send (cmd, len); |
||
304 | f9daq | 274 | len=sprintf(cmd,":SOURCE:VOLTAGE:MCONNECT ON"); |
275 | K6517_send (cmd, len); |
||
281 | f9daq | 276 | return; |
277 | } |
||
278 | |||
279 | double _VI_FUNC K6517_vsource_get (void) |
||
280 | { |
||
281 | double value; |
||
282 | |||
283 | /* |
||
284 | K6517_send ("SENS:FUNC 'volt'",0); |
||
285 | K6517_send ("SENS:VOLT:RANG:AUTO ON",0); |
||
286 | K6517_send ("SYST:ZCH 0",0); |
||
287 | K6517_send ("READ?",0); |
||
288 | */ |
||
289 | K6517_send (":MEASure:VOLTage?",0); |
||
290 | char cres[100]; |
||
291 | cres[0]= 0; |
||
292 | int len = K6517_receive (cres, 50); |
||
293 | |||
294 | |||
295 | return atof(cres); |
||
296 | } |
||
297 | |||
298 | void _VI_FUNC K6517_vsource_operate (int operate) |
||
299 | { |
||
300 | |||
301 | if (operate){ |
||
302 | // K6517_send (":SOURCE:VOLTAGE:MCONNECT 1", 0); |
||
303 | // K6517_send (":SENS:VOLTAGE:MANual:VSOurce:OPERate 1", 0); |
||
304 | //K6517_send (":MCONNECT 1", 0); |
||
305 | K6517_send (":OUTP ON", 0); |
||
306 | |||
307 | // K6517_send (":SOURCE:VOLTAGE:RANGE 99", 0); |
||
308 | // K6517_send (":SOURCE:VOLTAGE 22", 0); |
||
309 | } else { |
||
310 | //K6517_send (":SOURCE:VOLTAGE 0", 0); |
||
311 | // K6517_send (":SENSe:VOLTAGE:MANual:VSOurce:OPERate 0", 0); |
||
312 | // K6517_send (":SOURCE:VOLTAGE:MCONNECT 0", 0); |
||
313 | K6517_send (":OUTP OFF", 0); |
||
314 | //K6517_send (":MCONNECT 0", 0); |
||
315 | |||
316 | } |
||
317 | K6517_send (":STATUS:OPER?",0); |
||
318 | char cres[100]; |
||
319 | cres[0]= 0; |
||
320 | int len = K6517_receive (cres, 50); |
||
321 | |||
322 | |||
323 | // return atoi(cres); |
||
324 | } |
||
325 | |||
326 | void _VI_FUNC K6517_close (void) |
||
327 | { |
||
328 | // iret = CloseDev (K6517_Gdev); |
||
329 | switch (K6517_Interface){ |
||
330 | case 1: |
||
331 | PROLOGIX_Close(); |
||
332 | break; |
||
333 | default: |
||
334 | iret = ibonl(K6517_Gdev, 0);// Take the device offline |
||
335 | if (ibsta & ERR) GpibError("OpenDev Error"); |
||
336 | } |
||
337 | return; |
||
338 | } |
||
339 | |||
340 | void _VI_FUNC K6517_test (void) |
||
341 | { |
||
342 | int i; |
||
343 | double value; |
||
344 | char cres[100]; |
||
345 | |||
346 | K6517_clear (); |
||
347 | K6517_current_mode (0); |
||
348 | K6517_zero_correct (1); |
||
349 | K6517_data_format (0); |
||
350 | K6517_trigger_mode (1); |
||
351 | K6517_vsource_set (-100.); |
||
352 | K6517_vsource_operate (1); |
||
353 | |||
354 | K6517_status(); |
||
355 | |||
356 | value=K6517_get(cres,&i); |
||
357 | printf("%s, %lg, %d\n",cres,value,i); |
||
358 | value=K6517_vsource_get(); |
||
359 | printf("%lg\n",value); |
||
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 | value=K6517_get(cres,&i); |
||
365 | printf("%s, %lg, %d\n",cres,value,i); |
||
366 | value=K6517_get(cres,&i); |
||
367 | printf("%s, %lg, %d\n",cres,value,i); |
||
368 | Delay(5); |
||
369 | K6517_vsource_operate (0); |
||
370 | |||
371 | |||
372 | } |
||
373 | |||
374 | #ifdef K6517_MAIN |
||
375 | |||
376 | #include <cvirte.h> |
||
377 | #include <userint.h> |
||
378 | #include "K6517-ctrl.h" |
||
379 | int pnl; int gLogToFile; |
||
380 | int pn2; |
||
381 | int gLogToFile; |
||
382 | int vmon[4]={P1_VMON_1}; |
||
383 | int imon[4]={P1_IMON_1 }; |
||
384 | int vset[4]={P1_U_1 }; |
||
385 | int iset[4]={P1_I_1 }; |
||
386 | int radiob[4]={P1_BOX_1 }; |
||
387 | |||
388 | int cvcc[4]={P1_CVCC_1 }; |
||
389 | const unsigned char Pre_1 = 1; |
||
390 | int gMask=0xF; |
||
391 | |||
392 | int pnl; |
||
393 | FILE *gFp; |
||
394 | |||
304 | f9daq | 395 | static int tfID; |
396 | static int rID; |
||
397 | static CmtThreadPoolHandle poolHandle = 0; |
||
398 | #define MAX_THREADS 10 |
||
281 | f9daq | 399 | |
304 | f9daq | 400 | |
401 | |||
402 | /*---------------------------------------------------------------------------*/ |
||
403 | /* Macros */ |
||
404 | /*---------------------------------------------------------------------------*/ |
||
405 | #define tcpChk(f) if ((g_TCPError=(f)) < 0) {ReportTCPError();} |
||
406 | |||
407 | |||
408 | /*---------------------------------------------------------------------------*/ |
||
409 | /* Internal function prototypes */ |
||
410 | /*---------------------------------------------------------------------------*/ |
||
411 | int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, |
||
412 | void *callbackData); |
||
413 | static void ReportTCPError (void); |
||
414 | |||
415 | /*---------------------------------------------------------------------------*/ |
||
416 | /* Module-globals */ |
||
417 | /*---------------------------------------------------------------------------*/ |
||
418 | static unsigned int g_hconversation; |
||
419 | static int g_hmainPanel; |
||
420 | static int g_connected = 0; |
||
421 | static int g_TCPError = 0; |
||
422 | |||
423 | /*---------------------------------------------------------------------------*/ |
||
424 | /* Report TCP Errors if any */ |
||
425 | /*---------------------------------------------------------------------------*/ |
||
426 | static void ReportTCPError(void) |
||
427 | { |
||
428 | if (g_TCPError < 0) |
||
429 | { |
||
430 | char messageBuffer[1024]; |
||
431 | sprintf(messageBuffer, |
||
432 | "TCP library error message: %s\nSystem error message: %s", |
||
433 | GetTCPErrorString (g_TCPError), GetTCPSystemErrorString()); |
||
434 | MessagePopup ("Error", messageBuffer); |
||
435 | g_TCPError = 0; |
||
436 | } |
||
437 | } |
||
438 | /*---------------------------------------------------------------------------*/ |
||
439 | |||
440 | |||
441 | int CVICALLBACK DisconnectCB (int panel, int control, int event, |
||
442 | void *callbackData, int eventData1, int eventData2) { |
||
443 | switch (event) { |
||
444 | case EVENT_COMMIT: |
||
445 | if (g_connected) |
||
446 | DisconnectFromTCPServer (g_hconversation); |
||
447 | g_hconversation = 0; |
||
448 | g_connected = 0; |
||
449 | break; |
||
450 | } |
||
451 | return 0; |
||
452 | } |
||
453 | |||
454 | int CVICALLBACK ConnectCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { |
||
455 | int portNum=10000; |
||
456 | char tempBuf[512]; |
||
457 | sprintf(tempBuf,"localhost"); |
||
458 | switch (event) { |
||
459 | case EVENT_COMMIT: |
||
460 | if (ConnectToTCPServer (&g_hconversation, portNum, tempBuf, ClientTCPCB, NULL, 5000) < 0) |
||
461 | MessagePopup("TCP Client", "Connection to server failed !"); |
||
462 | else |
||
463 | { |
||
464 | SetWaitCursor (0); |
||
465 | g_connected = 1; |
||
466 | |||
467 | /* We are successfully connected -- gather info */ |
||
468 | |||
469 | if (GetTCPHostAddr (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
||
470 | if (GetTCPHostName (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
||
471 | |||
472 | tcpChk (GetTCPPeerAddr (g_hconversation, tempBuf, 256)); |
||
473 | printf("%s\n" ,tempBuf); |
||
474 | tcpChk (GetTCPPeerName (g_hconversation, tempBuf, 256)); |
||
475 | printf("%s\n" ,tempBuf); |
||
476 | } |
||
477 | break; |
||
478 | } |
||
479 | return 0; |
||
480 | } |
||
481 | |||
482 | |||
483 | int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, void *callbackData) |
||
484 | { |
||
485 | char receiveBuf[256] = {0}; |
||
486 | ssize_t dataSize = sizeof (receiveBuf) - 1; |
||
487 | |||
488 | switch (event) |
||
489 | { |
||
490 | case TCP_DATAREADY: |
||
491 | if ((dataSize = ClientTCPRead (g_hconversation, receiveBuf, |
||
492 | dataSize, 1000)) |
||
493 | < 0) |
||
494 | { |
||
495 | printf( "Receive Error\n"); |
||
496 | } |
||
497 | else |
||
498 | { |
||
499 | receiveBuf[dataSize] = '\0'; |
||
500 | //printf("%s", receiveBuf); |
||
501 | float temp = 0; |
||
502 | float humidity = 0; |
||
503 | float dt=0; |
||
504 | float tdiff=0; |
||
505 | int t0 = 0; |
||
506 | sscanf(receiveBuf, "%d%f%f%f%f", &t0,&humidity,&temp, &tdiff, &dt); |
||
507 | SetCtrlVal(pn2,P2_TMON, temp); |
||
508 | SetCtrlVal(pn2,P2_HUMIDITY, humidity); |
||
509 | if (fabs(tdiff)<0.5 && fabs(dt) < 0.2) SetCtrlVal(pn2,P2_LED, 1); |
||
510 | else SetCtrlVal(pn2,P2_LED, 0); |
||
511 | } |
||
512 | break; |
||
513 | case TCP_DISCONNECT: |
||
514 | MessagePopup ("TCP Client", "Server has closed connection!"); |
||
515 | |||
516 | g_connected = 0; |
||
517 | |||
518 | break; |
||
519 | } |
||
520 | return 0; |
||
521 | } |
||
522 | |||
523 | |||
524 | void SetDimming(int state) { |
||
525 | SetCtrlAttribute (pnl, P2_IVSCAN, ATTR_DIMMED, state); |
||
526 | SetCtrlAttribute (pnl, P2_EXIT, ATTR_DIMMED, state); |
||
527 | SetCtrlAttribute (pnl, P2_STOP, ATTR_DIMMED, !state); |
||
528 | } |
||
529 | |||
530 | void CVICALLBACK EndOfThread ( CmtThreadPoolHandle poolhandle, |
||
531 | CmtThreadFunctionID functionID, unsigned int event, |
||
532 | int value, void *callbackData ) { |
||
533 | SetDimming(0); |
||
534 | printf("End of Thread \n"); |
||
535 | return ; |
||
536 | |||
537 | } |
||
538 | |||
539 | int ivscan (void *arg); |
||
540 | |||
541 | int TScan () { |
||
542 | |||
543 | double temp; |
||
544 | int n=0; |
||
545 | int led; |
||
546 | GetNumTableRows (pn2, P2_TABLE, &n ); |
||
547 | for(int i=0; i<n; i++) { |
||
548 | GetTableCellVal (pn2, P2_TABLE, MakePoint (1,i+1), &temp); |
||
549 | if (temp>100) break; |
||
550 | char transmitBuf[512]= {0}; |
||
551 | sprintf(transmitBuf, "1 %f\n", temp); |
||
552 | SetCtrlVal(pn2,P2_LED, 0); |
||
553 | if (g_hconversation) |
||
554 | if ( ClientTCPWrite (g_hconversation, transmitBuf, strlen (transmitBuf), 1000) < 0) printf("Transmit Error\n"); |
||
555 | |||
556 | do { |
||
557 | time_t t0 = time(NULL); |
||
558 | SetCtrlVal(pn2,P2_TIME, ctime(&t0)); |
||
559 | Delay(1); |
||
560 | GetCtrlVal(pn2,P2_LED, &led); |
||
561 | if (stop) break; |
||
562 | } while (!led); |
||
563 | if (stop) break; |
||
564 | |||
565 | int itemp = (int) temp; |
||
566 | ivscan(&itemp); |
||
567 | printf("%d %f\n",i,temp); |
||
568 | } |
||
569 | |||
570 | return 0; |
||
571 | } |
||
572 | |||
573 | |||
574 | int CVICALLBACK TScanCB (int panel, int control, int event, |
||
575 | void *callbackData, int eventData1, int eventData2) { |
||
576 | |||
577 | switch (event) { |
||
578 | case EVENT_COMMIT:{ |
||
579 | ThreadFunctionPtr mythread = TScan; |
||
580 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID, |
||
581 | DEFAULT_THREAD_PRIORITY, |
||
582 | EndOfThread, |
||
583 | EVENT_TP_THREAD_FUNCTION_END, |
||
584 | NULL, RUN_IN_SCHEDULED_THREAD, |
||
585 | &tfID); |
||
586 | } |
||
587 | break; |
||
588 | } |
||
589 | return 0; |
||
590 | } |
||
591 | |||
281 | f9daq | 592 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
593 | void *callbackData, int eventData1, int eventData2) |
||
594 | { |
||
595 | int state; |
||
596 | switch (event) |
||
597 | { |
||
598 | case EVENT_COMMIT: |
||
599 | GetCtrlVal(panel, control, &state); |
||
600 | if (state){ |
||
601 | ResumeTimerCallbacks(); |
||
602 | } else { |
||
603 | SuspendTimerCallbacks (); |
||
604 | printf ("Disabling timer....\n"); |
||
605 | } |
||
606 | break; |
||
607 | } |
||
608 | return 0; |
||
609 | } |
||
610 | |||
611 | // reads the run number from the first line in the file |
||
612 | int GetRunNumberFromFile(char *fname) { |
||
613 | char line[MAX_PATHNAME_LEN]; |
||
614 | int ndim= MAX_PATHNAME_LEN; |
||
615 | int current_run = -1; |
||
616 | FILE *fp = NULL; |
||
617 | ssize_t size; |
||
618 | |||
619 | if ( GetFileInfo(fname,&size) ) fp = fopen(fname,"r"); |
||
620 | |||
621 | if (fp) { |
||
622 | if (fgets(line,ndim,fp)!= NULL) current_run = atoi(line); |
||
623 | fclose(fp); |
||
624 | } |
||
625 | return current_run; |
||
626 | |||
627 | } |
||
628 | |||
629 | int IncreaseRunNumberInFile(char *fname) { |
||
630 | |||
631 | int current_run = GetRunNumberFromFile(fname); |
||
632 | FILE *fp = fopen(fname,"w"); |
||
633 | |||
634 | if (fp) { |
||
635 | fprintf(fp,"%d", current_run+1 ); |
||
636 | fclose(fp); |
||
637 | } |
||
638 | return current_run+1; |
||
639 | } |
||
640 | |||
304 | f9daq | 641 | |
281 | f9daq | 642 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
643 | LPSTR lpszCmdLine, int nCmdShow) |
||
644 | { |
||
645 | char cres[100]; |
||
646 | double Voltage, Current, tinterval; |
||
647 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
||
304 | f9daq | 648 | SetStdioPort (CVI_STDIO_WINDOW); |
649 | SetSleepPolicy(VAL_SLEEP_MORE); |
||
650 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
||
651 | |||
281 | f9daq | 652 | if ((pnl = LoadPanel (0, "K6517-ctrl.uir", P1)) < 0) return -1; |
653 | if ((pn2 = LoadPanel (0, "K6517-ctrl.uir", P2)) < 0) return -1; |
||
304 | f9daq | 654 | DisableBreakOnLibraryErrors(); |
281 | f9daq | 655 | K6517_open (1,4,3,0,13); |
656 | |||
657 | |||
658 | SetCtrlVal(pnl, P1_ONOFF, 0); |
||
659 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
||
660 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
||
661 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT,NULL,0,0); |
||
662 | for (unsigned char ch=0;ch<1;ch++){ |
||
663 | int ison,i; |
||
664 | Voltage =K6517_vsource_get(); |
||
665 | Current =K6517_get(cres,&i); |
||
666 | SetCtrlVal(pnl, vset[ch], Voltage); |
||
667 | SetCtrlVal(pnl, iset[ch], Current); |
||
668 | GetCtrlVal(pnl, radiob[ch], &ison); |
||
669 | gMask = ison; |
||
670 | } |
||
671 | |||
672 | DisplayPanel (pnl); |
||
673 | DisplayPanel (pn2); |
||
674 | RunUserInterface (); |
||
304 | f9daq | 675 | CmtDiscardThreadPool (poolHandle); |
676 | if (g_connected) |
||
677 | DisconnectFromTCPServer (g_hconversation); |
||
281 | f9daq | 678 | DiscardPanel (pn2); |
679 | DiscardPanel (pnl); |
||
680 | K6517_close(); |
||
681 | |||
682 | if (gFp) fclose(gFp); |
||
683 | |||
684 | |||
685 | return 0; |
||
686 | } |
||
687 | |||
688 | |||
689 | |||
690 | |||
691 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
||
692 | void *callbackData, int eventData1, int eventData2) |
||
693 | { |
||
694 | unsigned char state; |
||
695 | switch (event) |
||
696 | { |
||
697 | case EVENT_COMMIT: |
||
698 | GetCtrlVal(panel, control, &state); |
||
699 | K6517_vsource_operate (state); |
||
700 | break; |
||
701 | } |
||
702 | return 0; |
||
703 | } |
||
704 | |||
705 | int CVICALLBACK SetCB (int panel, int control, int event, |
||
706 | void *callbackData, int eventData1, int eventData2) |
||
707 | { |
||
708 | |||
709 | char cres[100]; |
||
710 | int i; |
||
711 | switch (event) |
||
712 | { |
||
713 | case EVENT_COMMIT: |
||
714 | |||
715 | for (unsigned char ch = 0; ch<1;ch++){ |
||
716 | //printf("ch %d %x\n", ch, gMask); |
||
717 | if (gMask){ |
||
718 | double Voltage; |
||
719 | double Current; |
||
720 | GetCtrlVal(panel, vset[ch], &Voltage); |
||
721 | GetCtrlVal(panel, iset[ch], &Current); |
||
722 | printf("->ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
723 | |||
724 | K6517_vsource_set (Voltage); |
||
725 | Voltage=K6517_vsource_get(); |
||
726 | |||
727 | // TMI_Current(TMI_DeviceId, ch+1, Pre_1, Current); |
||
728 | Current=K6517_get(cres,&i); |
||
729 | printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
730 | |||
731 | } |
||
732 | } |
||
733 | break; |
||
734 | } |
||
735 | return 0; |
||
736 | } |
||
737 | |||
738 | int CVICALLBACK ReadCB (int panel, int control, int event, |
||
739 | void *callbackData, int eventData1, int eventData2) |
||
740 | { |
||
741 | |||
742 | int iRet; |
||
743 | char ch=0; |
||
744 | double Voltage; |
||
745 | double Current; |
||
746 | char cv_cc; |
||
747 | char cres[100]; |
||
748 | |||
749 | switch (event) |
||
750 | { |
||
751 | case EVENT_COMMIT: |
||
752 | for (ch = 0; ch<1;ch++){ |
||
753 | if (gMask){ |
||
754 | int ison,i; |
||
755 | Voltage =K6517_vsource_get(); |
||
756 | Current =K6517_get(cres,&i); |
||
757 | cv_cc = 1; |
||
758 | printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
||
759 | SetCtrlVal(panel, vmon[ch], Voltage); |
||
760 | SetCtrlVal(panel, imon[ch], Current); |
||
761 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
||
762 | } |
||
763 | } |
||
764 | break; |
||
765 | } |
||
766 | return 0; |
||
767 | } |
||
768 | |||
769 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
||
770 | void *callbackData, int eventData1, int eventData2) { |
||
771 | double tinterval; |
||
772 | switch (event) { |
||
773 | case EVENT_COMMIT: |
||
774 | GetCtrlVal(panel, control, &tinterval); |
||
775 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
||
776 | break; |
||
777 | } |
||
778 | return 0; |
||
779 | } |
||
780 | |||
781 | |||
782 | |||
783 | int CVICALLBACK ExitCB (int panel, int control, int event, |
||
784 | void *callbackData, int eventData1, int eventData2) |
||
785 | { |
||
786 | switch (event) |
||
787 | { |
||
788 | case EVENT_COMMIT: |
||
789 | K6517_send (":OUTP OFF", 0); |
||
790 | QuitUserInterface(0); |
||
791 | break; |
||
792 | } |
||
793 | return 0; |
||
794 | } |
||
795 | |||
796 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
||
797 | void *callbackData, int eventData1, int eventData2) |
||
798 | { int ison; |
||
799 | switch (event) |
||
800 | { |
||
801 | case EVENT_COMMIT: |
||
802 | GetCtrlVal(panel, control, &ison); |
||
803 | for (int i=0;i<1;i++) if (control == radiob[i]) break; |
||
804 | gMask = ison; |
||
805 | break; |
||
806 | } |
||
807 | return 0; |
||
808 | } |
||
809 | |||
810 | |||
811 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
||
812 | void *callbackData, int eventData1, int eventData2) |
||
813 | { |
||
814 | |||
815 | switch (event) |
||
816 | { |
||
817 | case EVENT_COMMIT: |
||
818 | GetCtrlVal(panel, control, &gLogToFile); |
||
819 | |||
820 | break; |
||
821 | } |
||
822 | return 0; |
||
823 | } |
||
824 | |||
825 | int CVICALLBACK TimerCB (int panel, int control, int event, |
||
826 | void *callbackData, int eventData1, int eventData2) |
||
827 | { |
||
828 | switch (event) |
||
829 | { |
||
830 | |||
831 | unsigned char ch; |
||
832 | double current[4]; |
||
833 | double voltage; |
||
834 | char cv_cc = 0; |
||
835 | char cres[100]; |
||
836 | int i=0; |
||
837 | case EVENT_TIMER_TICK: |
||
838 | for (ch = 0; ch<1;ch++){ |
||
839 | if (gMask){ |
||
840 | voltage =K6517_vsource_get(); |
||
841 | current[ch] =K6517_get(cres,&i); |
||
842 | |||
843 | if (gLogToFile){ |
||
844 | if (!gFp) { |
||
845 | gFp= fopen("K6517.log","w"); |
||
846 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
||
847 | } |
||
848 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage, current[ch], cv_cc); |
||
849 | } |
||
850 | } |
||
851 | } |
||
852 | PlotStripChart (panel, P1_GRAPH, current, 1, 0, 0, VAL_DOUBLE); |
||
853 | PlotStripChart (panel, P1_GRAPH_1, &voltage, 1, 0, 0, VAL_DOUBLE); |
||
854 | break; |
||
855 | } |
||
856 | return 0; |
||
857 | } |
||
858 | |||
859 | int CVICALLBACK TestCB (int panel, int control, int event, |
||
860 | void *callbackData, int eventData1, int eventData2) { |
||
861 | switch (event) { |
||
862 | case EVENT_COMMIT: |
||
863 | K6517_test(); |
||
864 | break; |
||
865 | } |
||
866 | return 0; |
||
867 | } |
||
868 | |||
869 | |||
304 | f9daq | 870 | int ivscan (void *arg) { |
871 | int *iarg = (int *) arg; |
||
281 | f9daq | 872 | int nsteps; |
873 | double umin, umax, u; |
||
874 | double *xpoints; |
||
875 | double *ypoints; |
||
876 | static int plivhandle=0; |
||
877 | double current; |
||
878 | double voltage; |
||
879 | char cv_cc = 0; |
||
880 | char cres[100]; |
||
881 | char fileName[100]; |
||
882 | char fname[100]; |
||
883 | char path[100]; |
||
884 | double range; |
||
885 | int k=0; |
||
886 | int state; |
||
887 | int overflow; |
||
888 | char ovf[10]; |
||
889 | FILE *fp; |
||
890 | time_t mtime; |
||
891 | ssize_t size; |
||
304 | f9daq | 892 | int repeatscan = 1; |
893 | while (repeatscan){ |
||
894 | |||
895 | |||
281 | f9daq | 896 | K6517_send (":OUTP ON", 0); |
304 | f9daq | 897 | |
281 | f9daq | 898 | SetCtrlVal(pnl, P1_TIMERON, 0); |
304 | f9daq | 899 | GetCtrlVal(pn2, P2_FILENAME, fileName); |
900 | GetCtrlVal(pn2, P2_PATH, path); |
||
901 | |||
281 | f9daq | 902 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT, NULL, 0, 0); |
304 | f9daq | 903 | GetCtrlVal(pn2, P2_REPEAT, &repeatscan); |
904 | if (repeatscan) { |
||
905 | int month, day, year, hours,minutes,seconds; |
||
906 | GetSystemDate (&month,&day ,&year ); |
||
907 | GetSystemTime(&hours, &minutes, &seconds); |
||
908 | sprintf(fname ,"%s/%s.%d_%d_%d_%d_%d.dat", path, fileName,year,month,day,hours,minutes ); |
||
909 | fp = fopen(fname,"w"); |
||
910 | } else { |
||
911 | if (*iarg>=100) sprintf(fname, "%s/%s.dat", path, fileName); |
||
912 | else sprintf(fname, "%s/%s_T%d.dat", path, fileName,*iarg); |
||
913 | if ( !GetFileInfo(fname,&size) || strstr("test",fileName)!=NULL ) |
||
281 | f9daq | 914 | fp = fopen(fname,"w"); |
304 | f9daq | 915 | else { |
916 | sprintf(cres, "File %s exist\n Remove it first",fname); |
||
281 | f9daq | 917 | MessagePopup ("Info", cres); |
918 | return 0; |
||
304 | f9daq | 919 | } |
920 | } |
||
281 | f9daq | 921 | time(&mtime); |
922 | printf("#%s %s\n",DateStr(), TimeStr()); |
||
923 | if (fp) fprintf(fp, "#%s %s\n",DateStr(), TimeStr()); |
||
924 | // K6517_current_mode (range); |
||
925 | stop = 0; |
||
304 | f9daq | 926 | LogScaleCB (pn2, P2_LOGSCALE, EVENT_COMMIT,NULL, 0, 0); |
281 | f9daq | 927 | int voltageMax[4]={P2_UMAX_1,P2_UMAX_2,P2_UMAX_3,P2_UMAX_4}; |
928 | int voltageMin[4]={P2_UMIN_1,P2_UMIN_2,P2_UMIN_3,P2_UMIN_4}; |
||
929 | int numberOfSteps[4]={P2_NSTEPS_1,P2_NSTEPS_2,P2_NSTEPS_3,P2_NSTEPS_4}; |
||
930 | int selectRange[4]={P2_RANGE_1,P2_RANGE_2,P2_RANGE_3,P2_RANGE_4}; |
||
931 | int intervals[4]={P2_SLCT_1,P2_SLCT_2,P2_SLCT_3,P2_SLCT_4}; |
||
932 | int nrOfInt; |
||
933 | int nrOfSteps; |
||
934 | int N=0; |
||
935 | int K=0; |
||
936 | for (int j=0;j<4;j++){ |
||
304 | f9daq | 937 | GetCtrlVal(pn2, intervals[j], &nrOfInt); |
281 | f9daq | 938 | N = N + nrOfInt; |
304 | f9daq | 939 | GetCtrlVal(pn2, numberOfSteps[j], &nrOfSteps); |
281 | f9daq | 940 | K = K + nrOfSteps; |
941 | } |
||
304 | f9daq | 942 | xpoints = (double *) malloc ((K-N+2)*sizeof(double)*4); |
943 | ypoints = (double *) malloc ((K-N+2)*sizeof(double)*4); |
||
281 | f9daq | 944 | int tockaK=0; |
304 | f9daq | 945 | double t1,t2; |
946 | GetCtrlVal(pn2, P2_DELAY, &t1); |
||
947 | GetCtrlVal(pn2, P2_DELAY2, &t2); |
||
948 | |||
281 | f9daq | 949 | for (int i=0;i<N;i++){ |
304 | f9daq | 950 | GetCtrlVal(pn2, voltageMin[i], &umin); |
951 | GetCtrlVal(pn2, voltageMax[i], &umax); |
||
952 | GetCtrlVal(pn2, numberOfSteps[i], &nsteps); |
||
953 | GetCtrlVal(pn2, selectRange[i], &range); |
||
281 | f9daq | 954 | K6517_current_mode (range); |
955 | for (int n=0;n<nsteps+1;n++){ |
||
304 | f9daq | 956 | |
281 | f9daq | 957 | if (i>0) { |
958 | if(n==0) n++; |
||
959 | }; |
||
960 | u= umin+ n*(umax-umin)/nsteps; |
||
304 | f9daq | 961 | if (n==0) { |
962 | K6517_vsource_set (u); |
||
963 | Delay(1); |
||
964 | K6517_get(cres,&k); |
||
965 | K6517_vsource_set (u); |
||
966 | Delay(1); |
||
967 | K6517_get(cres,&k); |
||
968 | |||
969 | } |
||
970 | K6517_vsource_set (u); |
||
971 | current =K6517_get(cres,&k); |
||
972 | if (n==0) Delay(t1); |
||
973 | Delay(t2); |
||
281 | f9daq | 974 | // voltage =K6517_vsource_get(); |
975 | current =K6517_get(cres,&k); |
||
304 | f9daq | 976 | // if (current > range) printf("Overflow +\n"); |
977 | // if (current < -range) printf("Overflow -\n"); |
||
281 | f9daq | 978 | voltage = u; |
979 | xpoints[tockaK]= voltage; |
||
980 | ypoints[tockaK]= current; |
||
304 | f9daq | 981 | SetCtrlVal(pn2, P2_VMON, voltage); |
982 | SetCtrlVal(pn2, P2_VCUR, current); |
||
983 | double temperature=0; |
||
984 | double humidity=0; |
||
985 | GetCtrlVal(pn2, P2_TMON, &temperature); |
||
986 | GetCtrlVal(pn2, P2_HUMIDITY, &humidity); |
||
987 | if (fp) fprintf(fp, "%d %g %g %g %g %g\n",tockaK, u, voltage,current, humidity, temperature); |
||
988 | if (debugCode) printf("n=%d u=%g voltage=%g current=%g\n",tockaK, u, voltage,current); |
||
989 | if (plivhandle) DeleteGraphPlot (pn2, P2_GRAPHIV, plivhandle, VAL_IMMEDIATE_DRAW); |
||
990 | plivhandle = PlotXY (pn2, P2_GRAPHIV, xpoints, ypoints, tockaK+1, VAL_DOUBLE, VAL_DOUBLE, VAL_CONNECTED_POINTS, VAL_BOLD_X, VAL_SOLID, 1, VAL_RED); |
||
281 | f9daq | 991 | ProcessSystemEvents(); |
992 | tockaK++; |
||
993 | if (stop) break; |
||
994 | } |
||
304 | f9daq | 995 | if (stop) break; |
281 | f9daq | 996 | } |
304 | f9daq | 997 | u = 0; |
998 | K6517_vsource_set (u); |
||
999 | SetCtrlVal(pn2, P2_VMON, u); |
||
1000 | |||
1001 | SetCtrlVal(pnl, P1_ONOFF, 0); |
||
1002 | K6517_vsource_operate (0); |
||
281 | f9daq | 1003 | fclose(fp); |
1004 | free(xpoints); |
||
1005 | free(ypoints); |
||
304 | f9daq | 1006 | if (stop) break; |
1007 | if (repeatscan){ |
||
1008 | double period; |
||
1009 | GetCtrlVal(pn2,P2_PERIOD,&period); |
||
1010 | while (period>0){ |
||
1011 | Delay(1); |
||
1012 | period--; |
||
1013 | SetCtrlVal(pn2,P2_NEXTSCAN, period); |
||
1014 | if (stop) { |
||
1015 | SetCtrlVal(pn2,P2_NEXTSCAN, 0); |
||
1016 | return 0; |
||
1017 | } |
||
1018 | } |
||
1019 | } |
||
1020 | |||
1021 | } |
||
1022 | return 0; |
||
1023 | } |
||
1024 | |||
1025 | |||
1026 | |||
1027 | |||
1028 | |||
1029 | int CVICALLBACK IVSCANCB (int panel, int control, int event, |
||
1030 | void *callbackData, int eventData1, int eventData2) { |
||
1031 | |||
1032 | rID=100; |
||
1033 | switch (event) { |
||
1034 | case EVENT_COMMIT:{ |
||
1035 | ThreadFunctionPtr mythread = ivscan; |
||
1036 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID, |
||
1037 | DEFAULT_THREAD_PRIORITY, |
||
1038 | EndOfThread, |
||
1039 | EVENT_TP_THREAD_FUNCTION_END, |
||
1040 | NULL, RUN_IN_SCHEDULED_THREAD, |
||
1041 | &tfID); |
||
1042 | } |
||
281 | f9daq | 1043 | break; |
1044 | } |
||
1045 | return 0; |
||
1046 | } |
||
304 | f9daq | 1047 | |
281 | f9daq | 1048 | |
1049 | int CVICALLBACK SETVOLTCB (int panel, int control, int event, |
||
1050 | void *callbackData, int eventData1, int eventData2) { |
||
1051 | double voltage; |
||
1052 | switch (event) { |
||
1053 | case EVENT_COMMIT: |
||
1054 | GetCtrlVal(panel, P2_VOLT, &voltage); |
||
1055 | K6517_vsource_set (voltage); |
||
304 | f9daq | 1056 | SetCtrlVal(panel, P2_VMON, voltage); |
281 | f9daq | 1057 | break; |
1058 | } |
||
1059 | return 0; |
||
1060 | } |
||
1061 | |||
1062 | |||
1063 | int CVICALLBACK StopCB (int panel, int control, int event, |
||
1064 | void *callbackData, int eventData1, int eventData2) { |
||
1065 | switch (event) { |
||
1066 | case EVENT_COMMIT: |
||
1067 | stop = 1; |
||
1068 | break; |
||
1069 | } |
||
1070 | return 0; |
||
1071 | } |
||
1072 | |||
1073 | int CVICALLBACK LogScaleCB (int panel, int control, int event, |
||
1074 | void *callbackData, int eventData1, int eventData2) { |
||
1075 | int selected; |
||
1076 | switch (event) { |
||
1077 | case EVENT_COMMIT: |
||
1078 | GetCtrlVal(panel, control, &selected); |
||
1079 | if(selected) SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LOG); |
||
1080 | else SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LINEAR); |
||
1081 | break; |
||
1082 | } |
||
1083 | return 0; |
||
1084 | } |
||
1085 | |||
1086 | |||
1087 | //**************************** |
||
1088 | int EscapeString(const char *i, char *o) { |
||
1089 | int iptr=0, optr = 0; |
||
1090 | // walk though the input string |
||
1091 | for (iptr = 0; iptr < strlen(i); iptr++, optr++) { |
||
1092 | // search for |
||
1093 | if ( (i[iptr]=='\\') ) { |
||
1094 | printf("Escape String %d %d \n",i[iptr] , i[iptr]==92 ) ; |
||
1095 | //sa02Printf("Escape String %d %d \n",i[iptr] , ( (i[iptr] == 92) || (i[iptr] == 42) )) ; |
||
1096 | o[optr] = i[iptr]; |
||
1097 | optr++; |
||
1098 | } |
||
1099 | o[optr] = i[iptr]; |
||
1100 | } |
||
1101 | o[optr] = '\0'; |
||
1102 | return 0; |
||
1103 | } |
||
1104 | |||
1105 | |||
1106 | int CVICALLBACK DrawCB (int panel, int control, int event, |
||
1107 | void *callbackData, int eventData1, int eventData2) { |
||
1108 | switch (event) { |
||
1109 | case EVENT_COMMIT:{ |
||
1110 | char fileName[100]; |
||
1111 | char fname[100]; |
||
1112 | char path[100]; |
||
1113 | GetCtrlVal(panel, P2_FILENAME, fileName); |
||
1114 | GetCtrlVal(panel, P2_PATH, path); |
||
1115 | sprintf(fname, "%s/%s.dat", path, fileName); |
||
1116 | int status; |
||
1117 | char name[MAX_PATHNAME_LEN]; |
||
1118 | // char dfile[MAX_PATHNAME_LEN]; |
||
1119 | // char efile[MAX_PATHNAME_LEN]; |
||
1120 | // status = FileSelectPopup ("dat", "*.dat", ".dat", |
||
1121 | // "Izberi datoteko s podatki", |
||
1122 | // VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
||
1123 | // EscapeString(efile,dfile); |
||
1124 | sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx(\\\"%s\\\")", fname); |
||
1125 | // sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx"); |
||
1126 | printf("%s\n",name); |
||
1127 | LaunchExecutable(name); |
||
1128 | break; |
||
1129 | } |
||
1130 | } |
||
1131 | return 0; |
||
1132 | } |
||
1133 | |||
1134 | |||
1135 | int CVICALLBACK Print (int panel, int control, int event, |
||
1136 | void *callbackData, int eventData1, int eventData2) { |
||
1137 | char dfile[MAX_PATHNAME_LEN]; |
||
1138 | char name[MAX_PATHNAME_LEN]; |
||
1139 | int h2=0; |
||
1140 | switch (event) { |
||
1141 | case EVENT_COMMIT: { |
||
1142 | int hours, minutes, seconds; |
||
1143 | int month, day, year; |
||
1144 | int id=-1; |
||
1145 | //int bitmap = 0; |
||
1146 | |||
1147 | GetSystemDate (&month,&day ,&year ); |
||
1148 | GetSystemTime(&hours, &minutes, &seconds); |
||
1149 | sprintf(name,"IV"); |
||
1150 | sprintf(dfile ,"%d_%d_%d_%d_%d_%s.bmp",year,month,day,hours,minutes, name ); |
||
1151 | SaveCtrlDisplayToFile (panel,P2_GRAPHIV, 0, -1, -1, dfile); |
||
1152 | printf("bmp image saved as %s\n", dfile); |
||
1153 | |||
1154 | //PrintCtrl (p1h, P1_GRAPH2D, "sa02_CVI", 1, 1); |
||
1155 | } |
||
1156 | break; |
||
1157 | } |
||
1158 | return 0; |
||
1159 | } |
||
1160 | |||
1161 | int CVICALLBACK DebugCB (int panel, int control, int event, |
||
1162 | void *callbackData, int eventData1, int eventData2) { |
||
1163 | int selected; |
||
304 | f9daq | 1164 | |
281 | f9daq | 1165 | switch (event) { |
1166 | case EVENT_COMMIT: |
||
1167 | GetCtrlVal(panel, control, &selected); |
||
1168 | if(selected) debugCode = 1; |
||
1169 | else debugCode = 0; |
||
1170 | break; |
||
1171 | } |
||
1172 | return 0; |
||
1173 | } |
||
1174 | |||
1175 | int CVICALLBACK Exit2CB (int panel, int control, int event, |
||
1176 | void *callbackData, int eventData1, int eventData2) { |
||
1177 | switch (event) { |
||
1178 | case EVENT_COMMIT: |
||
1179 | K6517_send (":OUTP OFF", 0); |
||
1180 | QuitUserInterface(0); |
||
1181 | break; |
||
1182 | } |
||
1183 | return 0; |
||
1184 | } |
||
304 | f9daq | 1185 | |
1186 | |||
1187 | |||
281 | f9daq | 1188 | #endif |