FrmOrgConfig.cs
9.5 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
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
using log4net;
using URSoldering.Common;
using URSoldering.DeviceLibrary;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using URSoldering.Common.util;
using System.IO;
using System.Drawing.Drawing2D;
using URSoldering.LoadCSVLibrary;
using System.Threading.Tasks;
using System.Timers;
using HalconDotNet;
namespace URSoldering.Client
{
public partial class FrmOrgConfig : FrmBase
{
private bool isAuto = false;
private bool isConnect = false;
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public FrmOrgConfig( )
{
InitializeComponent();
}
private System.Timers.Timer timer1 = new System.Timers.Timer();
private void FrmBoardInfo_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
//此界面打开时,不能打开自动焊接
if (WeldRobotBean.ISRun)
{
LogUtil.error("进入焊接界面,发现WeldRobotBean自动运行中,关闭自动运行");
WeldRobotBean.StopRun();
}
if (EpsonDevice.IsRun)
{
EpsonDevice.FreeAxis();
EpsonDevice.GetPosition(AfterGet);
}
else
{
//btnChange.Text = "机器人连接中。。。";
RobotStatus(false);
}
isAuto = false;
timer1.Interval = 1000;
timer1.AutoReset = true;
timer1.Elapsed += timer_Elapsed;
timer1.Start();
timer2.Start();
}
private void AfterMove(string result)
{
}
private void AfterGet(double x, double y, double z, double u, int hand)
{
PointValue point = new PointValue(x, y, u, z, hand);
//PointValue point = EpsonDevice.LastPoint;
this.txtRobotX.Text = point.X.ToString();
this.txtRobotY.Text = point.Y.ToString();
this.txtRobotU.Text = point.U.ToString();
this.txtRobotZ.Text = point.Z.ToString();
string msg = WeldRobotBean.CheckEpsonPoint(point);
if (point.HandDir.Equals(1))
{
cmbHand.SelectedIndex = 0;
}
else
{
cmbHand.SelectedIndex = 1;
}
if (point.X != 0 && isConnect == false)
{
EpsonDevice.FreeAxis();
isConnect = true;
RobotStatus(true);
}
}
private void RobotStatus(bool isConnect)
{
}
private bool isRun = false;
private void timer_Elapsed(object sender, EventArgs e)
{
if (!EpsonDevice.IsRun && isRun.Equals(false))
{
Task.Factory.StartNew(delegate ()
{
string result = EpsonDevice.Start();
if (result != "")
{
LogUtil.info("连接失败:" + result);
}
else
{
EpsonDevice.FreeAxis();
isAuto = false;
}
});
isRun = true;
}
else
{
//EpsonControl.FreeAxis();
EpsonDevice.GetPosition(AfterGet);
}
}
private void FrmBoardInfo_FormClosing(object sender, FormClosingEventArgs e)
{
EpsonDevice.LockAxis();
timer2.Stop();
timer1.Stop();
UsbCameraHDevelop.CloseAllCamera();
}
private void btnRead_Click(object sender, EventArgs e)
{
EpsonDevice.GetPosition(AfterGet);
}
private void timer2_Tick(object sender, EventArgs e)
{
if (EpsonDevice.IsRun)
{
}
}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
if (this.IsDisposed)
{
this.Close();
}
}
private void btnSetOrigin_Click(object sender, EventArgs e)
{
saveOriginInfo();
}
private void saveOriginInfo()
{
ConfigAppSettings.SaveValue(Setting_Init.BOARD_ORIGIN_X, txtRobotX.Text);
ConfigAppSettings.SaveValue(Setting_Init.BOARD_ORIGIN_Y, txtRobotY.Text);
}
private void btnGoHome_Click(object sender, EventArgs e)
{
if (isAuto == false)
{
MessageBox.Show("请先切换到自动模式!");
return;
}
RobotBean.KNDIOMove(IO_Type.SendWire_Down, IO_VALUE.LOW);
RobotBean.KNDIOMove(IO_Type.SendWire_Up, IO_VALUE.HIGH);
double x = WeldRobotBean.EpsonOrgX;
double y = WeldRobotBean.EpsonOrgY;
double z = WeldRobotBean.EpsonOrgZ;
double u = WeldRobotBean.EpsonOrgU;
int hand = WeldRobotBean.EpsonOrgHandDir;
if (x != 0 && y != 0 && z != 0 && u != 0)
{
EpsonDevice.MoveTo(x, y, z, u, false, hand,AfterMove);
}
else
{
MessageBox.Show("原点坐标无效!");
}
}
private void btnSaveHome_Click(object sender, EventArgs e)
{
double orgx = FormUtil.getDoubleValue(txtRobotX);
double orgy = FormUtil.getDoubleValue(txtRobotY);
double orgu = FormUtil.getDoubleValue(txtRobotU);
double orgz = FormUtil.getDoubleValue(txtRobotZ);
//判断原点的Z轴
if (orgz > EpsonDevice.Robot_LIM_Z)
{
MessageBox.Show("保存失败,原点Z坐标(" + orgz + ")不能高于最高Z点(" + EpsonDevice.Robot_LIM_Z + ")");
return;
}
int hand =GetHand();
DialogResult result = MessageBox.Show("是否将当前位置X:" + orgx + ",Y:" + orgy + ",U:" + orgu + ",Z:" + orgz + "," + cmbHand.Text + "保存为原点?", "提示", MessageBoxButtons.YesNo);
if (result.Equals(DialogResult.Yes))
{
WeldRobotBean.UpdateOrgPoint(orgx, orgy, orgu, orgz, hand);
MessageBox.Show("保存原点成功!");
}
}
private int GetHand()
{
if (cmbHand.SelectedIndex >= 0)
{
return cmbHand.SelectedIndex + 1;
}
else
{
return 0;
}
}
private void btnSetClear1_Click(object sender, EventArgs e)
{
double clearx = FormUtil.getDoubleValue(txtRobotX);
double cleary = FormUtil.getDoubleValue(txtRobotY);
double clearu = FormUtil.getDoubleValue(txtRobotU);
double clearz = FormUtil.getDoubleValue(txtRobotZ);
//判断原点的Z轴
if (clearz > EpsonDevice.Robot_LIM_Z)
{
MessageBox.Show("保存失败,清洗点1的Z坐标(" + clearz + ")不能高于最高Z点(" + EpsonDevice.Robot_LIM_Z + ")");
return;
}
int hand = GetHand();
DialogResult result = MessageBox.Show("是否将当前位置X:" + clearx + ",Y:" + cleary + ",U:" + clearu + ",Z:" + clearz + "," + cmbHand.Text + "保存为清洗点1?", "提示", MessageBoxButtons.YesNo);
if (result.Equals(DialogResult.Yes))
{
WeldRobotBean.UpdateClear1Point(clearx, cleary, clearu, clearz, hand);
MessageBox.Show("保存清洗点1成功!");
}
}
private void btnSetClear2_Click(object sender, EventArgs e)
{
double clearx = FormUtil.getDoubleValue(txtRobotX);
double cleary = FormUtil.getDoubleValue(txtRobotY);
double clearu = FormUtil.getDoubleValue(txtRobotU);
double clearz = FormUtil.getDoubleValue(txtRobotZ);
//判断原点的Z轴
if (clearz > EpsonDevice.Robot_LIM_Z)
{
MessageBox.Show("保存失败,清洗点2的Z坐标(" + clearz + ")不能高于最高Z点(" + EpsonDevice.Robot_LIM_Z + ")");
return;
}
int hand = GetHand();
DialogResult result = MessageBox.Show("是否将当前位置X:" + clearx + ",Y:" + cleary + ",U:" + clearu + ",Z:" + clearz + "," + cmbHand.Text + "保存为清洗点2?", "提示", MessageBoxButtons.YesNo);
if (result.Equals(DialogResult.Yes))
{
WeldRobotBean.UpdateClear2Point(clearx, cleary, clearu, clearz, hand);
MessageBox.Show("保存清洗点2成功!");
}
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnMore_Click(object sender, EventArgs e)
{
FrmPwd frmOrgConfig = new FrmPwd();
this.Visible = false;
frmOrgConfig.ShowDialog();
this.Visible = true;
}
}
}