aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection/stubs/Scripts/Jig_Tester/JIG_TESTER1.cs
blob: c484fc39fc1e86007fea3ff7b1b6220b557a5186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
using System;
using System.Text;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using Tango.PMR.Stubs;
using Tango.Stubs; 

include "Tango_define.cs"  
include "MidTank_Jig.cs"
include "DyeHead_Jig.cs"
include "LTFU_Jig.cs"
include "RTFU_Jig.cs"
include "Winder_Jig.cs"  
include "Dryer_Jig.cs"
include "Mixer_Jig.cs"
include "Location.cs"
include "New_DyeHead_Jig.cs"
include "New_Mixer_Jig.cs"

//bool _click = false;
System.Timers.Timer timer;


string [,] Units_status   = new string[50,2];

string	File_Name1	;
string Status;


const int Winder =0 ;
const int LTFU =1 ;

string path;
string path1="C:\\Jig_Log\\";;

bool BlinkOn = false;
bool timer_started = false;
CancellationTokenSource _cancellationTokenSource;
 
int UNIT_UNDER_TEST ;	
 	

public void OnExecute(StubManager stubManager)
{
	Label Run_text =  new Label () 
	{
		Width = 110,
   	  	Height =35,
   	  	Text = "",
   	  	BackColor = Color.White
  	};
	
	System.Windows.Forms.Label  _calc_text= 	new Label()
    {
        Width = 350,
        Height = 125,
        Text = ""
    };
	void setLabel1TextSafe(string txt)
	{
		if (_calc_text.InvokeRequired)
	            _calc_text.Invoke(new Action(() => _calc_text.Text = txt));
	    else
	        _calc_text.Text = txt;
	}
	
	void timer_Tick(object sender, EventArgs e)
    {
        if (BlinkOn)
        {
            Run_text.ForeColor = Color.Green;
            Run_text.BackColor = Color.White;
        }
        else
        {
             Run_text.ForeColor = Color.Red;
             Run_text.BackColor = Color.Black;

         }
         BlinkOn = !BlinkOn;
        }
	
		timer = new System.Timers.Timer();
        timer.Elapsed += timer_Tick;
        timer.Interval = new TimeSpan(0, 0, 0, 0, 500).TotalMilliseconds;
	//stubManager.WriteLine("OK!");
		Form form1 = new Form();		
// Set the caption bar text of the form.
		//form1.TopMost = true;
		form1.Text = "Tests";
  		form1.FormBorderStyle = FormBorderStyle.FixedDialog;
 		form1.MaximizeBox = false;
		form1.MinimizeBox = false;
 		form1.StartPosition = FormStartPosition.CenterScreen;
	    form1.AutoSize = true;
	    form1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
	    form1.BackColor = Color.FromArgb(233, 245, 255);
//start mat	    
// Create buttons to Winder. 
 		Button Winder_btm = new Button () 
		{
			Width = 80,
	   	  	Height = 40,
	  	};
		Winder_btm.Text = "Winder";
		Winder_btm.Location = new Point (4, 70);
		Winder_btm.BackColor = System.Drawing.Color.Gray;
	    form1.Controls.Add(Winder_btm);
	    
// Create buttons to LTFU. 
 		Button LTFU_btm = new Button () 
		{
			Width = 80,
	   	  	Height = 40,
	  	};
		LTFU_btm.Text = "LTFU";
		LTFU_btm.Location = new Point (94, 70);
		LTFU_btm.BackColor = System.Drawing.Color.Gray;
	    form1.Controls.Add(LTFU_btm);
	    
// Create buttons to Dryer. 
 		Button Dryer_btm = new Button () 
		{
			Width = 80,
	   	  	Height = 40,
	  	};
		Dryer_btm.Text = "Dryer";
		Dryer_btm.Location = new Point (184, 70);
		Dryer_btm.BackColor = System.Drawing.Color.Gray;
	    form1.Controls.Add(Dryer_btm);
	    
// Create buttons to Dye head. 
 		Button DyeHead_btm = new Button () 
		{
			Width = 80,
	   	  	Height = 40,
	  	};
		DyeHead_btm.Text = "Dye head";
		DyeHead_btm.Location = new Point (4, 114);
		DyeHead_btm.BackColor = System.Drawing.Color.Gray;
	    form1.Controls.Add(DyeHead_btm);
	    
// Create buttons to RTFU. 
 		Button RTFU_btm = new Button () 
		{
			Width = 80,
	   	  	Height = 40,
	  	};
		RTFU_btm.Text = "RTFU";
		RTFU_btm.Location = new Point (94, 114);
		RTFU_btm.BackColor = System.Drawing.Color.Gray;
	    form1.Controls.Add(RTFU_btm);
	    
// Create buttons to Mid Tank. 
 		Button MidTank_btm = new Button () 
		{
			Width = 80,
	   	  	Height = 40,
	  	};
		MidTank_btm.Text = "Mid Tank";
		MidTank_btm.Location = new Point (184, 114);
		MidTank_btm.BackColor = System.Drawing.Color.Gray;
	    form1.Controls.Add(MidTank_btm);
	    
// Create buttons to WHS. 
 		Button WHS_btm = new Button () 
		{
			Width = 80,
	   	  	Height = 40,
	  	};
		WHS_btm.Text = "WHS";
		WHS_btm.Location = new Point (94, 158);
		WHS_btm.BackColor = System.Drawing.Color.Gray;
	    form1.Controls.Add(WHS_btm);
	    
// Create buttons to Mixer. 
 		Button Mixer_btm = new Button () 
		{
			Width = 80,
	   	  	Height = 40,
	  	};
		Mixer_btm.Text = "Mixer";
		Mixer_btm.Location = new Point (4, 158) ;
		Mixer_btm.BackColor = System.Drawing.Color.Gray;
	    form1.Controls.Add(Mixer_btm);

// Create buttons to New Mixer . 
 		Button NewMixer_btm = new Button () 
		{
			Width = 80,
	   	  	Height = 40,
	  	};
		NewMixer_btm.Text = "New Mixer";
		NewMixer_btm.Location = new Point (4, 202);
		NewMixer_btm.BackColor = System.Drawing.Color.Gray;
	    form1.Controls.Add(NewMixer_btm);
	    
// Create buttons to NewDyeHead. 
 		Button NewDyeHead_btm = new Button () 
		{
			Width = 80,
	   	  	Height = 40,
	  	};
		NewDyeHead_btm.Text = "New Dye head";
		NewDyeHead_btm.Location = new Point (184, 158);
		NewDyeHead_btm.BackColor = System.Drawing.Color.Gray;
	    form1.Controls.Add(NewDyeHead_btm);
	    
//-----Create Lable to Serial Number -----------

		Label SN_lbl = new Label () 
		{
			Width = 150,
	   	  	Height = 20,
	   	  	Text =" S/N"
  		};
		SN_lbl.Location = new Point (40, 10);
	 	form1.Controls.Add(SN_lbl);
		TextBox SN_TexstBox = new TextBox () 
		{
			Width = 150,
	   	  	Height = 20,
	   	  	Text =""
  		};
		SN_TexstBox.Location = new Point (40, 40);
		form1.Controls.Add(SN_TexstBox);
		//-----Create Lable to Part Number -----------

		Label PN_lbl = new Label () 
		{
			Width = 150,
	   	  	Height = 20,
	   	  	Text =" P/N"
  		};
		PN_lbl.Location = new Point (190, 10);
	 	form1.Controls.Add(PN_lbl);
		TextBox PN_TexstBox = new TextBox () 
		{
			Width = 150,
	   	  	Height = 20,
	   	  	Text =""
  		};
		PN_TexstBox.Location = new Point (190, 40);
		form1.Controls.Add(PN_TexstBox);
 //----------Create Lable to LOCATION----------
	 	Label Location_lbl = new Label () 
		{
			Width = 150,
	   	  	Height = 20,
	   	  	Text ="LOCATION"
	  	};
		Location_lbl.Location = new Point (440, 10);
 		form1.Controls.Add(Location_lbl);

		TextBox Location_TexstBox = new TextBox () 
		{
			Width = 150,
	   	  	Height = 20,
	   	  	Text =Location_str
	  	};
		Location_TexstBox.Location = new Point (440, 40);
 		form1.Controls.Add(Location_TexstBox);
 	
	Run_text.Location = new System.Drawing.Point(300, 100);
    Run_text.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    Run_text.Name = "blink_Text";
    Run_text.Font = new Font("Areal", 16, System.Drawing.FontStyle.Bold);
	form1.Controls.Add(Run_text); 	
//--------------------------------------------------------------------------------
	Button Stop_btm = new Button()
    {
        Width = 260,
        Height = 40,
    };
    Stop_btm.Text = "Stop process";
    Stop_btm.BackColor = System.Drawing.Color.Red;
    Stop_btm.Location = new System.Drawing.Point(4, 286);
	Stop_btm.Enabled= false;
    Stop_btm.Click += (_, __) =>
    {
        timer.Stop();
        timer_started = false;
        _cancellationTokenSource.Cancel();
     		stubManager.WriteLine("stop ");
 
    };
	
    form1.Controls.Add(Stop_btm);
	disable_test();
	void disable_test()
	{
            Winder_btm.Enabled = false;
			LTFU_btm.Enabled = false;
			RTFU_btm.Enabled = false;
			Dryer_btm.Enabled = false;
			MidTank_btm.Enabled= false;
			DyeHead_btm.Enabled= false;
			WHS_btm.Enabled= false;
			Mixer_btm.Enabled= false;
			NewMixer_btm.Enabled= false;
			NewDyeHead_btm.Enabled= false;
			Stop_btm.Enabled= false;
	}
	
//	void enable_test()
//	{
//			Winder_btm.Enabled = true;
//			LTFU_btm.Enabled = true;
//			RTFU_btm.Enabled = true;
//			Dryer_btm.Enabled = true;
//			MidTank_btm.Enabled= true;
//			DyeHead_btm.Enabled= true;
//			WHS_btm.Enabled= true;
//			Mixer_btm.Enabled= true;
//			NewMixer_btm.Enabled= true;
//			NewDyeHead_btm.Enabled= true;
//			Stop_btm.Enabled= false;
//	}
	void Timer_en()
	{	
		if (timer_started == false)
        {
            timer.Start();
            timer_started = true;
	     }
	}	
	void Timer_dis()
	{
		if (timer_started == true)
        {
            timer.Stop();
            timer_started = false;
	     }
	}
	void end_test()
	{	disable_test();
	//enable_test();
	
			Timer_dis();
		 
			Run_text.Text = Status; 
        if (Status=="Pass")
        {
            Run_text.ForeColor = Color.White;;
            Run_text.BackColor = Color.Green;
        }
        else
        {
             Run_text.ForeColor = Color.Black;
             Run_text.BackColor = Color.Red;

        }
	}

PN_TexstBox.TextChanged += (_,__)=>

	{
		string temp;

		if (SN_TexstBox.Text.Length!=15)
			return;

		
		if (PN_TexstBox.Text.Contains("-"))
		
		{
		temp=PN_TexstBox.Text.Substring(0, PN_TexstBox.Text.IndexOf("-"));
		disable_test();
		if (SN_TexstBox.Text.Length!=15)
			return;
		switch (temp)
		{
			case "AM00315":			//DyeHead
				NewDyeHead_btm.Enabled= true;
				break;
			case "AM00103":			//Winder
				Winder_btm.Enabled = true;
				break;
			case "AM00087":			//MidTank
				MidTank_btm.Enabled = true;
				break;
			case "AM00031":			//LTFU
				LTFU_btm.Enabled = true;
				break;
			case "AM00007":			//Dryer
				Dryer_btm.Enabled = true;
				break;
			case "AM00030":			//RTFU
				RTFU_btm.Enabled = true;
				break;
			case "AM00286":			//New Mixer
				NewMixer_btm.Enabled= true;
				break;
//			case "AM00281":			// Mixer
//				Mixer_btm.Enabled= true;
//				break;
		}		

		}

	};
	SN_TexstBox.TextChanged += (_,__)=>

	{
		string temp;
				if (SN_TexstBox.Text.Length!=15)
			return;
		if (PN_TexstBox.Text.Contains("-"))
		{

		temp=PN_TexstBox.Text.Substring(0, PN_TexstBox.Text.IndexOf("-"));
		disable_test();
			switch (temp)
			{
			case "AM00315":			//DyeHead
				NewDyeHead_btm.Enabled= true;
				break;
			case "AM00103":			//Winder
				Winder_btm.Enabled = true;
				break;
			case "AM00087":			//MidTank
				MidTank_btm.Enabled = true;
				break;
			case "AM00031":			//LTFU
				LTFU_btm.Enabled = true;
				break;
			case "AM00007":			//Dryer
				Dryer_btm.Enabled = true;
				break;
			case "AM00030":			//RTFU
				RTFU_btm.Enabled = true;
				break;
			case "AM00286":			//New Mixer
				NewMixer_btm.Enabled= true;
				break;
//			case "AM00281":			// Mixer
//				Mixer_btm.Enabled= true;
//				break;

			}
		}
	};
//-----------------------------------------
	Winder_btm.Click += async(_,__) => 
	{
		Run_text.Text = "Run";
		stubManager.WriteLine("DUT- Winder ");
		path="C:\\Users\\lp4\\Dropbox\\"+Location_TexstBox.Text +"_Bench_Tester"+"\\Winder\\"  ;
		Timer_en();
     	_cancellationTokenSource = new CancellationTokenSource();
        try
        {
		//	disable_test();
            Winder_btm.Enabled = false;
			Stop_btm.Enabled= true;
            var longRunningTask = await Winder_test(setLabel1TextSafe, _cancellationTokenSource.Token, SN_TexstBox.Text ,Location_TexstBox.Text );
        }
        catch (OperationCanceledException)
        {
			disable_test();
 			Status="Cancel";
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,WINDER_Motor,3);		//stop motor
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,SCREW,3);		//stop motor

		   stubManager.WriteLine("Task was cancelled");
        }
        finally
        {
            _cancellationTokenSource.Dispose();
        }
		end_test();
	};
//-----------------------------------------
	LTFU_btm.Click += async(_,__) => 
	{
		Run_text.Text = "Run";
		stubManager.WriteLine("DUT- LTFU ");
		path="C:\\Users\\lp4\\Dropbox\\"+Location_TexstBox.Text +"_Bench_Tester"+"\\LTFU\\"  ;

		Timer_en();
     	_cancellationTokenSource = new CancellationTokenSource();
        try
        {
//			disable_test();
			LTFU_btm.Enabled = false;
			Stop_btm.Enabled= true;
            var longRunningTask = await LTFU_test(setLabel1TextSafe, _cancellationTokenSource.Token, SN_TexstBox.Text ,Location_TexstBox.Text );
        }
        catch (OperationCanceledException)
        {
			disable_test();
 			Status="Cancel";
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,LLOADING_Motor, 3);					//hold LRoading high z
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,LDANCER1_Motor, 3);					//hold Lloading high z
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,LDRIVING_Motor,3);		//stop motor

			Thread.Sleep(100);
			Motor_SetParam(F1_MOTO_LLOADING_TX1,F1_MOTO_LLOADING_TX0,0x0a,0x14000000);							//set kval ran to 0x14,0.65A
			
			
		   stubManager.WriteLine("Task was cancelled");
        }
        finally
        {
            _cancellationTokenSource.Dispose();
        }
		end_test();
	};
//-----------------------------------------
	Dryer_btm.Click += async(_,__) => 
	{
		Run_text.Text = "Run";
		stubManager.WriteLine("DUT- Dryer ");
		path="C:\\Users\\lp4\\Dropbox\\"+Location_TexstBox.Text +"_Bench_Tester"+"\\Dryer\\"  ;
		
		Timer_en();
     	_cancellationTokenSource = new CancellationTokenSource();
        try
        {
//			disable_test();
			Dryer_btm.Enabled = false;
            Stop_btm.Enabled= true;
			var longRunningTask = await Dryer_test(setLabel1TextSafe, _cancellationTokenSource.Token, SN_TexstBox.Text ,Location_TexstBox.Text );
        }
        catch (OperationCanceledException)
        {
			
			disable_test();
 			Status="Cancel";
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DryerLid_Motor, 2);		//Hard stop hiZ motor
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DryerMain_Motor,3);		//stop motor
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DrierLoadingArm_Motor, 3);
			SetBit (F2_CTRL, 10, 0);		//turn SSR1 off
			SetBit (F2_CTRL, 9, 0);		//turn SSR2 off

			
			stubManager.WriteLine("Task was cancelled");
        }
        finally
        {
            _cancellationTokenSource.Dispose();
        }
		end_test();
	};
//-----------------------------------------
	DyeHead_btm.Click += async(_,__) => 
	{
		Run_text.Text = "Run";
		stubManager.WriteLine("DUT- DyeHead ");
		path="C:\\Users\\lp4\\Dropbox\\"+Location_TexstBox.Text +"_Bench_Tester"+"\\DyeHead\\"  ;

		Timer_en();
     	_cancellationTokenSource = new CancellationTokenSource();
        try
        {
//			disable_test();
			DyeHead_btm.Enabled= false;
            Stop_btm.Enabled= true;
           var longRunningTask = await DyeHead_test(setLabel1TextSafe, _cancellationTokenSource.Token, SN_TexstBox.Text ,Location_TexstBox.Text );
        }
        catch (OperationCanceledException)
        {
			disable_test();
 			Status="Cancel";
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,MAGNET_Driver,3);		//stop magnet
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DyeingHeadLid_Motor,3);		//stop motor
		   	SetBit (F2_CTRL, 3, 0);
			SetBit (F2_CTRL, 4, 0);
			SetBit (F2_CTRL, 5, 0);
			SetBit (F2_CTRL, 6, 0);
			SetBit (F1_gpo_01, 2, 0);
			SetBit (F3_GPO_01_bus, 4, 0);

			
		   stubManager.WriteLine("Task was cancelled");
        }
        finally
        {
            _cancellationTokenSource.Dispose();
        }
		end_test();
	};
//-----------------------------------------
	NewDyeHead_btm.Click += async(_,__) => 
	{
		Run_text.Text = "Run";
		stubManager.WriteLine("DUT- New DyeHead ");
		path="C:\\Users\\lp4\\Dropbox\\"+Location_TexstBox.Text +"_Bench_Tester"+"\\NewDyeHead\\"  ;

		Timer_en();
     	_cancellationTokenSource = new CancellationTokenSource();
        try
        {
//			disable_test();
			NewDyeHead_btm.Enabled= false;
            Stop_btm.Enabled= true;
            var longRunningTask = await NewDyeHead_test(setLabel1TextSafe, _cancellationTokenSource.Token, SN_TexstBox.Text ,Location_TexstBox.Text );
        }
        catch (OperationCanceledException)
        {
			disable_test();
 			Status="Cancel";
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,MAGNET_Driver,3);		//stop magnet
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DyeingHeadLid_Motor,3);		//stop motor

			for (Int32 i = 0; i < 12; i++)					//???MF
			{
					stubManager.Run<ProgressResponse>("ProgressRequest" ,0x0EAD,0x40F000 + i*0x100);				// turn all heaters OFF 
					Thread.Sleep(10);
 			}
			
		   stubManager.WriteLine("Task was cancelled");
        }
        finally
        {
            _cancellationTokenSource.Dispose();
        }
		end_test();
	};
//-----------------------------------------
	RTFU_btm.Click += async(_,__) => 
	{
		Run_text.Text = "Run";
		stubManager.WriteLine("DUT- RTFU ");
		path="C:\\Users\\lp4\\Dropbox\\"+Location_TexstBox.Text +"_Bench_Tester"+"\\RTFU\\"  ;		
		Timer_en();
     	_cancellationTokenSource = new CancellationTokenSource();
        try
        {
//			disable_test();
			RTFU_btm.Enabled= false;
            Stop_btm.Enabled= true;
            var longRunningTask = await RTFU_test(setLabel1TextSafe, _cancellationTokenSource.Token, SN_TexstBox.Text ,Location_TexstBox.Text );
        }
        catch (OperationCanceledException)
        {
			disable_test();
 			Status="Cancel";
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RLOADING_Motor, 3);					//hold Rloading high z
			Thread.Sleep(100);
			Motor_SetParam(F1_MOTO_RLOADING_TX1,F1_MOTO_RLOADING_TX0,0x0a,0x14000000);							//set kval ran to 0x14,0.65A
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RDANCER_Motor, 3);					//hold Rloading high z
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RDRIVING_Motor,3);		//stop motor
		   stubManager.WriteLine("Task was cancelled");
        }
        finally
        {
            _cancellationTokenSource.Dispose();
        }
		end_test();
	};
//-----------------------------------------
	MidTank_btm.Click += async(_,__) => 
	{
		Run_text.Text = "Run";
		stubManager.WriteLine("DUT- MidTank ");
		path="C:\\Users\\lp4\\Dropbox\\"+Location_TexstBox.Text +"_Bench_Tester"+"\\MidTank\\"  ;
		Timer_en();
     	_cancellationTokenSource = new CancellationTokenSource();
        try
        {
//			disable_test();
			MidTank_btm.Enabled= false;
            Stop_btm.Enabled= true;
            var longRunningTask = await MidTank_test(setLabel1TextSafe, _cancellationTokenSource.Token, SN_TexstBox.Text ,Location_TexstBox.Text );
        }
        catch (OperationCanceledException)
        {
			disable_test();
 			Status="Cancel";
			stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,F3_VALVE_OUT, 0);		//close all valve
			
		   stubManager.WriteLine("Task was cancelled");
        }
        finally
        {
            _cancellationTokenSource.Dispose();
        }
		end_test();
	};
//---------------------------Mixer--------------
	Mixer_btm.Click += async(_,__) => 
	{
		Run_text.Text = "Run";
		stubManager.WriteLine("DUT- Mixer ");
		path="C:\\Users\\lp4\\Dropbox\\"+Location_TexstBox.Text +"_Bench_Tester"+"\\Mixer\\"  ;

		Timer_en();
     	_cancellationTokenSource = new CancellationTokenSource();
        try
        {
//			disable_test();
			Mixer_btm.Enabled= false;			
            Stop_btm.Enabled= true;
            var longRunningTask = await Mixer_test(setLabel1TextSafe, _cancellationTokenSource.Token, SN_TexstBox.Text ,Location_TexstBox.Text );
        }
        catch (OperationCanceledException)
        {
			disable_test();
 			Status="Cancel";
			SetBit (F1_gpo_01, 7, 0);		//clear bit F1_VALVE_MIXCHIP_WASTECH
			SetBit (F2_CTRL, 7, 0);		//clear bit mixer SSR
		   stubManager.WriteLine("Task was cancelled");
        }
        finally
        {
            _cancellationTokenSource.Dispose();
        }
		end_test();
	};
//---------------------------new Mixer--------------
	NewMixer_btm.Click += async(_,__) => 
	{
		Run_text.Text = "Run";
		stubManager.WriteLine("DUT- New Mixer ");
		path="C:\\Users\\lp4\\Dropbox\\"+Location_TexstBox.Text +"_Bench_Tester"+"\\Mixer\\"  ;

		Timer_en();
     	_cancellationTokenSource = new CancellationTokenSource();
        try
        {
//			disable_test();
			NewMixer_btm.Enabled= false;
            Stop_btm.Enabled= true;
            var longRunningTask = await New_Mixer_test(setLabel1TextSafe, _cancellationTokenSource.Token, SN_TexstBox.Text ,Location_TexstBox.Text );
        }
        catch (OperationCanceledException)
        {
			disable_test();
 			Status="Cancel";
		//	SetBit (F1_gpo_01, 7, 0);		????????????//clear bit F1_VALVE_MIXCHIP_WASTECH
		//	SetBit (F2_CTRL, 7, 0);		//????????????clear bit mixer SSR
		   stubManager.WriteLine("Task was cancelled");
        }
        finally
        {
            _cancellationTokenSource.Dispose();
        }
		end_test();
	};

//---------------------------WHS--------------
	
//----------------------------------------
	 _calc_text.Location = new System.Drawing.Point(300, 150);
    _calc_text.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    _calc_text.Name = "";
    _calc_text.Font = new Font("Areal", 16, System.Drawing.FontStyle.Bold);
    form1.Controls.Add(_calc_text);
//	stubManager.WriteLine("Start dialog!");
	form1.ShowDialog();
	return ;
   
    
}
 //---------------------------------------------------------------------------------------------------------------------
string 		write_to_file(string s_n,string loocation,int unit_nm,string DUT)

{
string Stemp="Pass";
string Stemp1="P";

int i;
	
		for ( i=0;i<unit_nm;i++)
		{
			if ((Units_status[i,1]=="Fail")||(Units_status[i,1]=="Not Test"))
			{	Stemp="Fail";
				Stemp1="F";
			}
		}
		
if (!Directory.Exists(path))
	{
		if (!Directory.Exists(path1))
			Directory.CreateDirectory(path1);
		path=path1;	
	}			

		
		
string 	File_Name2=Environment.ExpandEnvironmentVariables(path +Stemp1+"_"+ s_n +"_"+DUT +"_"+ DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss")+".log" );

stubManager.Write(File_Name2 +"\n");

stubManager.WriteToFile(File_Name2,DateTime.Now +" " );
stubManager.Write(DateTime.Now +"\n" );

stubManager.AppendToFile(File_Name2,DUT + " Test Report" );
stubManager.Write(DUT + " Test Report\n" );

stubManager.AppendToFile(File_Name2,DUT + " S/N: \t" + s_n  );
stubManager.Write(DUT + " S/N: \t" + s_n+"\n" );
                  

stubManager.AppendToFile(File_Name2,"Location:\t" + loocation +"\n" );
stubManager.Write("Location:" + loocation+"\n\n" );

		for ( i=0;i<unit_nm;i++)
		{
			stubManager.AppendToFile(File_Name2,Units_status[i,0]+"\t" + Units_status[i,1] );
			stubManager.Write(Units_status[i,0]+"\t" + Units_status[i,1]+"\n" );
		}
		if (Stemp=="Fail")
			{
			stubManager.AppendToFile(File_Name2,"-------------"+DUT+ " Fail ------------ ");
			stubManager.Write("-------------"+DUT+ " Fail ------------ ");
			}
		else
			{
			stubManager.AppendToFile(File_Name2,"-------------"+DUT+ " Pass ------------ ");
			stubManager.Write("-------------"+DUT+ " Pass ------------ ");
			}
	return Stemp;
}	

//-------------------------------------------------------------------------------------
void copy_table(int testing_nm,string [,]Units_status_DUT)
{
	for (int i=0;i<testing_nm;i++)
	{
///	Units_status[i,0]=Units_status_Winder[i,0];
//		Units_status[i,1]=Units_status_Winder[i,1];
		Units_status[i,0]=Units_status_DUT[i,0];
		Units_status[i,1]=Units_status_DUT[i,1];
		
	}	
}

public int delay(Int32 ms_delay)
 {
int i;
	 for (i=0 ;i<ms_delay;i=i+10)
	 { 
		Thread.Sleep(10);
            if (_cancellationTokenSource.Token.IsCancellationRequested)
            {
                _cancellationTokenSource.Token.ThrowIfCancellationRequested();
                 throw new TaskCanceledException();
                return 0;
            }
	 }
	       return 0;

 }


Int32 GetBit(Int32 Adr, Int32 BitNo) 
{
	Int32 BitMask;
	var RetVal = Fpga_Read_Reg(Adr);
	BitMask = 0x1 << BitNo;
	if ( ( (Int32) RetVal.Value & BitMask) == BitMask ) 
	{ 
		return 1;
	}
	else 
	{
		return 0;
	}
	
}

public Int32 SetBit(Int32 Adr, Int32 BitNo, Int32 Bit)
{
	Int32 BitMask;
	var RetVal = Fpga_Read_Reg(Adr);
	Int32 RV = (Int32) RetVal.Value;
	
	if (Bit == 0x1) 
	{
		BitMask = 0x1 << BitNo;
		RV = RV | BitMask;
		Fpga_Write_Reg( Adr, RV );
	}
	else if (Bit == 0x0)
	{
		BitMask = ~(0x1 << BitNo);
		RV = RV & BitMask;
		Fpga_Write_Reg(Adr, RV );	
	}
	return 1;
}


int Fpga_Write_Reg(Int32 Addr, Int32 Data)
{
	var response = stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,Addr, Data);
	
	return 1;
}



StubFpgaReadRegResponse Fpga_Read_Reg(Int32 Addr)
{
    var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,Addr);
	response.Value = response.Value & 0xffff;
	
	return response;
}

float Read_pt100(int i)	
{
	var response = stubManager.Run<StubTempSensorResponse>("StubTempSensorRequest" ,i); //

			float ftemp = (float)response.TemperatureCMultBy100;
			ftemp = ftemp / 100;
		return (ftemp);
}
int Motor_SetParam(Int32 HighAdr, Int32 LowAdr, Int32 ParaAddr, uint ParaData1)
{
	
	Int32 Temp = 0;
	Temp = (ParaAddr << 8 ) + ( (Int32) ParaData1 >> 24);

	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,HighAdr, (Temp & 0xffff));
	Temp = ((Int32)ParaData1 >> 8) & 0xffff;
	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,LowAdr, (Temp));
		
	return 1;
}

//--------------------------------
int adc_configuration(uint I2C_Slave_Add,uint channel ) 
{
	StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest();
	stubI2CWriteBytesRequest.I2CId = I2C_ID2;
	stubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add;
	
	UInt32 uInt32 = new UInt32();
	stubI2CWriteBytesRequest.BytesTWrite.Add(0x00);//Byte 0 to write
	stubI2CWriteBytesRequest.BytesTWrite.Add(channel);//Byte 1 to Write, must be 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02 or 0x01 for different channels
	stubI2CWriteBytesRequest.BytesTWrite.Add(0x80);//Byte 2 to Write
	
	var response = stubManager.Run<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest);
	
	return 1;
}
//--------------------------------
int adc_set_for_read_ch(uint I2C_Slave_Add) 
{
	StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest();
	stubI2CWriteBytesRequest.I2CId = I2C_ID2;
	stubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add;
	
	UInt32 uInt32 = new UInt32();
	stubI2CWriteBytesRequest.BytesTWrite.Add(0x01);//Byte 0 to write

	var response = stubManager.Run<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest);
	
	return 1;
}
//--------------------------------	

uint adc_read_ch(uint I2C_Slave_Add) 
{
	StubI2CReadBytesRequest stubI2CReadBytesRequest = new StubI2CReadBytesRequest();
	stubI2CReadBytesRequest.I2CId = I2C_ID2;
	stubI2CReadBytesRequest.SlaveAddress = I2C_Slave_Add;
	stubI2CReadBytesRequest.NumberOfBytesToRead = 2; // Number of bytes to read

	var response1 = stubManager.Run<StubI2CReadBytesResponse>(stubI2CReadBytesRequest);
	uint temph=0;
	uint templ=0;
	uint temp;
			temph=response1.ReadBytes[0];
			templ=response1.ReadBytes[1];
			temp = (temph << 8) | templ;
			temp=temp & 0x0fff;
				
	return temp;
}