FrmMain.cs
11.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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DoubleLine
{
public partial class FrmMain : Form
{
private bool exit = false;
private NotifyIcon notify;
private ContextMenuStrip notifyMenu;
private Asa.File.Log log = Common.log;
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
//托盘菜单
notifyMenu = new ContextMenuStrip();
ToolStripMenuItem itemShow = new ToolStripMenuItem("显示(&S)");
itemShow.Click += ItemShow_Click;
ToolStripMenuItem itemExit = new ToolStripMenuItem("退出(&X)");
itemExit.Click += ItemExit_Click;
notifyMenu.Items.Add(itemShow);
notifyMenu.Items.Add(itemExit);
//托盘控件
notify = new NotifyIcon { Icon = Icon, Visible = true, ContextMenuStrip = notifyMenu, Text = Text };
notify.MouseDoubleClick += Notify_MouseDoubleClick;
DgvEmpty.Rows.Add("小料", "");
DgvEmpty.Rows.Add("大料", "");
DgvEmpty.Rows.Add("包装料", "");
DgvEmpty.Rows.Add("", "");
log.ShowText = TxtLog;
ChkUseAgv.Checked = true;
for (int i = 0; i < Common.ABB_Info.Length; i++)
DgvABB.Rows.Add(Common.ABB_Info[i].Name, Common.ABB_Info[i].IP, Common.ABB_Info[i].State, "", "");
for (int i = 0; i < Common.RFID_Info.Length; i++)
DgvRFID.Rows.Add(Common.RFID_Info[i].Name, Common.RFID_Info[i].IP, "", "", "Read", "");
for (int i = 0; i < Common.IO_Info.Length; i++)
DgvIO.Rows.Add(Common.IO_Info[i].Name, Common.IO_Info[i].IP, "");
//用于显示完界面后在打开
System.Threading.Thread tTemp = new System.Threading.Thread(new System.Threading.ThreadStart(Dev_Open));
tTemp.Name = "Dev_Open";
tTemp.Start();
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (!exit)
{
e.Cancel = true;
Hide();
}
}
private void ItemShow_Click(object sender, EventArgs e)
{
Show();
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
}
private void ItemExit_Click(object sender, EventArgs e)
{
Common.log.OutString("=====准备结束程序=====");
exit = true;
notify.Dispose();
Close();
}
private void Notify_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
}
private void BenqAGV_Status(bool status)
{
if (status)
LblAgvState.BackColor = Color.Lime;
else
LblAgvState.BackColor = Color.Red;
}
private void Dev_Open()
{
System.Threading.Thread.Sleep(50);
Application.DoEvents();
Common.BenqAGV.Status += BenqAGV_Status;
Common.Web.StatusEmpty += Web_StatusEmpty;
Common.ControlCenter.ABB_ActionChanged += ControlCenter_ABB_ActionChanged;
//ABB机器人
Common.ABB.StatusChanged += Robot_StatusChanged;
Common.ABB.ServerChanged += Robot_ServerChanged;
Common.ABB.Start();
//RFID
string[] rfid_ip = new string[Common.RFID_Info.Length];
for (int i = 0; i < Common.RFID_Info.Length; i++)
rfid_ip[i] = Common.RFID_Info[i].IP;
Common.RFID.ConnectStatus += ReaderAll_ConnectStatus;
Common.RFID.ScanStatus += ReaderAll_ScanStatus;
log.OutInfo("开启RFID");
Common.RFID.ScanMode = true;
Common.RFID.Open(rfid_ip);
//双层线
Common.LineDouble.Status += LineDouble_Status;
Common.LineDouble.Start();
//包装线
Common.LinePack.Status += LinePack_Status;
Common.LinePack.Start();
//出料皮带线
Common.LineDischarge.Status += DischargeLine_Status;
Common.LineDischarge.Start();
//控制中心
Common.ControlCenter.Start();
}
private void ControlCenter_ABB_ActionChanged(int idx, string s)
{
Invoke(new Action(() =>
{
DgvABB.Rows[idx].Cells[4].Value = s;
}));
}
private void Web_StatusEmpty(string[] s)
{
Invoke(new Action(() =>
{
//DgvABB.Rows[idx].Cells[2].Value = Common.ABB_Info[idx].State;
DgvEmpty.Rows[0].Cells[1].Value = s[0];
DgvEmpty.Rows[1].Cells[1].Value = s[1];
DgvEmpty.Rows[2].Cells[1].Value = s[2];
}));
}
private void ChkUseAgv_CheckedChanged(object sender, EventArgs e)
{
Common.LinePack.UseAgv(ChkUseAgv.Checked);
if (ChkUseAgv.Checked)
ChkUseAgv.BackColor = Color.Lime;
else
ChkUseAgv.BackColor = Color.Red;
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = Common.ControlCenter.TestBind();
}
#region ABB机器人
private void MnuABB_Click(object sender, EventArgs e)
{
FrmABB frm = new FrmABB { Text = MnuABB.Text };
frm.ShowDialog();
}
private void Robot_StatusChanged(int idx)
{
Invoke(new Action(() =>
{
DgvABB.Rows[idx].Cells[2].Value = Common.ABB_Info[idx].State;
}));
}
private void Robot_ServerChanged(int idx)
{
Invoke(new Action(() =>
{
bool rtn = Common.ABB_Info[idx].IsOpen;
DgvABB.Rows[idx].Cells[3].Value = rtn.ToString();
DgvABB.Rows[idx].Cells[3].Style.BackColor = rtn ? Color.Lime : Color.Red;
}));
}
private void BtnABBReload_Click(object sender, EventArgs e)
{
Common.ABB.LoadController();
}
#endregion
#region RFID
private void ReaderAll_ConnectStatus(int idx, string ip, bool status)
{
Invoke(new Action(() => {
Common.RFID_Info[idx].IsOpen = status;
DgvRFID.Rows[idx].Cells[2].Value = status.ToString();
DgvRFID.Rows[idx].Cells[2].Style.BackColor = status ? Color.Lime : Color.Red;
DgvRFID.Refresh();
}));
}
private void ReaderAll_ScanStatus(int idx, string ip, bool status)
{
Invoke(new Action(() => {
Common.RFID_Info[idx].IsScan = status;
DgvRFID.Rows[idx].Cells[3].Value = status.ToString();
DgvRFID.Rows[idx].Cells[3].Style.BackColor = status ? Color.Lime : Color.Red;
DgvRFID.Refresh();
}));
}
private void DgvRFID_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0) return;
if (e.ColumnIndex != 4) return;
string val = Common.RFID.ReadStr(Common.RFID_Info[e.RowIndex].IP);
DgvRFID.Rows[e.RowIndex].Cells[5].Value = val;
}
#endregion
#region 双层线
private void MnuDouble_Click(object sender, EventArgs e)
{
FrmDoubleLine frm = new FrmDoubleLine { Text = MnuDouble.Text };
frm.ShowDialog();
}
private void LineDouble_Status(int idx)
{
Invoke(new Action(() =>
{
DgvIO.Rows[idx].Cells[2].Value = Common.IO_Info[idx].Box.IsConn.ToString();
DgvIO.Rows[idx].Cells[2].Style.BackColor = Common.IO_Info[idx].Box.IsConn ? Color.Lime : Color.Red;
}));
}
#endregion
#region 包装线
private void MnuPackage_Click(object sender, EventArgs e)
{
FrmPackLine frm = new FrmPackLine { Text = MnuPackage.Text };
frm.ShowDialog();
}
private void LinePack_Status(int idx)
{
Invoke(new Action(() =>
{
DgvIO.Rows[idx].Cells[2].Value = Common.IO_Info[idx].Box.IsConn.ToString();
DgvIO.Rows[idx].Cells[2].Style.BackColor = Common.IO_Info[idx].Box.IsConn ? Color.Lime : Color.Red;
}));
}
#endregion
#region 出料线
private void DischargeLine_Status(int idx)
{
Invoke(new Action(() =>
{
DgvIO.Rows[idx].Cells[2].Value = Common.IO_Info[idx].Box.IsConn.ToString();
DgvIO.Rows[idx].Cells[2].Style.BackColor = Common.IO_Info[idx].Box.IsConn ? Color.Lime : Color.Red;
}));
}
#endregion
#region 功能
private void ChkServerPause_CheckedChanged(object sender, EventArgs e)
{
Common.ControlCenter.ServerPause = ChkServerPause.Checked;
}
private void BtnNeedD_Click(object sender, EventArgs e)
{
Common.LineDouble.NeedTypeD = DeviceAction.Start;
}
private void BtnNeedC_Click(object sender, EventArgs e)
{
Common.LineDouble.NeedTypeC = DeviceAction.Start;
}
private void BtnPlaceLeft_Click(object sender, EventArgs e)
{
Common.LineDouble.PlaceLeft = DeviceAction.Start;
}
private void BtnPlaceRight_Click(object sender, EventArgs e)
{
Common.LineDouble.PlaceRight = DeviceAction.Start;
}
private void BtnGoPlace1_Click(object sender, EventArgs e)
{
Common.LineDouble.GoPlace1 = DeviceAction.Start;
}
private void BtnGoPlace2_Click(object sender, EventArgs e)
{
Common.LineDouble.GoPlace2 = DeviceAction.Start;
}
private void BtnPlace1Place2_Click(object sender, EventArgs e)
{
Common.LineDouble.Place1ToPlace2 = DeviceAction.Start;
}
private void BtnPlace1Leave_Click(object sender, EventArgs e)
{
Common.LineDouble.Place1Leave = DeviceAction.Start;
}
private void BtnPlace2Leave_Click(object sender, EventArgs e)
{
Common.LineDouble.Place2Leave = DeviceAction.Start;
}
private void BtnPackingGoPlace_Click(object sender, EventArgs e)
{
Common.LinePack.GoPlace = DeviceAction.Start;
}
private void BtnPackingPlaceLeave_Click(object sender, EventArgs e)
{
Common.LinePack.PlaceLeave = DeviceAction.Start;
}
private void BtnPackingLeave_Click(object sender, EventArgs e)
{
Common.LinePack.Leave = true;
}
#endregion
}
}