aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection/stubs/Scripts/Assemblies/New_DyeHead/Test_Lid.cs
blob: 110a0f09be0d2e0972dc0f2b6e56ee7276fe01b0 (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
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 	New_DyeHead_UNDER_TEST=48;

const 	Int32	MGNET_OPEN=0x42F801;
const	Int32	MGNET_EN=0x42F701;
const	Int32	MGNET_CLOSE=0x42F800;
const	Int32	MGNET_DIS=0x42F700;

const	Int32	LS_FRONT=0X460110;
const	Int32	LS_REAR=0X460120;
const	Int32	LS_UPPER=0X460140;
const	Int32	LS_SPARE=0X460180;

const Int32 DyeingHeadLid_Motor		=	2;

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

public void OnExecute(StubManager stubManager)
{
     var response = stubManager.ShowResponseWindow("Enter Loop Number for Dye Head Lead.", "");
    //stubManager.WriteLine(response);
	int Loop_Nm = int.Parse(response);

	for (int i=0;i<Loop_Nm;i++)
	{
		if (Test_Magnet_Motor_LS_New_DyeHead() != 0 )
		{
			i=Loop_Nm;
			stubManager.Write("Error"); 
		}
		Thread.Sleep(2000);
	}
}
  
//------------------------------------------------------------- 

//-------------------------------------------- 
 int Test_Magnet_Motor_LS_New_DyeHead()
{  
	Int32 temp;
	int i=0;
	
//---------------------- open Magnet ---------------------------- 
		stubManager.Run<ProgressResponse>("ProgressRequest" ,0x0EAD,MGNET_OPEN);	// turn magnet on
					Thread.Sleep(100);

		stubManager.Run<ProgressResponse>("ProgressRequest" ,0x0EAD,MGNET_EN);	// magnet enable
							Thread.Sleep(100);

		Thread.Sleep(1000);																					
//---------------------- chekc Magnet is open  ---------------------------- 
//	DialogResult result = MessageBox.Show("Make shure, Magnet is open and DyeHead cover on front.", "Warning",MessageBoxButtons.YesNo);
//	if(result == DialogResult.No)
//		{
//			stubManager.Write("Magnet is close\n"); 
//			return 0;
//		}
		temp=read_pio (LS_UPPER);	// read LS_UPPER
		if (temp != 0)		
		{	
			stubManager.Write("LS_UPPER of Magnet is close\n"); 
			return 1;
		}
		stubManager.Write("Magnet is Open\n"); 
		
		
//---------------------- Move DyeingHead Lid Motor rear---------------------------- 
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,DyeingHeadLid_Motor, true, 250);
	stubManager.Write("***   Open Lid Head ********* \n");
	
	temp = 0;
	 i=0;		
	while ((temp == 0x0)&& (i<200) )		//wait until Limit Switch or timeout 200*50msec=10sec
			{	
					temp=read_pio (LS_REAR);	// read LS_REAR
					Thread.Sleep(50);

					i++;
			}
			
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DyeingHeadLid_Motor,3);		//stop motor
	if(i==200)
		{
			stubManager.Write("LS_REAR Not calibrate\n");
			return 1;
		}
	
//---------------------- Move DyeingHead Lid Motor front---------------------------- 
	stubManager.Write("***   Close Lid Head \n");
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,DyeingHeadLid_Motor, false, 250);
	temp = 0;
	 i=0;		
	while ((temp == 0x0)&& (i<200) )		//wait until Limit Switch or timeout 200*50msec=10sec
			{	
					temp=read_pio (LS_FRONT);	// read LS_FRONT
					Thread.Sleep(50);
					i++;
			}
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,DyeingHeadLid_Motor,3);		//stop motor
	if(i==200)
		{
			stubManager.Write("LS_FRONT Not calibrate\n");
			return 1;
		}
//---------------------- Close Magnet ---------------------------- 
		stubManager.Run<ProgressResponse>("ProgressRequest" ,0x0EAD,MGNET_CLOSE);	// turn magnet off
		Thread.Sleep(2000);																					
		stubManager.Run<ProgressResponse>("ProgressRequest" ,0x0EAD,MGNET_DIS);	// magnet Disable
		
		stubManager.Write("Magnet is Close\n"); 
		Thread.Sleep(1000);																					

		temp=read_pio (LS_UPPER);	// read LS_UPPER
		if (temp == 0)		
		{	
			stubManager.Write("LS_UPPER of Magnet is open\n"); 
			return 1;
		}
			stubManager.Write("LS_UPPER of Magnet is close\n"); 
			return 0;
	}

Int32 read_pio(Int32 i2c_input)
{
		Int32 temp=0;
	var response = stubManager.Run<ProgressResponse>("ProgressRequest" ,0x0EAD,i2c_input);	// read break

		temp = (Int32) (response.Progress);
		temp =temp & (i2c_input& 0xff);						//if break ok

		return temp;
}
//end mati