FrmIoManager.cs
11.1 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
using log4net;
using URSoldering.Common;
using URSoldering.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
using UserFromControl;
using URSoldering.LoadCSVLibrary;
namespace URSoldering.Client
{
public partial class FrmIoManager : FrmBase
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public FrmIoManager()
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
LoadIOList();
timer1.Enabled = true;
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
}
Dictionary<string, IOTextControl> DIControlList = new Dictionary<string, IOTextControl>();
Dictionary<string, IOTextControl> DOControlList = new Dictionary<string, IOTextControl>();
private void LoadIOList()
{
int roleindex = 0;
this.tableLayoutPanel1.RowStyles.Clear();
this.tableLayoutPanel1.RowCount = RobotManager.robotConfig.RobotDIList.Count;
foreach (ConfigIO ioValue in RobotManager.robotConfig.RobotDIList.Values)
{
this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30));
IOTextControl control = new IOTextControl();
control.IOName = ioValue.ElectricalDefinition + "_" + ioValue.Explain;
control.IOValue = 0;
control.isCanClick = false;
control.Name = "IO_" + ioValue.DisplayStr;
control.Size = new System.Drawing.Size(200, 28);
control.TabIndex = 0;
this.tableLayoutPanel1.Controls.Add(control, 0, roleindex);
roleindex++;
DIControlList.Add(ioValue.ProName, control);
}
tableLayoutPanel2.RowStyles.Clear();
this.tableLayoutPanel2.RowCount = RobotManager.robotConfig.RobotDOList.Count;
roleindex = 0;
foreach (ConfigIO ioValue in RobotManager.robotConfig.RobotDOList.Values)
{
this.tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Absolute, 30));
IOTextControl control = new IOTextControl();
control.IOName = ioValue.ElectricalDefinition + "_" + ioValue.Explain;
control.IOValue = 0;
control.isCanClick = true;
//control.Location = new System.Drawing.Point(0, 25*roleindex);
control.Name = "IO_" + ioValue.DisplayStr;
control.Size = new System.Drawing.Size(200, 28);
control.TabIndex = 0;
this.tableLayoutPanel2.Controls.Add(control, 0, roleindex);
roleindex++;
DOControlList.Add(ioValue.ProName, control);
}
this.SuspendLayout(); //此处为不闪屏,一定要有的!
cmbWriteIO.DataSource = new List<ConfigIO>(RobotManager.robotConfig.RobotDOList.Values);
cmbWriteIO.ValueMember = "ProName";
cmbWriteIO.DisplayMember = "DisplayStr";
}
private void btnReadIO_Click(object sender, EventArgs e)
{
ReadIOList();
}
private void ReadIOList()
{
foreach (string key in DIControlList.Keys)
{
IOTextControl control = DIControlList[key];
int iov = (int)KNDManager.GetIOValue(RobotManager.robotConfig.RobotDIList[key]);
if (iov != control.IOValue)
{
control.IOValue = iov;
control.ShowData();
}
} foreach (string key in this.DOControlList.Keys)
{
IOTextControl control = DOControlList[key];
int iov = (int)KNDManager.GetIOValue(RobotManager.robotConfig.RobotDOList[key]);
if (iov != control.IOValue)
{
control.IOValue = iov;
control.ShowData();
}
}
}
private void btnWriteSingleDO_Click(object sender, EventArgs e)
{
string deviceName = txtDoName.Text;
int index = FormUtil.GetIntValue(txtDOIndex);
IO_VALUE value = IO_VALUE.LOW;
if (rdoHigh.Checked)
{
value = IO_VALUE.HIGH;
}
int time = FormUtil.GetIntValue(txtWriteTime);
int slaveId = FormUtil.GetIntValue(txtSlaveId);
if (time > 0)
{
KNDManager.WriteSingleDO(deviceName, (byte)slaveId, (ushort)index, (IO_VALUE)value, time);
}
else
{
KNDManager.WriteSingleDO(deviceName, (byte)slaveId, (ushort)index, (IO_VALUE)value);
}
}
private ConfigIO GetSelectDO()
{
string text = cmbWriteIO.SelectedValue.ToString();
if (RobotManager.robotConfig.RobotDOList.ContainsKey(text))
{
ConfigIO io = RobotManager.robotConfig.RobotDOList[text];
return io;
}
return null;
}
IOTextControl selectControl = null;
private void cmbWriteIO_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbWriteIO.SelectedIndex >= 0)
{
ConfigIO io = GetSelectDO();
if (io != null)
{
// txtIp.Text = io.DeviceName;
txtDOIndex.Text = io.ProVale.ToString();
txtDoName.Text = io.DeviceName;
txtSlaveId.Text = io.SlaveID.ToString();
if (selectControl != null)
{
selectControl.BorderStyle = System.Windows.Forms.BorderStyle.None;
}
IOTextControl newControl = DOControlList[io.ProName];
newControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
selectControl = newControl;
}
}
}
private void btnReadAllDi_Click(object sender, EventArgs e)
{
string deviceName = txtDoName.Text;
int slaveId = FormUtil.GetIntValue(txtSlaveId);
KNDManager.ReadMultipleDI(deviceName, (byte)slaveId, (ushort)KNDManager.DIStartAddress, 16);
}
private void btnReadAllDo_Click(object sender, EventArgs e)
{
string deviceName = txtDoName.Text;
int slaveId = FormUtil.GetIntValue(txtSlaveId);
KNDManager.ReadMultipleDO(deviceName, (byte)slaveId, (ushort)KNDManager.DoStartAddress, 16);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (RobotBean.ShuddenOK().Equals(false))
{
lblMsg.Text = "急停未开";
if (this.btnSendWireStop.Enabled)
{
FormStatus(false);
}
}
else
{
lblMsg.Text = "";
if (this.btnSendWireStop.Enabled == false)
{
FormStatus(true);
}
}
if (chbAutoRead.Checked)
{
ReadIOList();
}
}
private void FormStatus(bool isOpen)
{
this.btnSendWireStop.Enabled = isOpen;
this.btnWDown.Enabled = isOpen;
this.btnWUp.Enabled = isOpen;
this.btnTestSend.Enabled = isOpen;
this.btnSendWire.Enabled = isOpen;
this.btnStopSend.Enabled = isOpen;
this.btnWStop.Enabled = isOpen;
groupBox4.Enabled = isOpen;
btnFixtureStop.Enabled = isOpen;
btnWireWork.Enabled = isOpen;
}
private void btnSendWire_Click(object sender, EventArgs e)
{
double speed = FormUtil.getDoubleValue(txtSpeed);
double length = FormUtil.getDoubleValue(txtSendWireLength);
SendWireManager.setLength(length);
SendWireManager.setSpeed(speed);
SendWireManager.StartFSend();
}
private void btnStopSend_Click(object sender, EventArgs e)
{
SendWireManager.StopSend();
}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
if (!IsHandleCreated)
{
this.Close();
}
}
private void btnTestSend_Click(object sender, EventArgs e)
{
int speed = FormUtil.GetIntValue(txtSpeed);
int length = FormUtil.GetIntValue(txtSendWireLength);
SendWireManager.setLength(length);
SendWireManager.setSpeed(speed);
SendWireManager.StartBSend();
}
private void btnCloseForm_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnClean_Click(object sender, EventArgs e)
{
SendWireCylinderMove(IO_VALUE.LOW, IO_VALUE.LOW);
}
private void SolderingCylinderMove(IO_VALUE down,IO_VALUE up)
{
RobotBean.KNDIOMove(IO_Type.Soldering_Down, down);
RobotBean.KNDIOMove(IO_Type.Soldering_Up, up);
}
private void FixtureCylinderMove(IO_VALUE clamp, IO_VALUE relax)
{
RobotBean.KNDIOMove(IO_Type.Fixture_Clamp, clamp);
RobotBean.KNDIOMove(IO_Type.Fixture_Relax, relax);
}
private void SendWireCylinderMove(IO_VALUE work, IO_VALUE clear)
{
RobotBean.KNDIOMove(IO_Type.SendWire_Work, work);
RobotBean.KNDIOMove(IO_Type.SendWire_Clear, clear);
}
private void btnWDown_Click(object sender, EventArgs e)
{
SolderingCylinderMove(IO_VALUE.HIGH, IO_VALUE.LOW);
}
private void btnWUp_Click(object sender, EventArgs e)
{
SolderingCylinderMove(IO_VALUE.LOW, IO_VALUE.HIGH);
}
private void btnWStop_Click(object sender, EventArgs e)
{
SolderingCylinderMove(IO_VALUE.LOW, IO_VALUE.LOW);
}
private void btnFixtureClamp_Click(object sender, EventArgs e)
{
FixtureCylinderMove(IO_VALUE.HIGH, IO_VALUE.LOW);
}
private void btnFixtureReleax_Click(object sender, EventArgs e)
{
FixtureCylinderMove(IO_VALUE.LOW, IO_VALUE.HIGH);
}
private void btnFixtureStop_Click(object sender, EventArgs e)
{
FixtureCylinderMove(IO_VALUE.LOW, IO_VALUE.LOW);
}
private void btnWireWork_Click(object sender, EventArgs e)
{
SendWireCylinderMove(IO_VALUE.HIGH, IO_VALUE.LOW);
}
private void btnWireClear_Click(object sender, EventArgs e)
{
SendWireCylinderMove(IO_VALUE.LOW, IO_VALUE.HIGH);
}
}
}