aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection/stubs/Scripts/Jig_Tester/Winder_Jig.cs
blob: 3ad16cb5eaefaf7550fd3fb6d54283362b8d46ad (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
using System;
using System.Text;
using System.IO;
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;


const  int Winder_UNDER_TEST=6;

string [,] Units_status_Winder = new string[Winder_UNDER_TEST,2]	{ 
												{"Winder_Motor","Not Test"},
												{"Screw_Motor","Not Test"},
												{"LS_Screw_Right","Not Test"},
												{"LS_Screw_Left","Not Test"},
												{"Screw_Encoder","Not Test"},
												{"SW_Spool_Exist","Not Test"},
											};


//--------------------------------------------------------------------------------

public Task<decimal> Winder_test( Action<string> settext, CancellationToken cancellationToken, string SN, string Location)
{
    Task<decimal> task = null;
    // Start a task and return it
    task = Task.Run(() =>
    {

	stubManager.Write("S/N:" +SN+ "\n");
	stubManager.Write("Location:" +Location+ "\n");

	copy_table (Winder_UNDER_TEST,Units_status_Winder);
	DialogResult result2 = MessageBox.Show("Insert Spool");
	
	settext("Test_Winder_motor");
 	Test_Winder_motor();
	settext("Test_Screw_LS_Motor_Encoder");
	Test_Screw_LS_Motor_Encoder ();
	settext("Test_Pooler_Exis");
	Test_Pooler_Exist ();

	Status=write_to_file(SN,Location,Winder_UNDER_TEST,"Winder");
    settext("End Test");
	decimal result = 0;

    return result;
    });
    return task;
}
  
//------------------------------------------
public int Test_Winder_motor ()

{
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,WINDER_Motor, true, 500);		//rotate Winder Motor.
	stubManager.Write("Winder Motor rotate \n");
	DialogResult result = MessageBox.Show("Are Winder Motor rotate?", "Warning",MessageBoxButtons.YesNo);
	 if (_cancellationTokenSource.Token.IsCancellationRequested)
            {
                _cancellationTokenSource.Token.ThrowIfCancellationRequested();
                 throw new TaskCanceledException();
                return 0;
            }
	if(result == DialogResult.No)
		{
			Units_status[0,1]="Fail";
			stubManager.Write("Winder Motor not rotate\n");
		}
	else 
		{
			Units_status[0,1]="Pass";
			stubManager.Write("Winder Motor rotate\n");
		}
		stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,WINDER_Motor,3);		//stop motor

	return 0;
}	


//-------------------------------------------- 
 int Test_Screw_LS_Motor_Encoder()
{  
	UInt32 temp	;
	Int32 Bit = 1;	
	
	
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,SCREW, false, 250);		//rotate screw Motor out.
	delay(1000);
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,SCREW,3);				//stop motor

	DialogResult result2 = MessageBox.Show("Did screw Motor move ?", "Warning",MessageBoxButtons.YesNo);
	if(result2 == DialogResult.No)
		{
			Units_status[1,1]="Fail";
			stubManager.Write("Screw Motor not move\n");
			return 0;
		}
			Units_status[1,1]="Pass";
	
	stubManager.Write("Screw Motor rotate \n");

	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,SCREW, true, 250);
	stubManager.Write("Move screw in\n");
	
	Bit = 1;
	int i=0;		
	while ((Bit != 0x0)&& (i<200) )		//wait until Limit Switch or timeout 200*50msec=10sec
			{	
					Bit = GetBit(F1_LS_03_Direct,0);	
					delay(50);
					i++;
			}
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,SCREW,3);		//stop motor
		
	DialogResult result1 = MessageBox.Show("Limit Switch calibrate ?", "Warning",MessageBoxButtons.YesNo);
	if(result1 == DialogResult.No)
		{
			Units_status[2,1]="Fail";
			stubManager.Write("LS_SCREW_RIGHT Not calibrate\n");
			return 0;
		}
	Units_status[2,1]="Pass";
	stubManager.Write("Move screw out\n");

	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,F1_SCREW_ROTENC_lsb, 0x0000);		//clear encoder
	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,F1_SCREW_ROTENC_msb, 0x0000);		//clear encoder

	Bit = 1;
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,SCREW, false, 250);
	i=0;		
	while ((Bit != 0x0) && (i<200))		//wait until Limit Switch or timeout 200*50msec=10sec
			{	
				Bit = GetBit(F1_LS_03_Direct,1);	
				delay(50);
				i++;
			}
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,SCREW,3);		//stop motor
		
	DialogResult result3 = MessageBox.Show("Limit Switch calibrate ?", "Warning",MessageBoxButtons.YesNo);
	if(result3 == DialogResult.No)
		{
			Units_status[3,1]="Fail";
			stubManager.Write("LS_SCREW_LEFT Not calibrate\n");
			return 0;
		}
	Units_status[3,1]="Pass";
	
	var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_SCREW_ROTENC_lsb);
	var response1 = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_SCREW_ROTENC_msb);

	temp=(response.Value & 0xffff )+((response1.Value & 0xffff )<<16);
	temp=temp&0x0fffffff;
	temp= 0x4000000-temp;
	stubManager.Write("Encoder positio:" +temp+"\n");

	if ((temp>20000) && temp<28000)
		Units_status[4,1]="Pass";
	else	
		Units_status[4,1]="Fail";//

 	return 1;
}  
 //---------------------------------------
int Test_Pooler_Exist()
{
	if 	( (GetBit(F1_LS_03_Direct,11))==0)	
		{
			Units_status[5,1]="Fail";
			return 0;
		}

	DialogResult result2 = MessageBox.Show("Remove Spool");
	if 	( (GetBit(F1_LS_03_Direct,11))!=0)
			Units_status[5,1]="Fail"; //
	else
			Units_status[5,1]="Pass";	
	
			return 0	;


}