aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection/stubs/Scripts/Jig_Tester/Dryer_Jig.cs
blob: 5f5c970c14be7078ca84e04882bec53ac735c21b (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
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 Dryer_UNDER_TEST=12;
//--------------------------------------------------------------------------------
//---------------------------
Int32	last_14bit_position;
Int32	position_32bit=0;
float [] DryerTemp = new float[20]	;


string [,] Units_status_Dryer = new string[Dryer_UNDER_TEST,2]	{ 
												{"Lid_Motor","Not Test"},		//0
												{"LS_Lid_Open","Not Test"},		//1
												{"LS_Lid_Close","Not Test"},	//2
												{"DRIVING_Motor","Not Test"},	//3
												{"SSI_Encoder","Not Test"},		//4
												{"LoadArm_Motor","Not Test"},	//5
												{"Blower_test","Not Test"},		//6
												{"Air_PT100_test","Not Test"},	//7
												{"Main_PT100_test","Not Test"},	//8
												{"Sec.PT100","Not Test"},		//9
												{"SSR1_heater","Not Test"},		//10											
												{"SSR2_heater","Not Test"},		//11											
											};



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


public Task<decimal> Dryer_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 (Dryer_UNDER_TEST,Units_status_Dryer);

	settext("Test Dryer LId");
	Test_LId();
	
	settext("Test Dryer motor Driving");
	Test_motor_driving();

	settext("Test Dryer Load Arm");
	Test_Load_Arm ();
	
 	settext("Test Dryer Blower heaters pt100");
	Test_Blower_heaters_pt100();
	
	Status=write_to_file(SN,Location,Dryer_UNDER_TEST,"Dryer");

	settext("End Test");
	
	decimal result = 0;
		
        return result;
    });
    return task;
}
//------------------------------------------
int Test_Blower_heaters_pt100()
{
	
	float ftemp=0;
	float ftemp1=0;
	
	SetBit(F1_gpo_01,5,1);		//turn off Blower
	  delay(500);

	var RetVal=Fpga_Read_Reg(F1_Tacho_reg8); 

   	DialogResult result = MessageBox.Show("Close Dryer Door", "Warning");
		 
	SetBit(F1_gpo_01,4,1);		//Dir
	SetBit(F1_gpo_01,3,1);		//Torqer High
	SetBit(F1_gpo_01,5,0);		//turn on Blower

	const int LOW = 70;//0 - 100%
	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,F2_Prescaler1_reg11, 0xFF);//Freq 8 bit
	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,F2_BLOWER_PWM_LOW, LOW+1);//Low 8 bit
	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,F2_BLOWER_PWM_HIGH, 101 - LOW);//High 8 bit 
	 
	delay(1000);
	RetVal=Fpga_Read_Reg(F1_Tacho_reg8); 
	stubManager.Write("blower Speed-  " + RetVal.Value + "\n");	
	if ((RetVal.Value<150)||(RetVal.Value>250) )
	{
		Units_status[6,1]="Fail";
		stubManager.Write("Error,Fan rotate\n");		
		return 0;
	}	
		Units_status[6,1]="Pass";
		
	stubManager.Write("Temp Befor heating \n");
	if	(test_pt100_dryer()!=0)
		return 0;

float temp=0;
float temp1=4096*95*5;

	//Write GPO_DRYER_SSR1_CTRL SSR/SSR no. 1
   SetBit (F2_CTRL, 10, 1);		//turn SSR1 on
   stubManager.Write("\tTesting SSR no. 1\t");
   delay(1000);
var response1 = stubManager.Run<StubIntADCReadResponse>("StubIntADCReadRequest" ,16);
	temp=Convert.ToUInt32 (response1.SamplingInBits);
	temp=temp*800*3*100;
	temp=temp/(4096*95*50);
	stubManager.Write("Current = "+ temp + "A\n");
	if ((temp>6) || (temp<3))
		Units_status[10,1]="Fail";
	else
		Units_status[10,1]="Pass";
  
	//Write GPO_DRYER_SSR2_CTRL SSR/SSR no. 2	
	SetBit (F2_CTRL, 9, 1);
	stubManager.Write("\tTesting SSR no. 2\t");
	delay(1000);
	response1 = stubManager.Run<StubIntADCReadResponse>("StubIntADCReadRequest" ,17);
	temp=Convert.ToUInt32 (response1.SamplingInBits);
	temp=temp*800*3*100;
	temp=temp/(4096*95*100);
	stubManager.Write("Current = "+ temp + "A\n");
 	if ((temp>3) || (temp<1))
		Units_status[11,1]="Fail";
	else
		Units_status[11,1]="Pass";
  
 	delay(50000);

//check air temp
	ftemp=Read_pt100(6);
	stubManager.Write("After heating air temp is " + ftemp + "\n");
	ftemp = ftemp - DryerTemp[6];
	if ((ftemp<5)||(ftemp>40))
		Units_status[7,1]="Fail";
	else
		Units_status[7,1]="Pass";



//check Main temp
	ftemp=Read_pt100(7);
	stubManager.Write("After heating Main temp is " + ftemp + "\n");
	ftemp = ftemp - DryerTemp[7];
	if ((ftemp<5)||(ftemp>60))
		Units_status[8,1]="Fail";
	else
		Units_status[8,1]="Pass";

//check Sec. temp
	ftemp=Read_pt100(8);
	stubManager.Write("After heating Sec. temp is " + ftemp + "\n");
	ftemp = ftemp - DryerTemp[8];
	if ((ftemp<5)||(ftemp>60))
		Units_status[9,1]="Fail";
	else
		Units_status[9,1]="Pass";

	SetBit (F2_CTRL, 10, 0);		//turn SSR1 off
	SetBit (F2_CTRL, 9, 0);		//turn SSR2 off

	SetBit(F1_gpo_01,5,1);		//turn off Blower
	return 1;
   
}

	int	test_pt100_dryer()
	{
		float ftemp=0;
	int temp=0;
	int		j=0;
			for (int i = 6; i < 9; i++)
	    {
			DryerTemp[i]=Read_pt100(i);

			ftemp=DryerTemp[i];
			if ((ftemp>140)|| (ftemp<10))
			{	
				Units_status[i+1,1]="Fail";
			}
			else
			{
				Units_status[i+1,1]="Pass";
			}	
			stubManager.Write(Units_status[i+1,0] +"\t"+ ftemp.ToString("F2")); 
			stubManager.Write("°C \t" + Units_status[i+1,1] + " \n");	
	
	    }
			return 0;
	}
//------------------------------------------
int Test_motor_driving ()

{
	MessageBox.Show("Open Dryer Door and add CHEATER to Door. ", "Warning");
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,DryerMain_Motor, true, 500);		//rotate Dryer Motor.
	stubManager.Write("Dryer Motor rotate \n ");
	DialogResult result = MessageBox.Show("Are Dryer Motor rotate smoothly ?", "Warning",MessageBoxButtons.YesNo);
	if(result == DialogResult.No)
		{
			Units_status[3,1]="Fail";
			stubManager.Write("Dryer Motor not rotate\n");
		}
	else 
		{
			Units_status[3,1]="Pass";
			stubManager.Write("Dryer Motor rotate\n");
		}
		stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DryerMain_Motor,3);		//stop motor

	return 0;
}	
//----------------------------------
int Test_Load_Arm()
{
	
	Int32 temp3=0;
	Int32 j=0;
	Int32 i=0;

	if (!Encoder_Dryer_Exist())
	{
			Units_status[4,1]="Fail";
			stubManager.Write("Encoder of Dryer Fail \n");
			return 0;

	}
//	position_32bit=0;
//last_14bit_position
	ReadEncoder_Dryer();
	position_32bit=0;	
	ReadEncoder_Dryer();
	Int32 temp=position_32bit;
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,DrierLoadingArm_Motor, false, 100);//40
	delay(50);
//	temp=ReadEncoder_Dryer();	
	while ((temp3<2)&& (i<12000) )		//wait until Limit Switch or timeout 12000*50msec=10min
		{
	   		i++;
			delay(50);
	    	ReadEncoder_Dryer();	
//	   		stubManager.Write("position_32bit " + position_32bit  +"\t");

	    	if (Math.Abs(position_32bit)> (50*0x4000))
	    	    temp3=3;
			if ((position_32bit-temp)>20)
				temp3++;
//						stubManager.Write("Temp " + temp   +"\n");
			temp=position_32bit;
//			stubManager.Write("Temp3 " + temp3  +"\n");
		}
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DrierLoadingArm_Motor, 3);

	DialogResult result1 = MessageBox.Show("Arm Motor rotate ?", "Warning",MessageBoxButtons.YesNo);
	if(result1 == DialogResult.No)
		{
			Units_status[5,1]="Fail";
			stubManager.Write("Arm Motor Not rotate\n");
			return 0;
		}
	Units_status[5,1]="Pass";
			
	DialogResult result2 = MessageBox.Show("Did Arm Motor arrive to mechanical stopper?. See picture on document", "Warning",MessageBoxButtons.YesNo);
	if(result2 == DialogResult.No)
		{
			Units_status[4,1]="Fail";
			stubManager.Write("Arm Motor Not arrive to mecahnicl stopper \n");
			return 0;
		}

	position_32bit=0;
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,DrierLoadingArm_Motor, true, 100);
	delay(50);
		i=0;
		temp3=0;

		
	while ((temp3<1)&& (i<12000) )		//wait until Limit Switch or timeout 12000*50msec=10min
		{
		
		
//		while ((Math.Abs(ReadEncoder_Dryer())< (30*0x4000))&& (i<12000)) 
//
//			{
	   			delay(50);
	   			i++;
//	    		stubManager.Write("position_32bit " + position_32bit  +"\t" + temp3 + "\n" );
	    	ReadEncoder_Dryer();	
//	   		stubManager.Write("position_32bit " + position_32bit  +"\t");

	    	if (Math.Abs(position_32bit)> (30*0x4000))
	    	    temp3=3;
			if ((temp-position_32bit)>20)
				temp3++;
//						stubManager.Write("Temp " + temp   +"\n");
			temp=position_32bit;

								
		}
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DrierLoadingArm_Motor, 3);

	DialogResult result3 = MessageBox.Show("Did Arm Motor make 30 rounds? See picture on document", "Warning",MessageBoxButtons.YesNo);
	if(result3 == DialogResult.No)
		{
			Units_status[4,1]="Fail";
			stubManager.Write("Arm Motor not make 30 rounds\n");
			return 0;
		}
	Units_status[4,1]="Pass";
	return 1;	
}
bool Encoder_Dryer_Exist()
{
	Int32 temp;
	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,0x6000019e, 0x0000);		//triggers a TX transmission

	var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000190);
	var response1 = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000192);		 

	temp =  Convert.ToInt32 (response.Value  & 0x0300);
	if (temp==0)
		return true;
	else
		return false;
}



void ReadEncoder_Dryer()
{
	Int32 temp;
	Int32 temp1;
	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,0x6000019e, 0x0000);		//triggers a TX transmission

	var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000190);
	var response1 = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000192);		 

	temp =  Convert.ToInt32 (((((response1.Value <<16) + 	response.Value)>>10 ) & 0x3fff));
	if (temp>last_14bit_position)
		{
		temp1=temp-last_14bit_position;
		position_32bit=position_32bit+temp1;
		if (temp1>0x2000)
			position_32bit=position_32bit-0x4000;
		}
	else if (temp<last_14bit_position)
		
		{
			temp1=last_14bit_position-temp;
			position_32bit=position_32bit-temp1;
		if (temp1>0x2000)
			position_32bit=position_32bit+0x4000;
		}
	
	last_14bit_position=temp;

	return ;
}
//-----------------------------------
int Test_LId ()
{
	Int32 Bit = 1;	
 	int i = 0;

	UInt32 PowerStep_driver=0;
	
 if (Get_Driver_Type(4)>0x14)
	PowerStep_driver=1;



	
	stubManager.Run<StubMotorMovResponse>("StubMotorMovRequest" ,DryerLid_Motor, false, 0x800000+2*(1-PowerStep_driver));		//mov Dryer Lid motor down
	delay(2000);
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DryerLid_Motor, 2);		//Hard stop hiZ motor
	delay(1000);
	
	stubManager.Run<StubMotorMovResponse>("StubMotorMovRequest" ,DryerLid_Motor, false, 0x800000+2*PowerStep_driver);		//mov Dryer Lid motor up

	while ((Bit != 0x0) && (i<200))		//wait until Limit Switch or timeout 200*50msec=10sec
			{	
					Bit = GetBit(F1_LS_01_Direct,4);	
					delay(50);
					i++;
			}
	stubManager.Write("\n--------1-Lid Open--------");

	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DryerLid_Motor, 2);		//Hard stop hiZ motor
	DialogResult result1 = MessageBox.Show("Limit Switch calibrate ?", "Warning",MessageBoxButtons.YesNo);
	if(result1 == DialogResult.No)
		{
			Units_status[1,1]="Fail";
			stubManager.Write("LS_Lid_Open Not calibrate\n");
			return 0;
		}
	Units_status[1,1]="Pass";

	stubManager.Run<StubMotorMovResponse>("StubMotorMovRequest" ,DryerLid_Motor, false, 0x800000+2*(1-PowerStep_driver));		//mov Dryer Lid motor down

	Bit = 1;
	i=0;	 
	while ((Bit != 0x0) && (i<200))		//wait until Limit Switch or timeout 200*50msec=10sec
			{	
					Bit = GetBit(F1_LS_01_Direct,5);	
					delay(50);
					i++;
			}
					stubManager.Write("\n--------2-Lid Close--------");

	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DryerLid_Motor, 2);		//Hard stop hiZ motor
	DialogResult result2 = MessageBox.Show("Limit Switch calibrate ?", "Warning",MessageBoxButtons.YesNo);
	if(result2 == DialogResult.No)
		{
			Units_status[2,1]="Fail";
			stubManager.Write("LS_Lid_Close Not calibrate\n");
			return 0;
		}
	Units_status[2,1]="Pass";
	Units_status[0,1]="Pass";
			return 1;

}

UInt32 Get_Driver_Type(UInt32 i)
{
	Int32 x_GET_PARAM  = 0x20;
	Int32 x_ADC_OUT    = 0x12;
	UInt32 ADC_out ;


	var response = stubManager.Run<StubMotorResponse>("StubMotorRequest" ,i, (x_GET_PARAM | x_ADC_OUT)<<8, 0, 0);

			ADC_out= (response.RecivedData) & 0x001F; 
		stubManager.WriteHex(ADC_out,2) ;
	 return ADC_out ;
}