FrmShuoKeDebug.cs
10.8 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
using URSoldering.Common;
using URSoldering.DeviceLibrary;
using URSoldering.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace URSoldering.Client
{
public partial class FrmShuoKeDebug : FrmBase
{
public FrmShuoKeDebug()
{
InitializeComponent();
}
private URSolderingRobot Robot = null;
private bool isDebug = true ;
private int SendWireAddr = WeldRobotBean.RobotConfig.SendWire_Slv;
private int LineAddr = 2;
private void btnOpen_Click(object sender, EventArgs e)
{
ShuoKeControls.InitPort(comboBoxPortName.Text);
if (ShuoKeControls.isRun)
{
WeldRobotBean.InitSendWireSpeed();
Robot.InitLineSpeed();
FormComStatus(true);
}
else
{
MessageBox.Show("打开串口"+comboBoxPortName.Text+"失败");
}
}
private void FormComStatus(bool isOpen)
{
btnOpen.Enabled = !isOpen;
btnClose.Enabled = isOpen;
btnRelMove.Enabled = isOpen;
btnClearPosition.Enabled = isOpen;
btnVolMove.Enabled = isOpen;
btnGetPosition.Enabled = isOpen;
btnHomeMove.Enabled = isOpen;
btnLineAbsMove.Enabled = isOpen;
btnStatusSearch.Enabled = isOpen;
groupBox1.Enabled = isOpen;
groupBox6.Enabled = isOpen;
groupBox2.Enabled = isOpen;
timer1.Enabled = isOpen;
}
private void btnClose_Click(object sender, EventArgs e)
{
ShuoKeControls.SuddownStop(SendWireAddr);
ShuoKeControls.SuddownStop(LineAddr);
ShuoKeControls.ClosePort();
FormComStatus(false);
}
private void btnVolMove_Click(object sender, EventArgs e)
{
int speed = FormUtil.GetIntValue(txtWireSpeed) * WeldRobotBean.SendWireXiShu;
ShuoKeControls.VolMove(SendWireAddr, speed);
}
private void btnGetPosition_Click(object sender, EventArgs e)
{
int addr = SendWireAddr;
if (radioButton2.Checked)
{
addr = LineAddr;
}
ShuoKeControls.GetABSPosition(addr);
}
private void btnStop_Click(object sender, EventArgs e)
{
ShuoKeControls.SuddownStop(SendWireAddr);
}
private void btnClearPosition_Click(object sender, EventArgs e)
{
int addr = SendWireAddr;
if (radioButton2.Checked)
{
addr = LineAddr;
}
ShuoKeControls.PositionClear(addr, ShuoKeCMD.AbsPositionClear);
ShuoKeControls.PositionClear(addr, ShuoKeCMD.RelPositionClear);
}
private void btnHomeMove_Click(object sender, EventArgs e)
{
int addr = SendWireAddr;
if (radioButton2.Checked)
{
addr = LineAddr;
}
ShuoKeControls.HomeMove(addr, byte.Parse(cmbHomeType.Text));
}
private void btnLineAbsMove_Click(object sender, EventArgs e)
{
int posi = FormUtil.GetIntValue(txtWirePosition);
ShuoKeControls.AbsMove(SendWireAddr, posi);
}
private void btnStatusSearch_Click(object sender, EventArgs e)
{
ShuoKeControls.GetStatus(SendWireAddr);
}
private void btnLineAbsMove_Click_1(object sender, EventArgs e)
{
int addr = SendWireAddr;
if (radioButton2.Checked)
{
addr = LineAddr;
}
int posi = FormUtil.GetIntValue(txtPosition);
ShuoKeControls.AbsMove(addr, posi);
}
private void btnRelMove_Click(object sender, EventArgs e)
{
int posi = FormUtil.GetIntValue(txtWirePosition) * WeldRobotBean.SendWireXiShu;
ShuoKeControls.RelativeMove(SendWireAddr, posi);
}
private void txtAddr_TextChanged(object sender, EventArgs e)
{
SendWireAddr = FormUtil.GetIntValue(txtWireAddr);
if (SendWireAddr <= 0)
{
MessageBox.Show("地址只能是大于0的数字!");
SendWireAddr = WeldRobotBean.RobotConfig.SendWire_Slv;
txtWireAddr.Text = SendWireAddr.ToString();
}
}
//private IO_VALUE sendWirePointMove = IO_VALUE.LOW;
private void timer1_Tick(object sender, EventArgs e)
{
if (this.Visible.Equals(false))
{
return;
}
if (ShuoKeControls.isRun.Equals(false))
{
return;
}
if (RobotBean.ShuddenOK().Equals(false))
{
lblMsg.Text = "急停未开";
}
else
{
lblMsg.Text = ShuoKeControls.LastMsg;
CheckSendWireAlarm();
}
}
/// <summary>
/// 检测送丝错误
/// </summary>
private void CheckSendWireAlarm()
{
//如果休眠了不需要处理
if (RobotBean.KNDIOValue(IO_Type.SendWireLock).Equals(IO_VALUE.HIGH))
{
//停止运动
lblMsg.Text = "送丝报警:卡丝,停止匀速运动";
LogUtil.info("送丝报警:卡丝,停止匀速运动");
//sendWirePointMove = IO_VALUE.LOW;
ShuoKeControls.SuddownStop(SendWireAddr);
}
else if (RobotBean.KNDIOValue(IO_Type.SendWireNoWire).Equals(IO_VALUE.HIGH))
{
lblMsg.Text = "送丝报警:无丝,停止匀速运动";
//停止运动
LogUtil.info("送丝报警:无丝,停止匀速运动");
//sendWirePointMove = IO_VALUE.LOW;
ShuoKeControls.SuddownStop(SendWireAddr);
}
}
private void FrmShuoKe_Load(object sender, EventArgs e)
{
Robot = RobotManager.SolderingRobot;
txtLineSpeed.Text =(0- Robot.Config.Line_EndSpeed).ToString();
LineAddr = Robot.Config.Line_Slv;
this.groupBox2.Visible = isDebug;
this.btnStatusSearch.Visible = true;
txtLineAddr.Text = LineAddr.ToString();
txtWireAddr.Text = SendWireAddr.ToString();
LoadData();
radioButton1_CheckedChanged(null, null);
}
private void LoadData()
{
cmbHomeType.SelectedIndex = 0;
List<string> port = new List<string>(SerialPort.GetPortNames());
comboBoxPortName.DataSource = port;
string portStr = WeldRobotBean.RobotConfig.ShuoKe_PortName;
if (port.IndexOf(portStr) >= 0)
{
comboBoxPortName.SelectedIndex = port.IndexOf(portStr);
}
if (ShuoKeControls.isRun)
{
FormComStatus(true);
}
else
{
FormComStatus(false);
}
}
private void btnSetSpeed_Click(object sender, EventArgs e)
{
//设置速度
int startSpeed = FormUtil.GetIntValue(txtBeginSpeed);
int endSpeed = FormUtil.GetIntValue(txtTargetSpeed);
int maxSpeed = FormUtil.GetIntValue(txtMaxSpeed);
int addSpeed = FormUtil.GetIntValue(txtAddSpeed);
int delSpeed = FormUtil.GetIntValue(txtDelSpeed);
int addr = SendWireAddr;
if (radioButton2.Checked)
{
addr = LineAddr;
}
ShuoKeControls.SetSpeed(addr, ShuoKeCMD.SetAddSpeed, addSpeed);
Thread.Sleep(100);
ShuoKeControls.SetSpeed(addr, ShuoKeCMD.SetDelSpeed, delSpeed);
Thread.Sleep(100);
ShuoKeControls.SetSpeed(addr, ShuoKeCMD.SetEndSpeed, endSpeed);
Thread.Sleep(100);
ShuoKeControls.SetSpeed(addr, ShuoKeCMD.SetMaxSpeed, maxSpeed);
Thread.Sleep(100);
ShuoKeControls.SetSpeed(addr, ShuoKeCMD.SetStartSpeed, startSpeed);
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnSet_Click(object sender, EventArgs e)
{
int speed = FormUtil.GetIntValue(txtWireSpeed) * WeldRobotBean.SendWireXiShu;
SendWireAddr = FormUtil.GetIntValue(txtWireAddr);
ShuoKeControls.SetMoveSpeed(SendWireAddr, speed);
}
private void btnLineStop_Click(object sender, EventArgs e)
{
ShuoKeControls.SuddownStop(LineAddr);
}
private void btnLineRelMove_Click(object sender, EventArgs e)
{
int position = FormUtil.GetIntValue(txtLinePosition);
ShuoKeControls.RelativeMove(LineAddr, position);
}
private void btnLineSpeedMove_Click(object sender, EventArgs e)
{
int speed = FormUtil.GetIntValue(txtLineSpeed);
ShuoKeControls.VolMove(LineAddr, speed);
}
private void btnLineSetSpeed_Click(object sender, EventArgs e)
{
int speed = FormUtil.GetIntValue(txtLineSpeed);
ShuoKeControls.SetMoveSpeed(LineAddr, speed);
}
private void button2_Click(object sender, EventArgs e)
{
ShuoKeControls.GetStatus(LineAddr);
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
this.txtBeginSpeed.Text = WeldRobotBean.RobotConfig.SendWire_StartSpeed.ToString();
this.txtTargetSpeed.Text = WeldRobotBean.RobotConfig.SendWire_EndSpeed.ToString();
this.txtMaxSpeed.Text = WeldRobotBean.RobotConfig.SendWire_MaxSpeed.ToString();
this.txtAddSpeed.Text = WeldRobotBean.RobotConfig.SendWire_AddSpeed.ToString();
this.txtDelSpeed.Text = WeldRobotBean.RobotConfig.SendWire_DelSpeed.ToString();
}
else
{
this.txtBeginSpeed.Text = Robot.Config.Line_StartSpeed.ToString();
this.txtTargetSpeed.Text = Robot.Config.Line_EndSpeed.ToString();
this.txtMaxSpeed.Text = Robot.Config.Line_MaxSpeed.ToString();
this.txtAddSpeed.Text = Robot.Config.Line_AddSpeed.ToString();
this.txtDelSpeed.Text = Robot.Config.Line_DelSpeed.ToString();
}
}
}
}