Rev 280 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 280 | Rev 297 | ||
---|---|---|---|
Line 347... | Line 347... | ||
347 | int vset[4]={P1_U_1,P1_U_2,P1_U_3,P1_U_4 }; |
347 | int vset[4]={P1_U_1,P1_U_2,P1_U_3,P1_U_4 }; |
348 | int iset[4]={P1_I_1,P1_I_2,P1_I_3,P1_I_4 }; |
348 | int iset[4]={P1_I_1,P1_I_2,P1_I_3,P1_I_4 }; |
349 | int radiob[4]={P1_BOX_1,P1_BOX_2,P1_BOX_3,P1_BOX_4 }; |
349 | int radiob[4]={P1_BOX_1,P1_BOX_2,P1_BOX_3,P1_BOX_4 }; |
350 | 350 | ||
351 | int cvcc[4]={P1_CVCC_1,P1_CVCC_2,P1_CVCC_3,P1_CVCC_4 }; |
351 | int cvcc[4]={P1_CVCC_1,P1_CVCC_2,P1_CVCC_3,P1_CVCC_4 }; |
352 | const unsigned char Pre_1 = 1; |
- | |
- | 352 | ||
353 | int gMask=0xF; |
353 | int gMask=0xF; |
354 | 354 | ||
355 | int pnl; |
355 | int pnl; |
356 | FILE *gFp; |
356 | FILE *gFp; |
357 | int main (int argc, char *argv[]) |
357 | int main (int argc, char *argv[]) |
358 | { |
358 | { |
359 | int DeviceId=0; |
359 | int DeviceId=0; |
360 | unsigned char MainOutput; |
360 | unsigned char MainOutput, preset; |
361 | double Voltage, Current, tinterval; |
361 | double Voltage, Current, tinterval; |
362 | char str[0xFF]; |
362 | char str[0xFF]; |
363 | if (InitCVIRTE (0, argv, 0) == 0) |
363 | if (InitCVIRTE (0, argv, 0) == 0) |
364 | return -1; /* out of memory */ |
364 | return -1; /* out of memory */ |
365 | SetStdioPort (CVI_STDIO_WINDOW); |
365 | SetStdioPort (CVI_STDIO_WINDOW); |
Line 373... | Line 373... | ||
373 | 373 | ||
374 | TMI_MainOutputQ(TMI_DeviceId, &MainOutput); |
374 | TMI_MainOutputQ(TMI_DeviceId, &MainOutput); |
375 | SetCtrlVal(pnl, P1_ONOFF, MainOutput); |
375 | SetCtrlVal(pnl, P1_ONOFF, MainOutput); |
376 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
376 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
377 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
377 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
- | 378 | TMI_PresetQ(TMI_DeviceId, &preset); |
|
- | 379 | SetCtrlVal(pnl, P1_PRESET, preset); |
|
- | 380 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 1, ATTR_TRACE_LG_TEXT, "CH +18V"); |
|
- | 381 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 2, ATTR_TRACE_LG_TEXT, "CH -18V"); |
|
- | 382 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 3, ATTR_TRACE_LG_TEXT, "CH +6V"); |
|
- | 383 | SetTraceAttributeEx (pnl, P1_GRAPH_IMON, 4, ATTR_TRACE_LG_TEXT, "CH -6V"); |
|
378 | 384 | ||
- | 385 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 1, ATTR_TRACE_LG_TEXT, "CH +18V"); |
|
- | 386 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 2, ATTR_TRACE_LG_TEXT, "CH -18V"); |
|
- | 387 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 3, ATTR_TRACE_LG_TEXT, "CH +6V"); |
|
- | 388 | SetTraceAttributeEx (pnl, P1_GRAPH_VMON, 4, ATTR_TRACE_LG_TEXT, "CH -6V"); |
|
379 | for (unsigned char ch=0;ch<4;ch++){ |
389 | for (unsigned char ch=0;ch<4;ch++){ |
380 | int ison; |
390 | int ison; |
381 | TMI_VoltageQ(TMI_DeviceId, ch+1, |
391 | TMI_VoltageQ(TMI_DeviceId, ch+1, preset, &Voltage); |
382 | TMI_CurrentQ(TMI_DeviceId, ch+1, |
392 | TMI_CurrentQ(TMI_DeviceId, ch+1, preset, &Current); |
383 | SetCtrlVal(pnl, vset[ch], Voltage); |
393 | SetCtrlVal(pnl, vset[ch], Voltage); |
384 | SetCtrlVal(pnl, iset[ch], Current); |
394 | SetCtrlVal(pnl, iset[ch], Current); |
385 | GetCtrlVal(pnl, radiob[ch], &ison); |
395 | GetCtrlVal(pnl, radiob[ch], &ison); |
386 | if (ison) SETREG(gMask,(1<<ch)); else RSTREG(gMask,(1<<ch)); |
396 | if (ison) SETREG(gMask,(1<<ch)); else RSTREG(gMask,(1<<ch)); |
387 | } |
397 | } |
Line 417... | Line 427... | ||
417 | { |
427 | { |
418 | 428 | ||
419 | 429 | ||
420 | switch (event) |
430 | switch (event) |
421 | { |
431 | { |
422 | case EVENT_COMMIT: |
432 | case EVENT_COMMIT:{ |
423 | 433 | unsigned char preset; |
|
- | 434 | TMI_PresetQ(TMI_DeviceId, &preset); |
|
- | 435 | SetCtrlVal(pnl, P1_PRESET, preset); |
|
424 | for (unsigned char ch = 0; ch<4;ch++){ |
436 | for (unsigned char ch = 0; ch<4;ch++){ |
425 | //printf("ch %d %x\n", ch, gMask); |
437 | //printf("ch %d %x\n", ch, gMask); |
426 | if (gMask & (1<<ch)){ |
438 | if (gMask & (1<<ch)){ |
427 | double Voltage; |
439 | double Voltage; |
428 | double Current; |
440 | double Current; |
- | 441 | ||
429 | GetCtrlVal(panel, vset[ch], &Voltage); |
442 | GetCtrlVal(panel, vset[ch], &Voltage); |
430 | GetCtrlVal(panel, iset[ch], &Current); |
443 | GetCtrlVal(panel, iset[ch], &Current); |
431 |
|
444 | //printf("->ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
432 | TMI_Voltage(TMI_DeviceId, ch+1, |
445 | TMI_Voltage(TMI_DeviceId, ch+1, preset, Voltage); |
433 | TMI_VoltageQ(TMI_DeviceId, ch+1, |
446 | TMI_VoltageQ(TMI_DeviceId, ch+1, preset, &Voltage); |
434 | TMI_Current(TMI_DeviceId, ch+1, |
447 | TMI_Current(TMI_DeviceId, ch+1, preset, Current); |
435 | TMI_CurrentQ(TMI_DeviceId, ch+1, |
448 | TMI_CurrentQ(TMI_DeviceId, ch+1, preset, &Current); |
436 |
|
449 | //printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
437 | 450 | ||
438 | } |
451 | } |
439 | } |
452 | } |
- | 453 | } |
|
440 | break; |
454 | break; |
441 | } |
455 | } |
442 | return 0; |
456 | return 0; |
443 | } |
457 | } |
444 | 458 | ||
Line 449... | Line 463... | ||
449 | int iRet; |
463 | int iRet; |
450 | char ch=0; |
464 | char ch=0; |
451 | double Voltage; |
465 | double Voltage; |
452 | double Current; |
466 | double Current; |
453 | char cv_cc; |
467 | char cv_cc; |
454 | switch (event) |
468 | switch (event) |
455 | { |
469 | { |
456 | case EVENT_COMMIT: |
470 | case EVENT_COMMIT: |
457 | for (ch = 0; ch<4;ch++){ |
471 | for (ch = 0; ch<4;ch++){ |
458 | if (gMask & (1<<ch)){ |
472 | if (gMask & (1<<ch)){ |
459 | iRet = TMI_TimeOut(TMI_DeviceId, 1); |
473 | iRet = TMI_TimeOut(TMI_DeviceId, 1); |
460 | iRet = TMI_Refresh(TMI_DeviceId); |
474 | iRet = TMI_Refresh(TMI_DeviceId); |
461 | iRet = TMI_MoniDataQ(TMI_DeviceId, ch+1, &Voltage, &Current, &cv_cc); |
475 | iRet = TMI_MoniDataQ(TMI_DeviceId, ch+1, &Voltage, &Current, &cv_cc); |
462 |
|
476 | //printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
463 | SetCtrlVal(panel, vmon[ch], Voltage); |
477 | SetCtrlVal(panel, vmon[ch], Voltage); |
464 | SetCtrlVal(panel, imon[ch], Current); |
478 | SetCtrlVal(panel, imon[ch], Current); |
465 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
479 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
466 | } |
480 | } |
467 | } |
481 | } |
Line 493... | Line 507... | ||
493 | if (state){ |
507 | if (state){ |
494 | ResumeTimerCallbacks(); |
508 | ResumeTimerCallbacks(); |
495 | } else { |
509 | } else { |
496 | SuspendTimerCallbacks (); |
510 | SuspendTimerCallbacks (); |
497 | printf ("Disabling timer....\n"); |
511 | printf ("Disabling timer....\n"); |
498 | } |
512 | } |
499 | break; |
513 | break; |
500 | } |
514 | } |
501 | return 0; |
515 | return 0; |
502 | } |
516 | } |
503 | 517 | ||
504 | int CVICALLBACK ExitCB (int panel, int control, int event, |
518 | int CVICALLBACK ExitCB (int panel, int control, int event, |
505 | void *callbackData, int eventData1, int eventData2) |
519 | void *callbackData, int eventData1, int eventData2) |
506 | { |
520 | { |
507 | switch (event) |
521 | switch (event) |
508 | { |
522 | { |
509 | case EVENT_COMMIT: |
523 | case EVENT_COMMIT: |
510 | QuitUserInterface(0); |
524 | QuitUserInterface(0); |
511 | break; |
525 | break; |
512 | } |
526 | } |
513 | return 0; |
527 | return 0; |
Line 520... | Line 534... | ||
520 | { |
534 | { |
521 | case EVENT_COMMIT: |
535 | case EVENT_COMMIT: |
522 | GetCtrlVal(panel, control, &ison); |
536 | GetCtrlVal(panel, control, &ison); |
523 | for (int i=0;i<4;i++) if (control == radiob[i]) break; |
537 | for (int i=0;i<4;i++) if (control == radiob[i]) break; |
524 | if (ison) SETREG(gMask,(1<<i)); else RSTREG(gMask,(1<<i)); |
538 | if (ison) SETREG(gMask,(1<<i)); else RSTREG(gMask,(1<<i)); |
525 | break; |
539 | break; |
526 | } |
540 | } |
527 | return 0; |
541 | return 0; |
528 | } |
542 | } |
529 | 543 | ||
530 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
544 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
Line 547... | Line 561... | ||
547 | switch (event) |
561 | switch (event) |
548 | { |
562 | { |
549 | 563 | ||
550 | unsigned char ch; |
564 | unsigned char ch; |
551 | double current[4]; |
565 | double current[4]; |
552 | double voltage; |
566 | double voltage[4]; |
553 | char cv_cc; |
567 | char cv_cc; |
554 | case EVENT_TIMER_TICK: |
568 | case EVENT_TIMER_TICK: |
555 | for (ch = 0; ch<4;ch++){ |
569 | for (ch = 0; ch<4;ch++){ |
556 | if (gMask & (1<<ch)){ |
570 | if (gMask & (1<<ch)){ |
557 | TMI_TimeOut(TMI_DeviceId, 1); |
571 | TMI_TimeOut(TMI_DeviceId, 1); |
558 | TMI_Refresh(TMI_DeviceId); |
572 | TMI_Refresh(TMI_DeviceId); |
559 | TMI_MoniDataQ(TMI_DeviceId, ch+1, &voltage, ¤t[ch], &cv_cc); |
573 | TMI_MoniDataQ(TMI_DeviceId, ch+1, &voltage[ch], ¤t[ch], &cv_cc); |
560 | SetCtrlVal(panel, vmon[ch], voltage); |
574 | SetCtrlVal(panel, vmon[ch], voltage[ch]); |
561 | SetCtrlVal(panel, imon[ch], current[ch]); |
575 | SetCtrlVal(panel, imon[ch], current[ch]); |
562 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
576 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
563 | if (gLogToFile){ |
577 | if (gLogToFile){ |
564 | if (!gFp) { |
578 | if (!gFp) { |
565 | gFp= fopen("pw18-1.8aq.log","w"); |
579 | gFp= fopen("pw18-1.8aq.log","w"); |
566 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
580 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
567 | } |
581 | } |
568 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage, current[ch], cv_cc); |
582 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage[ch], current[ch], cv_cc); |
569 | } |
583 | } |
570 | } |
584 | } |
571 | } |
585 | } |
572 | PlotStripChart (panel, |
586 | PlotStripChart (panel, P1_GRAPH_IMON, current, 4, 0, 0, VAL_DOUBLE); |
- | 587 | PlotStripChart (panel, P1_GRAPH_VMON, voltage, 4, 0, 0, VAL_DOUBLE); |
|
573 | break; |
588 | break; |
574 | } |
589 | } |
575 | return 0; |
590 | return 0; |
576 | } |
591 | } |
- | 592 | ||
- | 593 | int CVICALLBACK SetPresetCB (int panel, int control, int event, |
|
- | 594 | void *callbackData, int eventData1, int eventData2) { |
|
- | 595 | ||
- | 596 | switch (event) { |
|
- | 597 | case EVENT_COMMIT:{ |
|
- | 598 | unsigned char preset; |
|
- | 599 | double Voltage, Current; |
|
- | 600 | GetCtrlVal(panel, control, &preset); |
|
- | 601 | TMI_Preset(TMI_DeviceId, preset); |
|
- | 602 | ||
- | 603 | for (unsigned char ch=0;ch<4;ch++){ |
|
- | 604 | int ison; |
|
- | 605 | TMI_VoltageQ(TMI_DeviceId, ch+1, preset, &Voltage); |
|
- | 606 | TMI_CurrentQ(TMI_DeviceId, ch+1, preset, &Current); |
|
- | 607 | SetCtrlVal(pnl, vset[ch], Voltage); |
|
- | 608 | SetCtrlVal(pnl, iset[ch], Current); |
|
- | 609 | GetCtrlVal(pnl, radiob[ch], &ison); |
|
- | 610 | if (ison) SETREG(gMask,(1<<ch)); else RSTREG(gMask,(1<<ch)); |
|
- | 611 | } |
|
- | 612 | break; |
|
- | 613 | } |
|
- | 614 | } |
|
- | 615 | return 0; |
|
- | 616 | } |
|
- | 617 | ||
- | 618 | ||
577 | #endif MAIN |
619 | #endif MAIN |
578 | 620 |