ElectricGripper - 复制.cs
4.2 KB
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
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class ElectricGripper
{
private static int subType = 0;
public static Enum GripperType = GripperTypeE.None;
public ElectricGripper(int subType)
{
//this.subType = subType;
}
public static void Clamp(StoreMoveInfo moveInfo = null)
{
GripperType = GripperTypeE.Gripper;
if (!IsBusy)
{
setAction("01000");
IOManager.IOMove(IO_Type.Clamp_DoAction, IO_VALUE.HIGH, subType);
}
if (moveInfo != null)
moveInfo.WaitList.Add(WaitResultInfo.WaitAction(new Func<WaitResultInfo, bool>(WaitAction)));
}
public static bool Release(StoreMoveInfo moveInfo = null)
{
GripperType = GripperTypeE.Release;
if (!IsBusy)
{
setAction("10000");
IOManager.IOMove(IO_Type.Clamp_DoAction, IO_VALUE.HIGH, subType);
moveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
return true;
}
else
{
if (moveInfo != null)
moveInfo.WaitList.Add(WaitResultInfo.WaitAction(new Func<WaitResultInfo, bool>(WaitAction)));
return false;
}
}
public static void HomeReset(StoreMoveInfo moveInfo = null) {
GripperType = GripperTypeE.Reset;
if (!IsBusy)
{
setAction("11111");
IOManager.IOMove(IO_Type.Clamp_DoAction, IO_VALUE.HIGH, subType);
}
if (moveInfo != null)
//moveInfo.WaitList.Add(WaitResultInfo.WaitElectricClamp());
moveInfo.WaitList.Add(WaitResultInfo.WaitAction(new Func<WaitResultInfo, bool>(WaitAction)));
}
public static bool IsBusy {
get {
return IOManager.IOValue(IO_Type.Clamp_Busy, subType).Equals(IO_VALUE.HIGH);
}
}
public static bool IsClamp {
get
{
return IOManager.IOValue(IO_Type.Clamp_OnPosition, subType).Equals(IO_VALUE.HIGH);
}
}
static bool WaitAction(WaitResultInfo w)
{
if (ElectricGripper.IsBusy)
return false;
if (ElectricGripper.GripperType.Equals(ElectricGripper.GripperTypeE.Gripper))
{
if (ElectricGripper.IsClamp)
return true;
else
{
ElectricGripper.Clamp();
return false; ;
}
}
else if (ElectricGripper.GripperType.Equals(ElectricGripper.GripperTypeE.Release))
{
return ElectricGripper.Release();
}
else if (ElectricGripper.GripperType.Equals(ElectricGripper.GripperTypeE.Reset))
{
return ElectricGripper.IsBusy;
}
else {
return true;
}
}
public static int state
{
get
{
int s1 = (int)IOManager.IOValue(IO_Type.Clamp_Abnormal1, subType);
int s2 = (int)IOManager.IOValue(IO_Type.Clamp_Abnormal2, subType);
int s3 = (int)IOManager.IOValue(IO_Type.Clamp_ObjRecognize1, subType);
int s4 = (int)IOManager.IOValue(IO_Type.Clamp_ObjRecognize2, subType);
int s5 = (int)IOManager.IOValue(IO_Type.Clamp_ObjRecognize3, subType);
string b = s1.ToString() + s2 + s3 + s4 + s5;
return Convert.ToInt32(b, 2);
}
}
public static void setAction(string s) {
for (int i = 0; i < 5; i++)
{
IOManager.IOMove("Clamp_SetPos"+i,s[i]=='1'? IO_VALUE.HIGH : IO_VALUE.LOW, subType);
}
}
public enum GripperTypeE
{
Gripper,
Release,
Reset,
None
}
}
}