Rev 304 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 304 | Rev 313 | ||
|---|---|---|---|
| Line 181... | Line 181... | ||
| 181 | len=sprintf(cmd,"G%0dX",mode); |
181 | len=sprintf(cmd,"G%0dX",mode); |
| 182 | K6517_send (cmd, len); |
182 | K6517_send (cmd, len); |
| 183 | return; |
183 | return; |
| 184 | } |
184 | } |
| 185 | 185 | ||
| - | 186 | int _VI_FUNC K6517_EventStatus () |
|
| - | 187 | { |
|
| - | 188 | K6517_send (":STATUS:MEAS:EVEN?",0); |
|
| - | 189 | char cres[100]; |
|
| - | 190 | cres[0]= 0; |
|
| - | 191 | int len = K6517_receive (cres, 50); |
|
| - | 192 | if (len>0) |
|
| - | 193 | return atoi(cres); |
|
| - | 194 | else |
|
| - | 195 | return -1; |
|
| - | 196 | } |
|
| 186 | double _VI_FUNC K6517_get (char *prefix, int *loc) |
197 | double _VI_FUNC K6517_get (char *prefix, int *loc) |
| 187 | { |
198 | { |
| 188 | 199 | ||
| 189 | double value; |
200 | double value; |
| 190 | char cres[100]; |
201 | char cres[100]; |
| Line 271... | Line 282... | ||
| 271 | char cmd[100]; |
282 | char cmd[100]; |
| 272 | len=sprintf(cmd,":SOURCE:VOLTAGE %f",value); |
283 | len=sprintf(cmd,":SOURCE:VOLTAGE %f",value); |
| 273 | K6517_send (cmd, len); |
284 | K6517_send (cmd, len); |
| 274 | len=sprintf(cmd,":SOURCE:VOLTAGE:MCONNECT ON"); |
285 | len=sprintf(cmd,":SOURCE:VOLTAGE:MCONNECT ON"); |
| 275 | K6517_send (cmd, len); |
286 | K6517_send (cmd, len); |
| 276 | return; |
287 | return; |
| 277 | } |
288 | } |
| 278 | 289 | ||
| 279 | double _VI_FUNC K6517_vsource_get (void) |
290 | double _VI_FUNC K6517_vsource_get (void) |
| 280 | { |
291 | { |
| 281 | double value; |
292 | double value; |
| 282 | 293 | ||
| Line 409... | Line 420... | ||
| 409 | /* Internal function prototypes */ |
420 | /* Internal function prototypes */ |
| 410 | /*---------------------------------------------------------------------------*/ |
421 | /*---------------------------------------------------------------------------*/ |
| 411 | int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, |
422 | int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, |
| 412 | void *callbackData); |
423 | void *callbackData); |
| 413 | static void ReportTCPError (void); |
424 | static void ReportTCPError (void); |
| 414 | 425 | ||
| 415 | /*---------------------------------------------------------------------------*/ |
426 | /*---------------------------------------------------------------------------*/ |
| 416 | /* Module-globals */ |
427 | /* Module-globals */ |
| 417 | /*---------------------------------------------------------------------------*/ |
428 | /*---------------------------------------------------------------------------*/ |
| 418 | static unsigned int g_hconversation; |
429 | static unsigned int g_hconversation; |
| 419 | static int g_hmainPanel; |
430 | static int g_hmainPanel; |
| Line 455... | Line 466... | ||
| 455 | int portNum=10000; |
466 | int portNum=10000; |
| 456 | char tempBuf[512]; |
467 | char tempBuf[512]; |
| 457 | sprintf(tempBuf,"localhost"); |
468 | sprintf(tempBuf,"localhost"); |
| 458 | switch (event) { |
469 | switch (event) { |
| 459 | case EVENT_COMMIT: |
470 | case EVENT_COMMIT: |
| - | 471 | if (g_connected) return 0; |
|
| 460 | if (ConnectToTCPServer (&g_hconversation, portNum, tempBuf, ClientTCPCB, NULL, 5000) < 0) |
472 | if (ConnectToTCPServer (&g_hconversation, portNum, tempBuf, ClientTCPCB, NULL, 5000) < 0) |
| 461 | MessagePopup("TCP Client", "Connection to server failed !"); |
473 | MessagePopup("TCP Client", "Connection to server failed !"); |
| 462 | else |
474 | else |
| 463 | { |
475 | { |
| 464 | SetWaitCursor (0); |
476 | SetWaitCursor (0); |
| Line 504... | Line 516... | ||
| 504 | float tdiff=0; |
516 | float tdiff=0; |
| 505 | int t0 = 0; |
517 | int t0 = 0; |
| 506 | sscanf(receiveBuf, "%d%f%f%f%f", &t0,&humidity,&temp, &tdiff, &dt); |
518 | sscanf(receiveBuf, "%d%f%f%f%f", &t0,&humidity,&temp, &tdiff, &dt); |
| 507 | SetCtrlVal(pn2,P2_TMON, temp); |
519 | SetCtrlVal(pn2,P2_TMON, temp); |
| 508 | SetCtrlVal(pn2,P2_HUMIDITY, humidity); |
520 | SetCtrlVal(pn2,P2_HUMIDITY, humidity); |
| 509 | if (fabs(tdiff)<0. |
521 | if (fabs(tdiff)<0.2 && fabs(dt) < 0.05) SetCtrlVal(pn2,P2_LED, 1); |
| 510 | else SetCtrlVal(pn2,P2_LED, 0); |
522 | else SetCtrlVal(pn2,P2_LED, 0); |
| 511 | } |
523 | } |
| 512 | break; |
524 | break; |
| 513 | case TCP_DISCONNECT: |
525 | case TCP_DISCONNECT: |
| 514 | MessagePopup ("TCP Client", "Server has closed connection!"); |
526 | MessagePopup ("TCP Client", "Server has closed connection!"); |
| Line 542... | Line 554... | ||
| 542 | 554 | ||
| 543 | double temp; |
555 | double temp; |
| 544 | int n=0; |
556 | int n=0; |
| 545 | int led; |
557 | int led; |
| 546 | GetNumTableRows (pn2, P2_TABLE, &n ); |
558 | GetNumTableRows (pn2, P2_TABLE, &n ); |
| - | 559 | stop = 0; |
|
| 547 | for(int i=0; i<n; i++) { |
560 | for(int i=0; i<n; i++) { |
| - | 561 | if (stop) break; |
|
| 548 | GetTableCellVal (pn2, P2_TABLE, MakePoint (1,i+1), &temp); |
562 | GetTableCellVal (pn2, P2_TABLE, MakePoint (1,i+1), &temp); |
| 549 | if (temp>100) break; |
563 | if (temp>100) break; |
| 550 | char transmitBuf[512]= {0}; |
564 | char transmitBuf[512]= {0}; |
| 551 | sprintf(transmitBuf, "1 %f\n", temp); |
565 | sprintf(transmitBuf, "1 %f\n", temp); |
| - | 566 | ||
| 552 |
|
567 | |
| 553 | if ( |
568 | if (g_connected) |
| 554 | if ( ClientTCPWrite (g_hconversation, transmitBuf, strlen (transmitBuf), 1000) < 0) printf("Transmit Error\n"); |
569 | if ( ClientTCPWrite (g_hconversation, transmitBuf, strlen (transmitBuf), 1000) < 0) printf("Transmit Error\n"); else printf("%s\n", transmitBuf); |
| 555 | 570 | SetCtrlVal(pn2,P2_LED, 0); |
|
| 556 | do { |
571 | do { |
| 557 | time_t t0 = time(NULL); |
572 | time_t t0 = time(NULL); |
| 558 | SetCtrlVal(pn2,P2_TIME, ctime(&t0)); |
573 | SetCtrlVal(pn2,P2_TIME, ctime(&t0)); |
| 559 | Delay(1); |
574 | Delay(1); |
| 560 | GetCtrlVal(pn2,P2_LED, &led); |
575 | GetCtrlVal(pn2,P2_LED, &led); |
| - | 576 | if (led) { |
|
| - | 577 | for (int k=0;k<10;k++){ |
|
| - | 578 | Delay(1); |
|
| - | 579 | if (stop) break; |
|
| - | 580 | } |
|
| - | 581 | GetCtrlVal(pn2,P2_LED, &led); |
|
| - | 582 | } |
|
| 561 | if (stop) break; |
583 | if (stop) break; |
| 562 | } while (!led); |
584 | } while (!led); |
| 563 | if (stop) break; |
585 | if (stop) break; |
| 564 | 586 | ||
| 565 | int itemp = (int) temp; |
587 | int itemp = (int) temp; |
| Line 971... | Line 993... | ||
| 971 | current =K6517_get(cres,&k); |
993 | current =K6517_get(cres,&k); |
| 972 | if (n==0) Delay(t1); |
994 | if (n==0) Delay(t1); |
| 973 | Delay(t2); |
995 | Delay(t2); |
| 974 | // voltage =K6517_vsource_get(); |
996 | // voltage =K6517_vsource_get(); |
| 975 | current =K6517_get(cres,&k); |
997 | current =K6517_get(cres,&k); |
| - | 998 | int status = K6517_EventStatus(); |
|
| - | 999 | SetCtrlVal(pn2,P2_STATUS, status); |
|
| - | 1000 | SetCtrlVal(pn2,P2_OVERFLOW, status & 0x1); |
|
| 976 | // if (current > range) printf("Overflow +\n"); |
1001 | // if (current > range) printf("Overflow +\n"); |
| 977 | // if (current < -range) printf("Overflow -\n"); |
1002 | // if (current < -range) printf("Overflow -\n"); |
| - | 1003 | if (status & 0x1){ |
|
| - | 1004 | if (range>0) range*=10; |
|
| - | 1005 | K6517_current_mode (range); |
|
| - | 1006 | Delay(1); |
|
| - | 1007 | current =K6517_get(cres,&k); |
|
| - | 1008 | status = K6517_EventStatus(); |
|
| - | 1009 | SetCtrlVal(pn2,P2_STATUS, status); |
|
| - | 1010 | SetCtrlVal(pn2,P2_OVERFLOW, status & 0x1); |
|
| - | 1011 | } |
|
| 978 | voltage = u; |
1012 | voltage = u; |
| 979 | xpoints[tockaK]= voltage; |
1013 | xpoints[tockaK]= voltage; |
| 980 | ypoints[tockaK]= current; |
1014 | ypoints[tockaK]= current; |
| 981 | SetCtrlVal(pn2, P2_VMON, voltage); |
1015 | SetCtrlVal(pn2, P2_VMON, voltage); |
| 982 | SetCtrlVal(pn2, P2_VCUR, current); |
1016 | SetCtrlVal(pn2, P2_VCUR, current); |
| 983 | double temperature=0; |
1017 | double temperature=0; |
| 984 | double humidity=0; |
1018 | double humidity=0; |
| 985 | GetCtrlVal(pn2, P2_TMON, &temperature); |
1019 | GetCtrlVal(pn2, P2_TMON, &temperature); |
| 986 | GetCtrlVal(pn2, P2_HUMIDITY, &humidity); |
1020 | GetCtrlVal(pn2, P2_HUMIDITY, &humidity); |
| 987 | if (fp) fprintf(fp, "%d %g %g %g %g %g\n" |
1021 | if (fp) fprintf(fp, "%d %g %g %g %g %g %d\n",tockaK, u, voltage,current, humidity, temperature, status); |
| 988 | if (debugCode) printf("n=%d u=%g voltage=%g current=%g\n",tockaK, u, voltage,current); |
1022 | 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); |
1023 | 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); |
1024 | plivhandle = PlotXY (pn2, P2_GRAPHIV, xpoints, ypoints, tockaK+1, VAL_DOUBLE, VAL_DOUBLE, VAL_CONNECTED_POINTS, VAL_BOLD_X, VAL_SOLID, 1, VAL_RED); |
| 991 | ProcessSystemEvents(); |
1025 | ProcessSystemEvents(); |
| 992 | tockaK++; |
1026 | tockaK++; |