Rev 256 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 256 | Rev 279 | ||
---|---|---|---|
Line 270... | Line 270... | ||
270 | if (ibsta & ERR) GpibError("OpenDev Error"); |
270 | if (ibsta & ERR) GpibError("OpenDev Error"); |
271 | } |
271 | } |
272 | return; |
272 | return; |
273 | } |
273 | } |
274 | 274 | ||
275 |
|
275 | void _VI_FUNC K617_test (void) |
276 | - | ||
277 | #include <cvirte.h> |
- | |
278 | - | ||
279 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
- | |
280 | LPSTR lpszCmdLine, int nCmdShow) |
- | |
281 | { |
276 | { |
282 | int i; |
277 | int i; |
283 | double value; |
278 | double value; |
284 | char cres[100]; |
279 | char cres[100]; |
285 | 280 | ||
286 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
- | |
287 | - | ||
288 | K617_open (1,5,3,0,13); |
- | |
289 | K617_clear (); |
281 | K617_clear (); |
290 | K617_current_mode (4); |
282 | K617_current_mode (4); |
291 | K617_zero_correct (1); |
283 | K617_zero_correct (1); |
292 | K617_data_format (0); |
284 | K617_data_format (0); |
293 | K617_trigger_mode (1); |
285 | K617_trigger_mode (1); |
Line 298... | Line 290... | ||
298 | 290 | ||
299 | value=K617_get(cres,&i); |
291 | value=K617_get(cres,&i); |
300 | printf("%s, %lg, %d\n",cres,value,i); |
292 | printf("%s, %lg, %d\n",cres,value,i); |
301 | value=K617_vsource_get(); |
293 | value=K617_vsource_get(); |
302 | printf("%lg\n",value); |
294 | printf("%lg\n",value); |
303 | value=K617_get(cres,&i); |
295 | value=K617_get(cres,&i); |
304 | printf("%s, %lg, %d\n",cres,value,i); |
296 | printf("%s, %lg, %d\n",cres,value,i); |
305 | value=K617_get(cres,&i); |
297 | value=K617_get(cres,&i); |
306 | printf("%s, %lg, %d\n",cres,value,i); |
298 | printf("%s, %lg, %d\n",cres,value,i); |
307 | value=K617_get(cres,&i); |
299 | value=K617_get(cres,&i); |
308 | printf("%s, %lg, %d\n",cres,value,i); |
300 | printf("%s, %lg, %d\n",cres,value,i); |
309 | value=K617_get(cres,&i); |
301 | value=K617_get(cres,&i); |
310 | printf("%s, %lg, %d\n",cres,value,i); |
302 | printf("%s, %lg, %d\n",cres,value,i); |
311 | Delay(5); |
303 | Delay(5); |
312 | K617_vsource_operate (0); |
304 | K617_vsource_operate (0); |
313 | 305 | ||
- | 306 | ||
- | 307 | } |
|
- | 308 | ||
- | 309 | #ifdef K617_MAIN |
|
- | 310 | ||
- | 311 | #include <cvirte.h> |
|
- | 312 | #include <userint.h> |
|
- | 313 | #include "K617-ctrl.h" |
|
- | 314 | int pnl; int gLogToFile; |
|
- | 315 | int vmon[4]={P1_VMON_1}; |
|
- | 316 | int imon[4]={P1_IMON_1 }; |
|
- | 317 | int vset[4]={P1_U_1 }; |
|
- | 318 | int iset[4]={P1_I_1 }; |
|
- | 319 | int radiob[4]={P1_BOX_1 }; |
|
- | 320 | ||
- | 321 | int cvcc[4]={P1_CVCC_1 }; |
|
- | 322 | const unsigned char Pre_1 = 1; |
|
- | 323 | int gMask=0xF; |
|
- | 324 | ||
- | 325 | int pnl; |
|
- | 326 | FILE *gFp; |
|
- | 327 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
|
- | 328 | LPSTR lpszCmdLine, int nCmdShow) |
|
- | 329 | { |
|
- | 330 | char cres[100]; |
|
- | 331 | double Voltage, Current, tinterval; |
|
- | 332 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
|
- | 333 | SetStdioPort (CVI_STDIO_WINDOW); |
|
- | 334 | if ((pnl = LoadPanel (0, "K617-ctrl.uir", P1)) < 0) return -1; |
|
- | 335 | ||
- | 336 | K617_open (1,4,3,0,13); |
|
- | 337 | ||
- | 338 | ||
- | 339 | SetCtrlVal(pnl, P1_ONOFF, 0); |
|
- | 340 | GetCtrlVal(pnl, P1_TINTERVAL, &tinterval); |
|
- | 341 | SetCtrlAttribute (pnl, P1_TIMER, ATTR_INTERVAL, tinterval); |
|
- | 342 | ||
- | 343 | for (unsigned char ch=0;ch<1;ch++){ |
|
- | 344 | int ison,i; |
|
- | 345 | Voltage =K617_vsource_get(); |
|
- | 346 | Current =K617_get(cres,&i); |
|
- | 347 | SetCtrlVal(pnl, vset[ch], Voltage); |
|
- | 348 | SetCtrlVal(pnl, iset[ch], Current); |
|
- | 349 | GetCtrlVal(pnl, radiob[ch], &ison); |
|
- | 350 | gMask = ison; |
|
- | 351 | } |
|
- | 352 | ||
- | 353 | DisplayPanel (pnl); |
|
- | 354 | RunUserInterface (); |
|
- | 355 | DiscardPanel (pnl); |
|
314 | K617_close(); |
356 | K617_close(); |
- | 357 | ||
- | 358 | if (gFp) fclose(gFp); |
|
- | 359 | ||
- | 360 | ||
- | 361 | return 0; |
|
- | 362 | } |
|
- | 363 | ||
- | 364 | ||
- | 365 | ||
- | 366 | ||
- | 367 | int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
|
- | 368 | void *callbackData, int eventData1, int eventData2) |
|
- | 369 | { |
|
- | 370 | unsigned char state; |
|
- | 371 | switch (event) |
|
- | 372 | { |
|
- | 373 | case EVENT_COMMIT: |
|
- | 374 | GetCtrlVal(panel, control, &state); |
|
- | 375 | K617_vsource_operate (state); |
|
- | 376 | break; |
|
- | 377 | } |
|
- | 378 | return 0; |
|
- | 379 | } |
|
- | 380 | ||
- | 381 | int CVICALLBACK SetCB (int panel, int control, int event, |
|
- | 382 | void *callbackData, int eventData1, int eventData2) |
|
- | 383 | { |
|
- | 384 | ||
- | 385 | char cres[100]; |
|
- | 386 | int i; |
|
- | 387 | switch (event) |
|
- | 388 | { |
|
- | 389 | case EVENT_COMMIT: |
|
- | 390 | ||
- | 391 | for (unsigned char ch = 0; ch<1;ch++){ |
|
- | 392 | //printf("ch %d %x\n", ch, gMask); |
|
- | 393 | if (gMask){ |
|
- | 394 | double Voltage; |
|
- | 395 | double Current; |
|
- | 396 | GetCtrlVal(panel, vset[ch], &Voltage); |
|
- | 397 | GetCtrlVal(panel, iset[ch], &Current); |
|
- | 398 | printf("->ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
|
- | 399 | ||
- | 400 | K617_vsource_set (Voltage); |
|
- | 401 | Voltage=K617_vsource_get(); |
|
- | 402 | ||
- | 403 | // TMI_Current(TMI_DeviceId, ch+1, Pre_1, Current); |
|
- | 404 | Current=K617_get(cres,&i); |
|
- | 405 | printf("<-ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
|
- | 406 | ||
- | 407 | } |
|
- | 408 | } |
|
- | 409 | break; |
|
- | 410 | } |
|
- | 411 | return 0; |
|
- | 412 | } |
|
- | 413 | ||
- | 414 | int CVICALLBACK ReadCB (int panel, int control, int event, |
|
- | 415 | void *callbackData, int eventData1, int eventData2) |
|
- | 416 | { |
|
- | 417 | ||
- | 418 | int iRet; |
|
- | 419 | char ch=0; |
|
- | 420 | double Voltage; |
|
- | 421 | double Current; |
|
- | 422 | char cv_cc; |
|
- | 423 | char cres[100]; |
|
- | 424 | ||
- | 425 | switch (event) |
|
- | 426 | { |
|
- | 427 | case EVENT_COMMIT: |
|
- | 428 | for (ch = 0; ch<1;ch++){ |
|
- | 429 | if (gMask){ |
|
- | 430 | int ison,i; |
|
- | 431 | Voltage =K617_vsource_get(); |
|
- | 432 | Current =K617_get(cres,&i); |
|
- | 433 | cv_cc = 1; |
|
- | 434 | printf("ch %d VSet %g Iset %g\n", ch, Voltage, Current); |
|
- | 435 | SetCtrlVal(panel, vmon[ch], Voltage); |
|
- | 436 | SetCtrlVal(panel, imon[ch], Current); |
|
- | 437 | SetCtrlVal(panel, cvcc[ch], cv_cc); |
|
- | 438 | } |
|
- | 439 | } |
|
- | 440 | break; |
|
- | 441 | } |
|
- | 442 | return 0; |
|
- | 443 | } |
|
315 | 444 | ||
- | 445 | int CVICALLBACK SetIntervalCB (int panel, int control, int event, |
|
- | 446 | void *callbackData, int eventData1, int eventData2) { |
|
- | 447 | double tinterval; |
|
- | 448 | switch (event) { |
|
- | 449 | case EVENT_COMMIT: |
|
- | 450 | GetCtrlVal(panel, control, &tinterval); |
|
- | 451 | SetCtrlAttribute (panel, P1_TIMER, ATTR_INTERVAL, tinterval); |
|
- | 452 | break; |
|
- | 453 | } |
|
- | 454 | return 0; |
|
- | 455 | } |
|
- | 456 | ||
- | 457 | int CVICALLBACK TimerOnOffCB (int panel, int control, int event, |
|
- | 458 | void *callbackData, int eventData1, int eventData2) |
|
- | 459 | { |
|
- | 460 | int state; |
|
- | 461 | switch (event) |
|
- | 462 | { |
|
- | 463 | case EVENT_COMMIT: |
|
- | 464 | GetCtrlVal(panel, control, &state); |
|
- | 465 | if (state){ |
|
- | 466 | ResumeTimerCallbacks(); |
|
- | 467 | } else { |
|
- | 468 | SuspendTimerCallbacks (); |
|
- | 469 | printf ("Disabling timer....\n"); |
|
- | 470 | } |
|
- | 471 | break; |
|
- | 472 | } |
|
- | 473 | return 0; |
|
- | 474 | } |
|
- | 475 | ||
- | 476 | int CVICALLBACK ExitCB (int panel, int control, int event, |
|
- | 477 | void *callbackData, int eventData1, int eventData2) |
|
- | 478 | { |
|
- | 479 | switch (event) |
|
- | 480 | { |
|
- | 481 | case EVENT_COMMIT: |
|
- | 482 | QuitUserInterface(0); |
|
- | 483 | break; |
|
- | 484 | } |
|
- | 485 | return 0; |
|
- | 486 | } |
|
- | 487 | ||
- | 488 | int CVICALLBACK SetMaskCB (int panel, int control, int event, |
|
- | 489 | void *callbackData, int eventData1, int eventData2) |
|
- | 490 | { int ison; |
|
- | 491 | switch (event) |
|
- | 492 | { |
|
- | 493 | case EVENT_COMMIT: |
|
- | 494 | GetCtrlVal(panel, control, &ison); |
|
- | 495 | for (int i=0;i<1;i++) if (control == radiob[i]) break; |
|
- | 496 | gMask = ison; |
|
- | 497 | break; |
|
- | 498 | } |
|
- | 499 | return 0; |
|
- | 500 | } |
|
- | 501 | ||
- | 502 | ||
- | 503 | int CVICALLBACK LogToFileCB (int panel, int control, int event, |
|
- | 504 | void *callbackData, int eventData1, int eventData2) |
|
- | 505 | { |
|
- | 506 | ||
- | 507 | switch (event) |
|
- | 508 | { |
|
- | 509 | case EVENT_COMMIT: |
|
- | 510 | GetCtrlVal(panel, control, &gLogToFile); |
|
- | 511 | ||
- | 512 | break; |
|
- | 513 | } |
|
- | 514 | return 0; |
|
- | 515 | } |
|
- | 516 | ||
- | 517 | int CVICALLBACK TimerCB (int panel, int control, int event, |
|
- | 518 | void *callbackData, int eventData1, int eventData2) |
|
- | 519 | { |
|
- | 520 | switch (event) |
|
- | 521 | { |
|
- | 522 | ||
- | 523 | unsigned char ch; |
|
- | 524 | double current[4]; |
|
- | 525 | double voltage; |
|
- | 526 | char cv_cc = 0; |
|
- | 527 | char cres[100]; |
|
- | 528 | int i=0; |
|
- | 529 | case EVENT_TIMER_TICK: |
|
- | 530 | for (ch = 0; ch<1;ch++){ |
|
- | 531 | if (gMask){ |
|
- | 532 | voltage =K617_vsource_get(); |
|
- | 533 | current[ch] =K617_get(cres,&i); |
|
- | 534 | ||
- | 535 | if (gLogToFile){ |
|
- | 536 | if (!gFp) { |
|
- | 537 | gFp= fopen("K617.log","w"); |
|
- | 538 | fprintf(gFp,"#time\tch\tU\tI\tCV_CC\n"); |
|
- | 539 | } |
|
- | 540 | fprintf(gFp,"%ul\t%d\t%g\t%g\t%d\n", time(NULL), ch+1, voltage, current[ch], cv_cc); |
|
- | 541 | } |
|
- | 542 | } |
|
- | 543 | } |
|
- | 544 | PlotStripChart (panel, P1_GRAPH, current, 1, 0, 0, VAL_DOUBLE); |
|
- | 545 | PlotStripChart (panel, P1_GRAPH_1, &voltage, 1, 0, 0, VAL_DOUBLE); |
|
- | 546 | break; |
|
- | 547 | } |
|
316 | return 0; |
548 | return 0; |
317 | } |
549 | } |
318 | 550 | ||
- | 551 | int CVICALLBACK TestCB (int panel, int control, int event, |
|
- | 552 | void *callbackData, int eventData1, int eventData2) { |
|
- | 553 | switch (event) { |
|
- | 554 | case EVENT_COMMIT: |
|
- | 555 | K617_test(); |
|
- | 556 | break; |
|
- | 557 | } |
|
- | 558 | return 0; |
|
- | 559 | } |
|
- | 560 | ||
319 | #endif |
561 | #endif |
- | 562 |