Rev 354 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 354 | Rev 356 | ||
---|---|---|---|
Line 11... | Line 11... | ||
11 | #include <math.h> |
11 | #include <math.h> |
12 | 12 | ||
13 | //stepping motor busheng --> declaration 1step=1.8degrees |
13 | //stepping motor busheng --> declaration 1step=1.8degrees |
14 | //experimantally: full rotation = 3200 steps (on setting 1step/mm ($100)) |
14 | //experimantally: full rotation = 3200 steps (on setting 1step/mm ($100)) |
15 | 15 | ||
16 | 16 | // PORTS |
|
17 | int pCOM1 = 6; |
17 | int pCOM1 = 6; |
18 | int pCOM2 = 7; |
18 | int pCOM2 = 7; |
- | 19 | char GRBL[10] = "COM8"; //BE CAREFUL, IT'S IMPORTANT TO KNOW THE NAME OF THE PORTS |
|
- | 20 | char ADC[10] = "COM7"; |
|
19 | 21 | ||
20 | int run, graph, |
22 | int run, graph, chart, ji, vi, run1; |
21 | int left_1, right_1; |
23 | int left_1, right_1; |
22 | 24 | ||
23 | static int panel, tfID, tfID1; |
25 | static int panel, tfID, tfID1; |
24 | static int poolHandle = 0; |
26 | static int poolHandle = 0; |
25 | 27 | ||
Line 36... | Line 38... | ||
36 | 38 | ||
37 | 39 | ||
38 | void initialize() |
40 | void initialize() |
39 | { |
41 | { |
40 | // Open grbl serial port //("COM6",115200) |
42 | // Open grbl serial port //("COM6",115200) |
41 | OpenComConfig (pCOM1, |
43 | OpenComConfig (pCOM1, GRBL, 115200, 0, 8, 1, 512, 512); |
42 | 44 | ||
43 | /* Turn off Hardware handshaking (loopback test will not function with it on) */ |
45 | /* Turn off Hardware handshaking (loopback test will not function with it on) */ |
44 | SetCTSMode (pCOM1, LWRS_HWHANDSHAKE_OFF); |
46 | SetCTSMode (pCOM1, LWRS_HWHANDSHAKE_OFF); |
45 | 47 | ||
46 | ComWrt (pCOM1, "\r\n\r\n", 5); //Writing on Port |
48 | ComWrt (pCOM1, "\r\n\r\n", 5); //Writing on Port |
Line 119... | Line 121... | ||
119 | } |
121 | } |
120 | 122 | ||
121 | 123 | ||
122 | void initialize_voltage() |
124 | void initialize_voltage() |
123 | { |
125 | { |
124 | // Open serial port for photodetector - reading is on chanel A1 |
126 | // Open serial port for ADC & photodetector - reading is on chanel A1 |
125 | OpenComConfig (pCOM2, |
127 | OpenComConfig (pCOM2, ADC, 115200, 0, 8, 1, 512, 512); |
126 | SetCTSMode (pCOM2, LWRS_HWHANDSHAKE_OFF); |
128 | SetCTSMode (pCOM2, LWRS_HWHANDSHAKE_OFF); |
127 | 129 | ||
128 | Delay(0.5); |
130 | Delay(0.5); |
129 | FlushInQ (pCOM2); |
131 | FlushInQ (pCOM2); |
130 | FlushOutQ (pCOM2); |
132 | FlushOutQ (pCOM2); |
Line 173... | Line 175... | ||
173 | 175 | ||
174 | int strLen3 = GetInQLen (pCOM1); |
176 | int strLen3 = GetInQLen (pCOM1); |
175 | bytes_read3 = ComRd (pCOM1, read_data3, strLen3); |
177 | bytes_read3 = ComRd (pCOM1, read_data3, strLen3); |
176 | //printf(" :\n%s", read_data3); |
178 | //printf(" :\n%s", read_data3); |
177 | //printf("bytes_read = %d\n\n", bytes_read3); |
179 | //printf("bytes_read = %d\n\n", bytes_read3); |
178 | FlushInQ (pCOM1); |
180 | FlushInQ (pCOM1); |
179 | 181 | ||
180 | } |
182 | } |
181 | 183 | ||
182 | 184 | ||
183 | static int CVICALLBACK daq_run(void *functionData) |
185 | static int CVICALLBACK daq_run(void *functionData) |
184 | { |
186 | { |
185 | 187 | ||
Line 293... | Line 295... | ||
293 | //for(int i=0;i<j;i++) printf("volt_g[%d] = %lf\n",i,volt_g[i]); |
295 | //for(int i=0;i<j;i++) printf("volt_g[%d] = %lf\n",i,volt_g[i]); |
294 | if (graph>0) DeleteGraphPlot (panel, p1_VOLTAGE_GRAPH, graph, VAL_DELAYED_DRAW); |
296 | if (graph>0) DeleteGraphPlot (panel, p1_VOLTAGE_GRAPH, graph, VAL_DELAYED_DRAW); |
295 | graph = PlotY (panel, p1_VOLTAGE_GRAPH, &volt_g[0], num_points, VAL_DOUBLE, |
297 | graph = PlotY (panel, p1_VOLTAGE_GRAPH, &volt_g[0], num_points, VAL_DOUBLE, |
296 | VAL_CONNECTED_POINTS, VAL_SIMPLE_DOT, VAL_SOLID, 1, VAL_WHITE); |
298 | VAL_CONNECTED_POINTS, VAL_SIMPLE_DOT, VAL_SOLID, 1, VAL_WHITE); |
297 | ji = num_points; |
299 | ji = num_points; |
298 | f_t = 1; |
- | |
299 | } |
300 | } |
300 | 301 | ||
301 | FlushInQ (pCOM1); |
302 | FlushInQ (pCOM1); |
302 | FlushOutQ (pCOM1); |
303 | FlushOutQ (pCOM1); |
303 | FlushInQ (pCOM2); |
304 | FlushInQ (pCOM2); |
Line 308... | Line 309... | ||
308 | } |
309 | } |
309 | 310 | ||
310 | 311 | ||
311 | static int CVICALLBACK voltage_run(void *functionData) |
312 | static int CVICALLBACK voltage_run(void *functionData) |
312 | { |
313 | { |
313 | int fix_range; |
- | |
314 | double ymin,ymax,xmin,xmax; |
- | |
315 | double voltA |
314 | double voltA; |
316 | int time = 0; |
- | |
317 | //double volt1[TEXT_LENGTH]; |
- | |
318 | 315 | ||
319 | initialize_voltage(); |
316 | initialize_voltage(); |
320 | 317 | ||
321 |
|
318 | chart = NewCtrl (panel, CTRL_STRIP_CHART_LS, "RUN VOLTAGE", 100, 15); |
322 | SetCtrlAttribute(panel, chart, ATTR_HEIGHT, 600); |
319 | SetCtrlAttribute(panel, chart, ATTR_HEIGHT, 600); |
323 | SetCtrlAttribute(panel, chart, ATTR_WIDTH , 1300); |
320 | SetCtrlAttribute(panel, chart, ATTR_WIDTH , 1300); |
- | 321 | SetAxisRange(panel, chart, VAL_NO_CHANGE, 0, 0, VAL_AUTOSCALE, 0, 0); |
|
324 | 322 | ||
325 | while(1) |
323 | while(1) |
326 | { |
324 | { |
327 | // Range |
- | |
328 | GetCtrlVal(panel, p1_RANGE, &fix_range); |
- | |
329 | if(fix_range) |
- | |
330 | { |
- | |
331 | GetAxisRange (panel, chart, VAL_MANUAL, &xmin, &xmax, VAL_MANUAL, &ymin, &ymax); |
- | |
332 | if (ymax<=2) SetAxisRange (panel, chart, VAL_NO_CHANGE, 0, 0, VAL_MANUAL, 0, 2); |
- | |
333 | else SetAxisRange (panel, chart, VAL_NO_CHANGE, 0, 0, VAL_MANUAL, 0, 5); |
- | |
334 | } |
- | |
335 | else SetAxisRange (panel, chart, VAL_NO_CHANGE, 0, 0, VAL_AUTOSCALE, 0, 0); |
- | |
336 | - | ||
337 | //volt1[time] = read_voltage(); |
- | |
338 | voltA = read_voltage(); |
325 | voltA = read_voltage(); |
339 | - | ||
340 | PlotPoint(panel, chart, time, voltA, VAL_SOLID_SQUARE, VAL_WHITE); |
- | |
341 |
|
326 | PlotStripChartPoint (panel, chart, voltA); |
342 | if (time>50) SetAxisRange (panel, chart, VAL_MANUAL, time-50, time, VAL_NO_CHANGE, 0, 0); |
- | |
343 | 327 | ||
344 | SetCtrlVal(panel, p1_VOLTAGE, voltA); |
328 | SetCtrlVal(panel, p1_VOLTAGE, voltA); |
345 | 329 | ||
346 | Delay(0.05); |
330 | Delay(0.05); |
347 | time++; |
- | |
348 | - | ||
349 | voltB = voltA; |
- | |
350 | - | ||
351 | //volt1[time] = voltA; |
- | |
352 | 331 | ||
353 | FlushInQ (pCOM2); |
332 | FlushInQ (pCOM2); |
354 | 333 | ||
355 | if (vi == 0) break; |
334 | if (vi == 0) break; |
356 | } |
335 | } |
357 | 336 | ||
358 | DiscardCtrl (panel, chart); |
337 | DiscardCtrl (panel, chart); |
359 | - | ||
360 | // After some time (~4000 points) it becomes slower in writing out data... |
- | |
361 | 338 | chart = 0; |
|
362 | //if (graph!=0) DeleteGraphPlot (panel, p1_VOLTAGE_GRAPH, graph, VAL_DELAYED_DRAW); |
- | |
363 | //graph = PlotY (panel, p1_VOLTAGE_GRAPH, &volt1[0], time+1, VAL_DOUBLE, |
- | |
364 | // VAL_CONNECTED_POINTS, VAL_SIMPLE_DOT, VAL_SOLID, 1, VAL_WHITE); |
- | |
365 | 339 | ||
366 | return 0; |
340 | return 0; |
367 | } |
341 | } |
368 | 342 | ||
369 | 343 | ||
370 | static int CVICALLBACK free_run(void *functionData) |
344 | static int CVICALLBACK free_run(void *functionData) |
371 | { |
345 | { |
372 | if (run == 1) return 0; |
346 | if (run == 1) return 0; |
373 | run1 = 1; |
347 | run1 = 1; |
374 | 348 | ||
375 | if (left_1) movement(-10000); |
349 | if (left_1) movement(-10000); |
376 | if (right_1) movement(10000); |
350 | if (right_1) movement(10000); |
Line 392... | Line 366... | ||
392 | 366 | ||
393 | int strLen = GetInQLen (pCOM1); |
367 | int strLen = GetInQLen (pCOM1); |
394 | bytes_read0 = ComRd (pCOM1, read_data0, strLen); |
368 | bytes_read0 = ComRd (pCOM1, read_data0, strLen); |
395 | //printf(" : %s", read_data0); |
369 | //printf(" : %s", read_data0); |
396 | 370 | ||
397 |
|
371 | //printf("Stop run1\n"); |
398 | 372 | ||
399 | break; |
373 | break; |
400 | } |
374 | } |
401 | } |
375 | } |
402 | 376 | ||
403 | return 0; |
377 | return 0; |
404 | } |
378 | } |
405 | 379 | ||
406 | 380 | ||
Line 436... | Line 410... | ||
436 | if (run == 1) break; |
410 | if (run == 1) break; |
437 | 411 | ||
438 | run = 1; |
412 | run = 1; |
439 | 413 | ||
440 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID); |
414 | CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID); |
441 | 415 | ||
442 | } |
416 | } |
443 | 417 | ||
444 | return 0; |
418 | return 0; |
445 | } |
419 | } |
446 | 420 | ||
447 | 421 | ||
448 | int CVICALLBACK StopCB (int panel, int control, int event, |
422 | int CVICALLBACK StopCB (int panel, int control, int event, |
449 | void *callbackData, int eventData1, int eventData2) |
423 | void *callbackData, int eventData1, int eventData2) |
450 | { |
424 | { |
451 | switch (event) |
425 | switch (event) |
452 | { |
426 | { |
453 | case EVENT_COMMIT: |
427 | case EVENT_COMMIT: |
454 | 428 | ||
455 | if (run == 0) break; |
429 | if (run == 0) break; |
Line 459... | Line 433... | ||
459 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, |
433 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, |
460 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
434 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
461 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID); |
435 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID); |
462 | 436 | ||
463 | printf("Stop\n"); |
437 | printf("Stop\n"); |
464 | 438 | ||
465 | break; |
439 | break; |
466 | 440 | ||
467 | } |
441 | } |
468 | 442 | ||
469 | return 0; |
443 | return 0; |
470 | } |
444 | } |
471 | 445 | ||
472 | 446 | ||
473 | int CVICALLBACK ExitCB (int panel, int control, int event, |
447 | int CVICALLBACK ExitCB (int panel, int control, int event, |
474 | void *callbackData, int eventData1, int eventData2) |
448 | void *callbackData, int eventData1, int eventData2) |
475 | { |
449 | { |
476 | switch (event) |
450 | switch (event) |
477 | { |
451 | { |
478 | case EVENT_COMMIT: |
452 | case EVENT_COMMIT: |
479 | QuitUserInterface (0); |
453 | QuitUserInterface (0); |
480 | CloseCom(pCOM1); |
454 | CloseCom(pCOM1); |
481 | CloseCom(pCOM2); |
455 | CloseCom(pCOM2); |
482 | break; |
456 | break; |
483 | } |
457 | } |
484 | return 0; |
458 | return 0; |
485 | } |
459 | } |
486 | 460 | ||
487 | 461 | ||
488 | int CVICALLBACK Fourier_TransCB (int panel, int control, int event, |
462 | int CVICALLBACK Fourier_TransCB (int panel, int control, int event, |
489 | void *callbackData, int eventData1, int eventData2) |
463 | void *callbackData, int eventData1, int eventData2) |
490 | { |
464 | { |
491 | if (!ji) return 0; |
465 | if (!ji) return 0; |
492 | const int ii = ji; |
466 | const int ii = ji; |
493 | double fourier_t[ii], fourier_ti[ii]; |
467 | double fourier_t[ii], fourier_ti[ii]; |
494 | char window_fun; |
468 | char window_fun; |
- | 469 | double voltmax=0, voltmin=5, voltavg; |
|
495 | 470 | ||
496 | switch (event) |
471 | switch (event) |
497 | { |
472 | { |
498 | case EVENT_COMMIT: |
473 | case EVENT_COMMIT: |
499 | 474 | ||
500 | for(int i=0; i<ii; i++) |
475 | for(int i=0; i<ii; i++) |
501 | { |
476 | { |
502 | fourier_t[i] = volt_g[i]; |
477 | fourier_t[i] = volt_g[i]; |
503 | fourier_ti[i] = 0; |
478 | fourier_ti[i] = 0; |
- | 479 | ||
- | 480 | if (fourier_t[i]>voltmax) voltmax = fourier_t[i]; |
|
- | 481 | if (fourier_t[i]<voltmin) voltmin = fourier_t[i]; |
|
504 | } |
482 | } |
505 | 483 | ||
- | 484 | voltavg = (voltmin+voltmax)/2.0; |
|
506 | GetCtrlVal(panel, p1_WIN_FUN, &window_fun); |
485 | GetCtrlVal(panel, p1_WIN_FUN, &window_fun); |
507 | //printf("window_fun = %d\n", window_fun); |
486 | //printf("window_fun = %d\n", window_fun); |
- | 487 | //printf("max %f, min %f, avg %f\n", voltmax, voltmin, voltavg); |
|
508 | if (window_fun!=0) |
488 | if (window_fun!=0) |
509 | { |
489 | { |
510 | //do something with window functions |
490 | //do something with window functions (N=ii) |
511 | if(window_fun==1) for(int i=0; i<ii; i++) fourier_t[i] = ( |
491 | if(window_fun==1) for(int i=0; i<ii; i++) fourier_t[i] = (fourier_t[i] - voltavg)*(1 - fabs((i-(ii/2.0))/(ii/2))) + voltavg; //Bartlett |
- | 492 | if(window_fun==2) for(int i=0; i<ii; i++) fourier_t[i] = (fourier_t[i] - voltavg)*(1 - ((i-(ii/2.0))/(ii/2))*((i-(ii/2.0))/(ii/2))) + voltavg; //Welch |
|
512 | if(window_fun== |
493 | if(window_fun==3) for(int i=0; i<ii; i++) fourier_t[i] = (fourier_t[i] - voltavg)*(0.5*(1 - cos(2*3.14159265359*i/ii))) + voltavg; //Hann |
513 | YGraphPopup ("HOW |
494 | YGraphPopup ("HOW voltage LOOKS NOW", fourier_t, ii, VAL_DOUBLE); |
514 | } |
495 | } |
515 | 496 | ||
516 | FFT (fourier_t, fourier_ti, ii); |
497 | FFT (fourier_t, fourier_ti, ii); |
517 | for (int i=0; i<ii; i++) fourier_t[i] = fabs(fourier_t[i]); |
498 | for (int i=0; i<ii; i++) fourier_t[i] = fabs(fourier_t[i]); |
518 | fourier_t[0]=0; |
499 | fourier_t[0]=0; |
519 | 500 | ||
520 | YGraphPopup ("FOURIER", fourier_t, ii/2+1, VAL_DOUBLE); |
501 | YGraphPopup ("FOURIER", fourier_t, ii/2+1, VAL_DOUBLE); |
- | 502 | ||
- | 503 | ||
- | 504 | FILE *fp,*fp1; |
|
- | 505 | ||
- | 506 | //file name has to have file extension |
|
- | 507 | char fname[50]; |
|
- | 508 | GetCtrlVal(panel, p1_F_NAME, fname); |
|
- | 509 | ||
- | 510 | char fname0[100] = "C:/Users/"; |
|
- | 511 | char *name; |
|
- | 512 | name = getenv("USERNAME"); |
|
- | 513 | strcat(fname0,name); |
|
- | 514 | strcat(fname0,"/Desktop/"); |
|
- | 515 | //char fname0[100] = "C:/Users/Student/Desktop/"; //Alternative way |
|
- | 516 | strcat(fname0,fname); |
|
- | 517 | fp = fopen(fname0, "w"); |
|
- | 518 | ||
- | 519 | char fname1[50]; |
|
- | 520 | GetCtrlVal(panel, p1_F_NAME1, fname1); |
|
- | 521 | char fname10[100] = "C:/Users/"; |
|
- | 522 | strcat(fname10,name); |
|
- | 523 | strcat(fname10,"/Desktop/"); |
|
- | 524 | strcat(fname10,fname1); |
|
- | 525 | fp1 = fopen(fname10, "w"); |
|
- | 526 | ||
- | 527 | fprintf(fp, "step\tvoltage\n"); |
|
- | 528 | for(int i=0; i<ii; i++) |
|
- | 529 | { |
|
- | 530 | fprintf(fp, "%d\t%lf\n", i+1, volt_g[i]); |
|
- | 531 | } |
|
- | 532 | ||
- | 533 | fprintf(fp1, "step\tfourier\n"); |
|
- | 534 | for(int i=0; i<ii/2+1; i++) |
|
- | 535 | { |
|
- | 536 | fprintf(fp1, "%d\t%lf\n", i, fourier_t[i]); //0th component is from DC - background? YES |
|
- | 537 | } |
|
- | 538 | ||
- | 539 | fclose(fp); |
|
- | 540 | fclose(fp1); |
|
- | 541 | printf("Files %s and %s created.\n", fname, fname1); |
|
521 | 542 | ||
522 | if (f_t == 1) |
- | |
523 | { |
- | |
524 | FILE *fp,*fp1; |
- | |
525 | - | ||
526 | //file name has to have file extension |
- | |
527 | char fname[50]; |
- | |
528 | GetCtrlVal(panel, p1_F_NAME, fname); |
- | |
529 | fp = fopen(fname, "w"); |
- | |
530 | - | ||
531 | char fname1[50]; |
- | |
532 | GetCtrlVal(panel, p1_F_NAME1, fname1); |
- | |
533 | fp1 = fopen(fname1, "w"); |
- | |
534 | - | ||
535 | fprintf(fp, "step\tvolt_g\n"); |
- | |
536 | for(int i=0; i<ii; i++) |
- | |
537 | { |
- | |
538 | fprintf(fp, "%d\t%lf\n", i+1, volt_g[i]); |
- | |
539 | } |
- | |
540 | - | ||
541 | fprintf(fp1, "step\tfourier_t\n"); |
- | |
542 | for(int i=0; i<ii/2+1; i++) |
- | |
543 | { |
- | |
544 | fprintf(fp1, "%d\t%lf\n", i, fourier_t[i]); //0th component is from DC - background? |
- | |
545 | } |
- | |
546 | - | ||
547 | fclose(fp); |
- | |
548 | fclose(fp1); |
- | |
549 | printf("Files %s and %s created.\n", fname, fname1); |
- | |
550 | } |
- | |
551 | - | ||
552 | f_t = 0; //so that we make only one file |
- | |
553 | break; |
543 | break; |
554 | 544 | ||
555 | } |
545 | } |
556 | 546 | ||
557 | return 0; |
547 | return 0; |
558 | } |
548 | } |
559 | 549 | ||
560 | 550 | ||
561 | int CVICALLBACK ExamplesCB (int panel, int control, int event, |
551 | int CVICALLBACK ExamplesCB (int panel, int control, int event, |
562 | void *callbackData, int eventData1, int eventData2) |
552 | void *callbackData, int eventData1, int eventData2) |
563 | { |
553 | { |
564 | const int ki=1024; |
554 | const int ki=1024; |
565 | double ret[ki], ret1[ki]; |
555 | double ret[ki], ret1[ki]; |
566 | double val = 3.14159265/180; |
556 | double val = 3.14159265/180; |
567 | int x1, x2, a1, a2; |
557 | int x1, x2, a1, a2; |
- | 558 | char window_fun; |
|
568 | 559 | ||
569 | switch (event) |
560 | switch (event) |
570 | { |
561 | { |
571 | case EVENT_COMMIT: |
562 | case EVENT_COMMIT: |
572 | 563 | ||
573 | GetCtrlVal(panel, p1_FREQ1, &x1); |
564 | GetCtrlVal(panel, p1_FREQ1, &x1); |
574 | GetCtrlVal(panel, p1_FREQ2, &x2); |
565 | GetCtrlVal(panel, p1_FREQ2, &x2); |
575 | GetCtrlVal(panel, p1_AMPL1, &a1); |
566 | GetCtrlVal(panel, p1_AMPL1, &a1); |
576 | GetCtrlVal(panel, p1_AMPL2, &a2); |
567 | GetCtrlVal(panel, p1_AMPL2, &a2); |
577 | 568 | ||
- | 569 | GetCtrlVal(panel, p1_WIN_FUN, &window_fun); |
|
- | 570 | //printf("window_fun = %d\n", window_fun); |
|
- | 571 | ||
578 | for (int i=0; i<ki; i++) |
572 | for (int i=0; i<ki; i++) |
579 | { |
573 | { |
580 | ret[i] = a1*sin(x1*i*val)+a2*sin(x2*i*val); |
574 | ret[i] = a1*sin(x1*i*val)+a2*sin(x2*i*val); |
581 | ret1[i] = 0; |
575 | ret1[i] = 0; |
- | 576 | } |
|
- | 577 | if (window_fun!=0) |
|
- | 578 | { |
|
- | 579 | //do something with window functions (N=ki) |
|
- | 580 | if(window_fun==1) for(int i=0; i<ki; i++) ret[i] = ret[i]*(1 - fabs((i-(ki/2.0))/(ki/2))); //Bartlett |
|
- | 581 | if(window_fun==2) for(int i=0; i<ki; i++) ret[i] = ret[i]*(1 - ((i-(ki/2.0))/(ki/2))*((i-(ki/2.0))/(ki/2))); //Welch |
|
- | 582 | if(window_fun==3) for(int i=0; i<ki; i++) ret[i] = ret[i]*(0.5*(1 - cos(2*3.14159265359*i/ki))); //Hann |
|
582 | } |
583 | } |
583 | YGraphPopup ("example graph", ret, ki, VAL_DOUBLE); |
584 | YGraphPopup ("example graph", ret, ki, VAL_DOUBLE); |
584 | FFT (ret, ret1, ki); |
585 | FFT (ret, ret1, ki); |
585 | for (int i=0; i<ki; i++) ret[i] = fabs(ret[i]); |
586 | for (int i=0; i<ki; i++) ret[i] = fabs(ret[i]); |
586 | //for (int i=0;i<ki;i++) printf("basic: %lf, fourier: %lf\n", ret1[i], ret[i]); |
587 | //for (int i=0;i<ki;i++) printf("basic: %lf, fourier: %lf\n", ret1[i], ret[i]); |
Line 632... | Line 633... | ||
632 | switch (event) |
633 | switch (event) |
633 | { |
634 | { |
634 | case EVENT_COMMIT: |
635 | case EVENT_COMMIT: |
635 | 636 | ||
636 | GetCtrlVal(panel, p1_RANGE, &fix_range); |
637 | GetCtrlVal(panel, p1_RANGE, &fix_range); |
- | 638 | ||
- | 639 | if(chart) |
|
- | 640 | { |
|
- | 641 | if(fix_range) |
|
- | 642 | { |
|
- | 643 | GetAxisRange (panel, chart, VAL_MANUAL, &xmin, &xmax, VAL_MANUAL, &ymin, &ymax); |
|
- | 644 | if (ymax<=2) SetAxisRange (panel, chart, VAL_NO_CHANGE, 0, 0, VAL_MANUAL, 0, 2); |
|
- | 645 | else SetAxisRange (panel, chart, VAL_NO_CHANGE, 0, 0, VAL_MANUAL, 0, 5); |
|
- | 646 | } |
|
- | 647 | else SetAxisRange(panel, chart, VAL_NO_CHANGE, 0, 0, VAL_AUTOSCALE, 0, 0); |
|
- | 648 | } |
|
- | 649 | ||
637 | if(fix_range) |
650 | if(fix_range) |
638 | { |
651 | { |
639 | GetAxisRange (panel, p1_VOLTAGE_GRAPH, VAL_MANUAL, &xmin, &xmax, VAL_MANUAL, &ymin, &ymax); |
652 | GetAxisRange (panel, p1_VOLTAGE_GRAPH, VAL_MANUAL, &xmin, &xmax, VAL_MANUAL, &ymin, &ymax); |
640 | if (ymax<=2) SetAxisRange (panel, p1_VOLTAGE_GRAPH, VAL_NO_CHANGE, 0, 0, VAL_MANUAL, 0, 2); |
653 | if (ymax<=2) SetAxisRange (panel, p1_VOLTAGE_GRAPH, VAL_NO_CHANGE, 0, 0, VAL_MANUAL, 0, 2); |
641 | else SetAxisRange (panel, p1_VOLTAGE_GRAPH, VAL_NO_CHANGE, 0, 0, VAL_MANUAL, 0, 5); |
654 | else SetAxisRange (panel, p1_VOLTAGE_GRAPH, VAL_NO_CHANGE, 0, 0, VAL_MANUAL, 0, 5); |
642 | } |
655 | } |
643 | else SetAxisRange (panel, p1_VOLTAGE_GRAPH, VAL_NO_CHANGE, 0, 0, VAL_AUTOSCALE, 0, 0); |
656 | else SetAxisRange (panel, p1_VOLTAGE_GRAPH, VAL_NO_CHANGE, 0, 0, VAL_AUTOSCALE, 0, 0); |
644 | 657 | ||
645 | break; |
658 | break; |
646 | 659 | ||
647 | } |
660 | } |
648 | 661 | ||
649 | return 0; |
662 | return 0; |
650 | } |
663 | } |
651 | 664 | ||
652 | 665 | ||
653 | int CVICALLBACK FreeMoveCB (int panel, int control, int event, |
666 | int CVICALLBACK FreeMoveCB (int panel, int control, int event, |
654 | void *callbackData, int eventData1, int eventData2) |
667 | void *callbackData, int eventData1, int eventData2) |
655 | { |
668 | { |
656 | int dummy; |
669 | int dummy; |
657 | - | ||
658 | switch (event) |
- | |
659 | { |
- | |
660 | case EVENT_COMMIT: |
- | |
661 | - | ||
662 | if (run == 1) break; |
- | |
663 | if (run1 == 1) break; |
- | |
664 | right_1 = 1; |
- | |
665 | - | ||
666 | CmtScheduleThreadPoolFunction (poolHandle, free_run, (void *)&dummy, &tfID1); |
- | |
667 | 670 | ||
- | 671 | switch (event) |
|
- | 672 | { |
|
- | 673 | case EVENT_COMMIT: |
|
- | 674 | ||
- | 675 | if (run == 1) break; |
|
- | 676 | if (run1 == 1) break; |
|
- | 677 | right_1 = 1; |
|
- | 678 | ||
- | 679 | CmtScheduleThreadPoolFunction (poolHandle, free_run, (void *)&dummy, &tfID1); |
|
- | 680 | ||
668 | break; |
681 | break; |
669 | 682 | ||
670 | } |
683 | } |
671 | 684 | ||
672 | return 0; |
685 | return 0; |
673 | } |
686 | } |
674 | 687 | ||
675 | int CVICALLBACK FreeMove1CB (int panel, int control, int event, |
688 | int CVICALLBACK FreeMove1CB (int panel, int control, int event, |
676 | void *callbackData, int eventData1, int eventData2) |
689 | void *callbackData, int eventData1, int eventData2) |
677 | { |
690 | { |
678 | int dummy; |
691 | int dummy; |
679 | 692 | ||
680 | switch (event) |
693 | switch (event) |
681 | { |
694 | { |
682 | case EVENT_COMMIT: |
695 | case EVENT_COMMIT: |
683 | 696 | ||
684 | if (run == 1) break; |
697 | if (run == 1) break; |
685 | if (run1 == 1) break; |
698 | if (run1 == 1) break; |
686 | left_1 = 1; |
699 | left_1 = 1; |
687 | 700 | ||
688 | CmtScheduleThreadPoolFunction (poolHandle, free_run, (void *)&dummy, &tfID1); |
701 | CmtScheduleThreadPoolFunction (poolHandle, free_run, (void *)&dummy, &tfID1); |
689 | 702 | ||
690 | break; |
703 | break; |
691 | 704 | ||
692 | } |
705 | } |
693 | 706 | ||
694 | return 0; |
707 | return 0; |
Line 702... | Line 715... | ||
702 | case EVENT_COMMIT: |
715 | case EVENT_COMMIT: |
703 | 716 | ||
704 | if (run == 1) break; |
717 | if (run == 1) break; |
705 | if (run1 == 0) break; |
718 | if (run1 == 0) break; |
706 | run1 = 0; |
719 | run1 = 0; |
- | 720 | ||
- | 721 | if (run1 == 0) //Additionally here just to be sure |
|
- | 722 | { |
|
- | 723 | ComWrt (pCOM1, "!\n", 2); //stops grbl |
|
- | 724 | ||
- | 725 | Delay(0.01); |
|
- | 726 | ||
- | 727 | ComWrt (pCOM1, "~\n", 2); //releases grbl |
|
- | 728 | ||
- | 729 | Delay(0.01); |
|
- | 730 | ||
- | 731 | int strLen = GetInQLen (pCOM1); |
|
- | 732 | bytes_read0 = ComRd (pCOM1, read_data0, strLen); |
|
- | 733 | //printf(" : %s", read_data0); |
|
- | 734 | ||
- | 735 | printf("Stop run1\n"); |
|
- | 736 | } |
|
707 | 737 | ||
708 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID1, |
738 | CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID1, |
709 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
739 | OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
710 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID1); |
740 | CmtReleaseThreadPoolFunctionID (poolHandle, tfID1); |
711 | 741 |