ClampJawBean.cs
4.6 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
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
using Neotel;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class ClampJawBean
{
public string Name = "";
public ConfigClampJaw config = null;
public Rmaxis rmaxis = null;
public ClampJawBean(ConfigClampJaw config)
{
this.config = config;
Name = config.DisplayStr + "(" + config.PortName + "_" + config.AxisNo + ")";
OpenPort();
}
public bool OpenPort()
{
if (config == null)
{
return false;
}
if (rmaxis == null)
{
rmaxis = new Rmaxis("Rmaxis");
}
if (!rmaxis.IsPortOpen)
{
bool result = rmaxis.OpenPort(config.PortName, config.AxisNo);
if (!result)
{
LogUtil.error(Name + " OpenPort 失败");
}
}
return rmaxis.IsPortOpen;
}
public void ClosePort()
{
if (rmaxis != null)
{
rmaxis.ClosePort();
}
}
public void Push(LineMoveInfo moveInfo = null, bool checkHasReel = true)
{
if (rmaxis != null && rmaxis.IsPortOpen)
{
rmaxis.Push(config.Force, config.Distance, config.Velocity);
}
if (moveInfo != null)
{
moveInfo.WaitList.Add(WaitResultInfo.WaitClampReached((int)config.Distance));
if (checkHasReel)
{
moveInfo.WaitList.Add(WaitResultInfo.WaitClampHasReel());
//有一个到位就算到位
moveInfo.OneWaitCanEndStep = true;
}
}
}
public bool IsReached()
{
try
{
if (rmaxis != null && rmaxis.IsPortOpen)
{
return rmaxis.IsReached;
}
}
catch (Exception ex)
{
LogUtil.error(Name + " IsReached error :" + ex.ToString());
}
return false;
}
public bool HasReel()
{
try
{
if (rmaxis != null && rmaxis.IsPortOpen)
{
return !rmaxis.IsPushEmpty;
}
}
catch (Exception ex)
{
LogUtil.error(Name + " IsReached error :" + ex.ToString());
}
return false;
}
public void Relax(LineMoveInfo moveInfo = null)
{
int p = 0;
if (rmaxis != null && rmaxis.IsPortOpen)
{
rmaxis.MoveAbsolute(p);
}
if (moveInfo != null)
{
moveInfo.WaitList.Add(WaitResultInfo.WaitClampReached(p));
}
}
public void GoHome(LineMoveInfo moveInfo = null)
{
if (rmaxis != null && rmaxis.IsPortOpen)
{
rmaxis.GoHome();
}
if (moveInfo != null)
{
moveInfo.WaitList.Add(WaitResultInfo.WaitClampReached(0));
}
}
public float GetPosition()
{
try
{
return rmaxis.GetPosition();
}
catch (Exception ex)
{
LogUtil.error(Name + " IsReached error :" + ex.ToString());
}
return -1;
}
public float GetTorque()
{
try
{
return rmaxis.GetTorque();
}
catch (Exception ex)
{
LogUtil.error(Name + " IsReached error :" + ex.ToString());
}
return -1;
}
public void PushTest(float force, float distance)
{
if (rmaxis != null && rmaxis.IsPortOpen)
{
rmaxis.Push(force, distance, config.Velocity);
}
}
public void Reset()
{
if (rmaxis != null && rmaxis.IsPortOpen)
{
rmaxis.ResetError();
}
}
public int GetErrorCode()
{
if (rmaxis != null && rmaxis.IsPortOpen)
{
return rmaxis.ErrorCode;
}
return 0;
}
}
}