Rev 281 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 281 | Rev 304 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | #include <tcpsupp.h> |
|
1 | #include <formatio.h> |
2 | #include <formatio.h> |
2 | #include <userint.h> |
3 | #include <userint.h> |
3 | #include <ansi_c.h> |
4 | #include <ansi_c.h> |
4 | #include <utility.h> |
5 | #include <utility.h> |
5 | #include <gpib.h> |
6 | #include <gpib.h> |
Line 9... | Line 10... | ||
9 | 10 | ||
10 | K6517STATUS K6517Stat; |
11 | K6517STATUS K6517Stat; |
11 | static int K6517_Interface,K6517_Port,K6517_Gdev; |
12 | static int K6517_Interface,K6517_Port,K6517_Gdev; |
12 | static int iret; |
13 | static int iret; |
13 | static int stop; |
14 | static int stop; |
- | 15 | static int debugCode; |
|
14 | int _VI_FUNC K6517_status_print (void); |
16 | int _VI_FUNC K6517_status_print (void); |
15 | void GpibError(char *msg) { |
17 | void GpibError(char *msg) { |
16 | 18 | ||
17 | printf ("%s\n", msg); |
19 | printf ("%s\n", msg); |
18 | 20 | ||
Line 118... | Line 120... | ||
118 | return; |
120 | return; |
119 | } |
121 | } |
120 | 122 | ||
121 | void _VI_FUNC K6517_send (char *cmd, int len) |
123 | void _VI_FUNC K6517_send (char *cmd, int len) |
122 | { |
124 | { |
123 | printf("-> %s\n", cmd); |
125 | if (debugCode) printf("-> %s\n", cmd); |
124 | if (!len) len = strlen(cmd); |
126 | if (!len) len = strlen(cmd); |
125 | switch (K6517_Interface){ |
127 | switch (K6517_Interface){ |
126 | case 1: |
128 | case 1: |
127 | PROLOGIX_Send(cmd); |
129 | PROLOGIX_Send(cmd); |
128 | break; |
130 | break; |
Line 139... | Line 141... | ||
139 | int ierr=0; |
141 | int ierr=0; |
140 | switch (K6517_Interface){ |
142 | switch (K6517_Interface){ |
141 | case 1: |
143 | case 1: |
142 | PROLOGIX_Send("++read eoi"); |
144 | PROLOGIX_Send("++read eoi"); |
143 | ierr= PROLOGIX_Receive (response,maxbyt); |
145 | ierr= PROLOGIX_Receive (response,maxbyt); |
144 | printf("<---Read [%d] %s\n", ierr, response); |
146 | if (debugCode) printf("<---Read [%d] %s\n", ierr, response); |
145 | return ierr; |
147 | return ierr; |
146 | break; |
148 | break; |
147 | default: |
149 | default: |
148 | iret = ibrd (K6517_Gdev, response, maxbyt); |
150 | iret = ibrd (K6517_Gdev, response, maxbyt); |
149 | if (ibsta & ERR) GpibError("OpenDev Error"); |
151 | if (ibsta & ERR) GpibError("OpenDev Error"); |
Line 192... | Line 194... | ||
192 | // K6517_send ("SYST:ZCH 0",0); |
194 | // K6517_send ("SYST:ZCH 0",0); |
193 | K6517_send ("READ?",0); |
195 | K6517_send ("READ?",0); |
194 | 196 | ||
195 | cres[0]= 0; |
197 | cres[0]= 0; |
196 | int len = K6517_receive (cres, 50); |
198 | int len = K6517_receive (cres, 50); |
197 | printf("current >%d, %s\n",len,cres); |
199 | if (debugCode) printf("current >%d, %s\n",len,cres); |
198 | 200 | ||
199 | return atof(cres); |
201 | return atof(cres); |
200 | /* |
202 | /* |
201 | K6517_send ("X", 1); |
203 | K6517_send ("X", 1); |
202 | len = K6517_receive (cres, 50); |
204 | len = K6517_receive (cres, 50); |
Line 266... | Line 268... | ||
266 | void _VI_FUNC K6517_vsource_set (float value) |
268 | void _VI_FUNC K6517_vsource_set (float value) |
267 | { |
269 | { |
268 | int len; |
270 | int len; |
269 | char cmd[100]; |
271 | char cmd[100]; |
270 | len=sprintf(cmd,":SOURCE:VOLTAGE %f",value); |
272 | len=sprintf(cmd,":SOURCE:VOLTAGE %f",value); |
- | 273 | K6517_send (cmd, len); |
|
- | 274 | len=sprintf(cmd,":SOURCE:VOLTAGE:MCONNECT ON"); |
|
271 | K6517_send (cmd, len); |
275 | K6517_send (cmd, len); |
272 | return; |
276 | return; |
273 | } |
277 | } |
274 | 278 | ||
275 | double _VI_FUNC K6517_vsource_get (void) |
279 | double _VI_FUNC K6517_vsource_get (void) |
Line 386... | Line 390... | ||
386 | int gMask=0xF; |
390 | int gMask=0xF; |
387 | 391 | ||
388 | int pnl; |
392 | int pnl; |
389 | FILE *gFp; |
393 | FILE *gFp; |
390 | 394 | ||
- | 395 | static int tfID; |
|
- | 396 | static int rID; |
|
- | 397 | static CmtThreadPoolHandle poolHandle = 0; |
|
- | 398 | #define MAX_THREADS 10 |
|
- | 399 | ||
- | 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 | } |
|
391 | 591 | ||
392 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
592 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
393 | void *callbackData, int eventData1, int eventData2) |
593 | void *callbackData, int eventData1, int eventData2) |
394 | { |
594 | { |
395 | int state; |
595 | int state; |
Line 435... | Line 635... | ||
435 | fprintf(fp,"%d", current_run+1 ); |
635 | fprintf(fp,"%d", current_run+1 ); |
436 | fclose(fp); |
636 | fclose(fp); |
437 | } |
637 | } |
438 | return current_run+1; |
638 | return current_run+1; |
439 | } |
639 | } |
- | 640 | ||
440 | 641 | ||
441 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
642 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
442 | LPSTR lpszCmdLine, int nCmdShow) |
643 | LPSTR lpszCmdLine, int nCmdShow) |
443 | { |
644 | { |
444 | char cres[100]; |
645 | char cres[100]; |
445 | double Voltage, Current, tinterval; |
646 | double Voltage, Current, tinterval; |
446 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
647 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
447 | SetStdioPort (CVI_STDIO_WINDOW); |
648 | SetStdioPort (CVI_STDIO_WINDOW); |
- | 649 | SetSleepPolicy(VAL_SLEEP_MORE); |
|
- | 650 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
|
- | 651 | ||
448 | if ((pnl = LoadPanel (0, "K6517-ctrl.uir", P1)) < 0) return -1; |
652 | if ((pnl = LoadPanel (0, "K6517-ctrl.uir", P1)) < 0) return -1; |
449 | if ((pn2 = LoadPanel (0, "K6517-ctrl.uir", P2)) < 0) return -1; |
653 | if ((pn2 = LoadPanel (0, "K6517-ctrl.uir", P2)) < 0) return -1; |
450 | - | ||
- | 654 | DisableBreakOnLibraryErrors(); |
|
451 | K6517_open (1,4,3,0,13); |
655 | K6517_open (1,4,3,0,13); |
452 | 656 | ||
453 | 657 | ||
454 | SetCtrlVal(pnl, P1_ONOFF, 0); |
658 | SetCtrlVal(pnl, P1_ONOFF, 0); |
455 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
659 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
Line 466... | Line 670... | ||
466 | } |
670 | } |
467 | 671 | ||
468 | DisplayPanel (pnl); |
672 | DisplayPanel (pnl); |
469 | DisplayPanel (pn2); |
673 | DisplayPanel (pn2); |
470 | RunUserInterface (); |
674 | RunUserInterface (); |
- | 675 | CmtDiscardThreadPool (poolHandle); |
|
- | 676 | if (g_connected) |
|
- | 677 | DisconnectFromTCPServer (g_hconversation); |
|
471 | DiscardPanel (pn2); |
678 | DiscardPanel (pn2); |
472 | DiscardPanel (pnl); |
679 | DiscardPanel (pnl); |
473 | K6517_close(); |
680 | K6517_close(); |
474 | 681 | ||
475 | if (gFp) fclose(gFp); |
682 | if (gFp) fclose(gFp); |
Line 564... | Line 771... | ||
564 | double tinterval; |
771 | double tinterval; |
565 | switch (event) { |
772 | switch (event) { |
566 | case EVENT_COMMIT: |
773 | case EVENT_COMMIT: |
567 | GetCtrlVal(panel, control, &tinterval); |
774 | GetCtrlVal(panel, control, &tinterval); |
568 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
775 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
569 | break; |
776 | break; |
570 | } |
777 | } |
571 | return 0; |
778 | return 0; |
572 | } |
779 | } |
573 | 780 | ||
574 | 781 | ||
575 | 782 | ||
576 | int CVICALLBACK ExitCB (int panel, int control, int event, |
783 | int CVICALLBACK ExitCB (int panel, int control, int event, |
577 | void *callbackData, int eventData1, int eventData2) |
784 | void *callbackData, int eventData1, int eventData2) |
578 | { |
785 | { |
579 | switch (event) |
786 | switch (event) |
580 | { |
787 | { |
581 | case EVENT_COMMIT: |
788 | case EVENT_COMMIT: |
582 | K6517_send (":OUTP OFF", 0); |
789 | K6517_send (":OUTP OFF", 0); |
583 | QuitUserInterface(0); |
790 | QuitUserInterface(0); |
584 | break; |
791 | break; |
585 | } |
792 | } |
586 | return 0; |
793 | return 0; |
587 | } |
794 | } |
588 | 795 | ||
589 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
796 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
590 | void *callbackData, int eventData1, int eventData2) |
797 | void *callbackData, int eventData1, int eventData2) |
591 | { int ison; |
798 | { int ison; |
592 | switch (event) |
799 | switch (event) |
593 | { |
800 | { |
594 | case EVENT_COMMIT: |
801 | case EVENT_COMMIT: |
595 | GetCtrlVal(panel, control, &ison); |
802 | GetCtrlVal(panel, control, &ison); |
596 | for (int i=0;i<1;i++) if (control == radiob[i]) break; |
803 | for (int i=0;i<1;i++) if (control == radiob[i]) break; |
597 | gMask = ison; |
804 | gMask = ison; |
598 | break; |
805 | break; |
Line 643... | Line 850... | ||
643 | } |
850 | } |
644 | } |
851 | } |
645 | PlotStripChart (panel, P1_GRAPH, current, 1, 0, 0, VAL_DOUBLE); |
852 | PlotStripChart (panel, P1_GRAPH, current, 1, 0, 0, VAL_DOUBLE); |
646 | PlotStripChart (panel, P1_GRAPH_1, &voltage, 1, 0, 0, VAL_DOUBLE); |
853 | PlotStripChart (panel, P1_GRAPH_1, &voltage, 1, 0, 0, VAL_DOUBLE); |
647 | break; |
854 | break; |
648 | } |
855 | } |
649 | return 0; |
856 | return 0; |
650 | } |
857 | } |
651 | 858 | ||
652 | int CVICALLBACK TestCB (int panel, int control, int event, |
859 | int CVICALLBACK TestCB (int panel, int control, int event, |
653 | void *callbackData, int eventData1, int eventData2) { |
860 | void *callbackData, int eventData1, int eventData2) { |
654 | switch (event) { |
861 | switch (event) { |
Line 658... | Line 865... | ||
658 | } |
865 | } |
659 | return 0; |
866 | return 0; |
660 | } |
867 | } |
661 | 868 | ||
662 | 869 | ||
663 | int |
870 | int ivscan (void *arg) { |
664 |
|
871 | int *iarg = (int *) arg; |
665 | int nsteps; |
872 | int nsteps; |
666 | double umin, umax, u; |
873 | double umin, umax, u; |
667 | double *xpoints; |
874 | double *xpoints; |
668 | double *ypoints; |
875 | double *ypoints; |
669 | static int plivhandle=0; |
876 | static int plivhandle=0; |
Line 680... | Line 887... | ||
680 | int overflow; |
887 | int overflow; |
681 | char ovf[10]; |
888 | char ovf[10]; |
682 | FILE *fp; |
889 | FILE *fp; |
683 | time_t mtime; |
890 | time_t mtime; |
684 | ssize_t size; |
891 | ssize_t size; |
685 | - | ||
686 |
|
892 | int repeatscan = 1; |
687 |
|
893 | while (repeatscan){ |
- | 894 | ||
- | 895 | ||
688 | K6517_send (":OUTP ON", 0); |
896 | K6517_send (":OUTP ON", 0); |
689 | // GetCtrlVal(panel, P2_UMIN, &umin); |
- | |
690 | // GetCtrlVal(panel, P2_UMAX, &umax); |
- | |
691 | // GetCtrlVal(panel, P2_NSTEPS, &nsteps); |
- | |
- | 897 | ||
692 | SetCtrlVal(pnl, P1_TIMERON, 0); |
898 | SetCtrlVal(pnl, P1_TIMERON, 0); |
693 | GetCtrlVal( |
899 | GetCtrlVal(pn2, P2_FILENAME, fileName); |
694 | GetCtrlVal( |
900 | GetCtrlVal(pn2, P2_PATH, path); |
695 | // GetCtrlVal(panel, P2_RANGE, &range); |
- | |
- | 901 | ||
696 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT, NULL, 0, 0); |
902 | TimerOnOffCB(pnl, P1_TIMERON, EVENT_COMMIT, NULL, 0, 0); |
- | 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); |
|
697 | sprintf |
912 | else sprintf(fname, "%s/%s_T%d.dat", path, fileName,*iarg); |
698 | if ( !GetFileInfo(fname,&size) ) |
913 | if ( !GetFileInfo(fname,&size) || strstr("test",fileName)!=NULL ) |
699 | fp = fopen(fname,"w"); |
914 | fp = fopen(fname,"w"); |
700 | else { |
915 | else { |
701 | sprintf(cres, "File %s exist\n Remove it first",fname); |
916 | sprintf(cres, "File %s exist\n Remove it first",fname); |
702 | MessagePopup ("Info", cres); |
917 | MessagePopup ("Info", cres); |
703 | return 0; |
918 | return 0; |
- | 919 | } |
|
704 | } |
920 | } |
705 | time(&mtime); |
921 | time(&mtime); |
706 | printf("#%s %s\n",DateStr(), TimeStr()); |
922 | printf("#%s %s\n",DateStr(), TimeStr()); |
707 | if (fp) fprintf(fp, "#%s %s\n",DateStr(), TimeStr()); |
923 | if (fp) fprintf(fp, "#%s %s\n",DateStr(), TimeStr()); |
708 | // K6517_current_mode (range); |
924 | // K6517_current_mode (range); |
709 | stop = 0; |
925 | stop = 0; |
710 | LogScaleCB ( |
926 | LogScaleCB (pn2, P2_LOGSCALE, EVENT_COMMIT,NULL, 0, 0); |
711 | int voltageMax[4]={P2_UMAX_1,P2_UMAX_2,P2_UMAX_3,P2_UMAX_4}; |
927 | 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}; |
928 | 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}; |
929 | 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}; |
930 | 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}; |
931 | int intervals[4]={P2_SLCT_1,P2_SLCT_2,P2_SLCT_3,P2_SLCT_4}; |
716 | int nrOfInt; |
932 | int nrOfInt; |
717 | int nrOfSteps; |
933 | int nrOfSteps; |
718 | int N=0; |
934 | int N=0; |
719 | int K=0; |
935 | int K=0; |
720 | for (int j=0;j<4;j++){ |
936 | for (int j=0;j<4;j++){ |
721 | GetCtrlVal( |
937 | GetCtrlVal(pn2, intervals[j], &nrOfInt); |
722 | N = N + nrOfInt; |
938 | N = N + nrOfInt; |
723 | GetCtrlVal( |
939 | GetCtrlVal(pn2, numberOfSteps[j], &nrOfSteps); |
724 | K = K + nrOfSteps; |
940 | K = K + nrOfSteps; |
725 | } |
941 | } |
726 | xpoints = (double *) malloc ((K-N+2)*sizeof(double)); |
942 | xpoints = (double *) malloc ((K-N+2)*sizeof(double)*4); |
727 | ypoints = (double *) malloc ((K-N+2)*sizeof(double)); |
943 | ypoints = (double *) malloc ((K-N+2)*sizeof(double)*4); |
728 | int tockaK=0; |
944 | int tockaK=0; |
- | 945 | double t1,t2; |
|
- | 946 | GetCtrlVal(pn2, P2_DELAY, &t1); |
|
- | 947 | GetCtrlVal(pn2, P2_DELAY2, &t2); |
|
- | 948 | ||
729 | for (int i=0;i<N;i++){ |
949 | for (int i=0;i<N;i++){ |
730 | GetCtrlVal( |
950 | GetCtrlVal(pn2, voltageMin[i], &umin); |
731 | GetCtrlVal( |
951 | GetCtrlVal(pn2, voltageMax[i], &umax); |
732 | GetCtrlVal( |
952 | GetCtrlVal(pn2, numberOfSteps[i], &nsteps); |
733 | GetCtrlVal( |
953 | GetCtrlVal(pn2, selectRange[i], &range); |
734 | K6517_current_mode (range); |
954 | K6517_current_mode (range); |
735 | for (int n=0;n<nsteps+1;n++){ |
955 | for (int n=0;n<nsteps+1;n++){ |
- | 956 | ||
736 | if (i>0) { |
957 | if (i>0) { |
737 | if(n==0) n++; |
958 | if(n==0) n++; |
738 | }; |
959 | }; |
739 | u= umin+ n*(umax-umin)/nsteps; |
960 | u= umin+ n*(umax-umin)/nsteps; |
- | 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 | } |
|
740 | K6517_vsource_set (u); |
970 | K6517_vsource_set (u); |
- | 971 | current =K6517_get(cres,&k); |
|
- | 972 | if (n==0) Delay(t1); |
|
- | 973 | Delay(t2); |
|
741 | // voltage =K6517_vsource_get(); |
974 | // voltage =K6517_vsource_get(); |
742 | current =K6517_get(cres,&k); |
975 | current =K6517_get(cres,&k); |
743 |
|
976 | // if (current > range) printf("Overflow +\n"); |
744 |
|
977 | // if (current < -range) printf("Overflow -\n"); |
745 | voltage = u; |
978 | voltage = u; |
746 | xpoints[tockaK]= voltage; |
979 | xpoints[tockaK]= voltage; |
747 | ypoints[tockaK]= current; |
980 | ypoints[tockaK]= current; |
748 | SetCtrlVal( |
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); |
|
749 | if (fp) fprintf(fp, "%d %g %g %g\n |
987 | if (fp) fprintf(fp, "%d %g %g %g %g %g\n",tockaK, u, voltage,current, humidity, temperature); |
750 | printf("n=%d u=%g voltage=%g current=%g\n",tockaK, u, voltage,current); |
988 | if (debugCode) printf("n=%d u=%g voltage=%g current=%g\n",tockaK, u, voltage,current); |
751 | if (plivhandle) DeleteGraphPlot ( |
989 | if (plivhandle) DeleteGraphPlot (pn2, P2_GRAPHIV, plivhandle, VAL_IMMEDIATE_DRAW); |
752 | plivhandle = PlotXY ( |
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); |
753 | ProcessSystemEvents(); |
991 | ProcessSystemEvents(); |
754 | tockaK++; |
992 | tockaK++; |
755 | if (stop) break; |
993 | if (stop) break; |
756 | } |
994 | } |
- | 995 | if (stop) break; |
|
757 | } |
996 | } |
- | 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); |
|
758 | fclose(fp); |
1003 | fclose(fp); |
759 | free(xpoints); |
1004 | free(xpoints); |
760 | free(ypoints); |
1005 | free(ypoints); |
- | 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 | } |
|
761 | break; |
1043 | break; |
762 | } |
1044 | } |
763 | return 0; |
1045 | return 0; |
764 | } |
1046 | } |
- | 1047 | ||
765 | 1048 | ||
766 | int CVICALLBACK SETVOLTCB (int panel, int control, int event, |
1049 | int CVICALLBACK SETVOLTCB (int panel, int control, int event, |
767 | void *callbackData, int eventData1, int eventData2) { |
1050 | void *callbackData, int eventData1, int eventData2) { |
768 | double voltage; |
1051 | double voltage; |
769 | switch (event) { |
1052 | switch (event) { |
770 | case EVENT_COMMIT: |
1053 | case EVENT_COMMIT: |
771 | GetCtrlVal(panel, P2_VOLT, &voltage); |
1054 | GetCtrlVal(panel, P2_VOLT, &voltage); |
772 | K6517_vsource_set (voltage); |
1055 | K6517_vsource_set (voltage); |
- | 1056 | SetCtrlVal(panel, P2_VMON, voltage); |
|
773 | break; |
1057 | break; |
774 | } |
1058 | } |
775 | return 0; |
1059 | return 0; |
776 | } |
1060 | } |
777 | 1061 | ||
778 | 1062 | ||
779 | int CVICALLBACK StopCB (int panel, int control, int event, |
1063 | int CVICALLBACK StopCB (int panel, int control, int event, |
780 | void *callbackData, int eventData1, int eventData2) { |
1064 | void *callbackData, int eventData1, int eventData2) { |
781 | switch (event) { |
1065 | switch (event) { |
782 | case EVENT_COMMIT: |
1066 | case EVENT_COMMIT: |
783 | stop = 1; |
1067 | stop = 1; |
784 | break; |
1068 | break; |
785 | } |
1069 | } |
786 | return 0; |
1070 | return 0; |
787 | } |
1071 | } |
788 | 1072 | ||
789 | int CVICALLBACK LogScaleCB (int panel, int control, int event, |
1073 | int CVICALLBACK LogScaleCB (int panel, int control, int event, |
Line 795... | Line 1079... | ||
795 | if(selected) SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LOG); |
1079 | if(selected) SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LOG); |
796 | else SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LINEAR); |
1080 | else SetCtrlAttribute (panel, P2_GRAPHIV,ATTR_YMAP_MODE, VAL_LINEAR); |
797 | break; |
1081 | break; |
798 | } |
1082 | } |
799 | return 0; |
1083 | return 0; |
800 | } |
1084 | } |
801 | 1085 | ||
802 | 1086 | ||
803 | //**************************** |
1087 | //**************************** |
804 | int EscapeString(const char *i, char *o) { |
1088 | int EscapeString(const char *i, char *o) { |
805 | int iptr=0, optr = 0; |
1089 | int iptr=0, optr = 0; |
Line 819... | Line 1103... | ||
819 | } |
1103 | } |
820 | 1104 | ||
821 | 1105 | ||
822 | int CVICALLBACK DrawCB (int panel, int control, int event, |
1106 | int CVICALLBACK DrawCB (int panel, int control, int event, |
823 | void *callbackData, int eventData1, int eventData2) { |
1107 | void *callbackData, int eventData1, int eventData2) { |
824 | switch (event) { |
1108 | switch (event) { |
825 | case EVENT_COMMIT:{ |
1109 | case EVENT_COMMIT:{ |
826 | char fileName[100]; |
1110 | char fileName[100]; |
827 | char fname[100]; |
1111 | char fname[100]; |
828 | char path[100]; |
1112 | char path[100]; |
829 | GetCtrlVal(panel, P2_FILENAME, fileName); |
1113 | GetCtrlVal(panel, P2_FILENAME, fileName); |
Line 875... | Line 1159... | ||
875 | } |
1159 | } |
876 | 1160 | ||
877 | int CVICALLBACK DebugCB (int panel, int control, int event, |
1161 | int CVICALLBACK DebugCB (int panel, int control, int event, |
878 | void *callbackData, int eventData1, int eventData2) { |
1162 | void *callbackData, int eventData1, int eventData2) { |
879 | int selected; |
1163 | int selected; |
880 |
|
1164 | |
881 | switch (event) { |
1165 | switch (event) { |
882 | case EVENT_COMMIT: |
1166 | case EVENT_COMMIT: |
883 | GetCtrlVal(panel, control, &selected); |
1167 | GetCtrlVal(panel, control, &selected); |
884 | if(selected) debugCode = 1; |
1168 | if(selected) debugCode = 1; |
885 | else debugCode = 0; |
1169 | else debugCode = 0; |
886 | break; |
1170 | break; |
887 | } |
1171 | } |
Line 896... | Line 1180... | ||
896 | QuitUserInterface(0); |
1180 | QuitUserInterface(0); |
897 | break; |
1181 | break; |
898 | } |
1182 | } |
899 | return 0; |
1183 | return 0; |
900 | } |
1184 | } |
- | 1185 | ||
- | 1186 | ||
- | 1187 | ||
901 | #endif |
1188 | #endif |