FrmMain.cs
18.4 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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common;
using DeviceLibrary;
namespace AGVControl
{
public partial class FrmMain : Form
{
private bool exit = false;
private NotifyIcon notify;
private ContextMenuStrip notifyMenu;
private System.Timers.Timer showTimer;
//private string[] agvRunStep;
public FrmMain()
{
InitializeComponent();
showTimer = new System.Timers.Timer();
showTimer.Interval = 5000;
//showTimer.Enabled = true;
showTimer.AutoReset = true;
showTimer.Elapsed += ShowTimer_Elapsed;
showTimer.Start();
LogUtil.logBox = richTextBox1;
}
private void ShowConfig()
{
int n;
//agvRunStep = new string[Common.agvInfo.Count];
for (int i = 0; i < AGVManager.agvInfo.Count; i++)
{
MiR_API.Get_IO_Status(AGVManager.agvInfo[i], out bool[] input, out bool[] output);
if (input != null && input.Length == 4)
AGVManager.agvInfo[i].IsExistShelf = input[3];
flowLayoutPanel1.Controls.Add(AGVManager.agvInfo[i].StateKanban);
AddForm(AGVManager.agvInfo[i].Name,new Manual(AGVManager.agvInfo[i]));
AGVManager.agvInfo[i].StateKanban.Init();
}
for (int i = 0; i < AGVManager.nodeInfo.Count; i++)
{
n = DgvNode.Rows.Add(AGVManager.nodeInfo[i].ToRow());
DgvNode.Rows[n].HeaderCell.Value = (n + 1).ToString();
if (i % 2 == 0)
DgvNode.Rows[n].DefaultCellStyle.BackColor = Color.LightBlue;
if (!AGVManager.nodeInfo[i].Online)
DgvNode.Rows[n].DefaultCellStyle.ForeColor = Color.Red;
if (AGVManager.nodeInfo[i].Name.StartsWith(SettingString.DoubleLine_Name_Prefix) || AGVManager.nodeInfo[i].Name.StartsWith(SettingString.RoomDFeederIn))
continue;
cmbBoxLineName.Items.Add(AGVManager.nodeInfo[i].AliceName);
}
}
private void Server_NodeChanged(int nodeIndex)
{
Invoke(new Action(() =>
{
DgvNode.Rows[nodeIndex].DefaultCellStyle.ForeColor = AGVManager.nodeInfo[nodeIndex].Online && AGVManager.nodeInfo[nodeIndex].IsUse ? Color.Black : Color.Red;
DgvNode.Rows[nodeIndex].SetValues(AGVManager.nodeInfo[nodeIndex].ToRow());
}));
System.GC.Collect();
}
private void Server_NodeOnline(int nodeIndex)
{
Invoke(new Action(() =>
{
DgvNode.Rows[nodeIndex].DefaultCellStyle.ForeColor = AGVManager.nodeInfo[nodeIndex].Online ? Color.Black : Color.Red;
DgvNode.Rows[nodeIndex].SetValues(AGVManager.nodeInfo[nodeIndex].ToRow());
}));
System.GC.Collect();
}
private void ItemShow_Click(object sender, EventArgs e)
{
Show();
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
}
private void ItemExit_Click(object sender, EventArgs e)
{
foreach (var item in AGVManager.agvInfo)
{
AGVManager.WriteIni(item.Name, SettingString.RFID, item.RFID);
}
notify.Dispose();
exit = true;
Close();
}
private void Notify_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
}
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;
ShowConfig();
AGVManager.server.NodeChanged += Server_NodeChanged;
AGVManager.control.NodeChangedEvent += Server_NodeChanged;
AGVManager.server.NodeOnline += Server_NodeOnline;
ReadUnlockLineInfo();
}
void ReadUnlockLineInfo()
{
if (!System.IO.File.Exists(AGVManager.CONFIG_PATH + "UnlockInfo.json"))
{
File.Create(AGVManager.CONFIG_PATH + "UnlockInfo.json");
AGVManager.unlockManager = new UnlockMissionManager(AGVManager.nodeInfo);
AGVManager.unlockManager.MissionChanged += MissionManager_MissionChanged;
return;
}
string s = File.ReadAllText(AGVManager.CONFIG_PATH + "UnlockInfo.json");
AGVManager.unlockManager = JsonHelper.DeserializeJsonToObject<UnlockMissionManager>(s);
if (AGVManager.unlockManager == null)
AGVManager.unlockManager = new UnlockMissionManager(AGVManager.nodeInfo);
AGVManager.unlockManager.MissionChanged += MissionManager_MissionChanged;
AGVManager.unlockManager.Init();
}
private void MissionManager_MissionChanged(Dictionary<string, UnlockInfo> pairs)
{
BindingSource bs = new BindingSource();
BindingSource bs2 = new BindingSource();
try
{
dgvUnlockInfo.BeginInvoke(new MethodInvoker(delegate
{
foreach (var item in pairs.Values)
{
if (item.Count > 0)
{
bs.Add(item);
foreach (var item1 in item.UnlockRfids)
{
bs2.Add(item1);
}
}
}
dgvUnlockInfo.DataSource = bs; //赋值控件自动更新
dgvUnlockDetail.DataSource = bs2;
}));
this.Invoke(new Action(() =>
{
//grpUnlock.Text = "解绑总数:"+count;
}
));
}
catch (Exception e)
{
LogUtil.error("ShowUnlockInfo", e);
}
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (!exit)
{
e.Cancel = true;
Hide();
}
foreach (var item in AGVManager.agvInfo)
{
AGVManager.WriteIni(item.Name, SettingString.RFID, item.RFID);
}
LogUtil.logBox = null;
//showTimer.Enabled = false;
showTimer.Stop();
AGVManager.server.NodeChanged -= Server_NodeChanged;
AGVManager.server.NodeOnline -= Server_NodeOnline;
}
private void DgvNode_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1) return;
if (e.ColumnIndex == 7) //调用
{
AGVManager.nodeInfo[e.RowIndex].IsUse = !AGVManager.nodeInfo[e.RowIndex].IsUse;
DgvNode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = AGVManager.nodeInfo[e.RowIndex].IsUse.ToString();
AGVManager.WriteIni(AGVManager.nodeInfo[e.RowIndex].Name, SettingString.IsUse, AGVManager.nodeInfo[e.RowIndex].IsUse.ToString());
DgvNode.Rows[e.RowIndex].SetValues(AGVManager.nodeInfo[e.RowIndex].ToRow());
}
}
bool InShhow = false;
private void ShowTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//ShowEmptyTask();
if (InShhow)
return;
InShhow = true;
Invoke(new Action(() =>
{
Application.DoEvents();
//if (!Common.doubleLine_WO.Equals(""))
lblWO.Text = AGVManager.doubleLine_WO;
// if (!AGVManager.A6_Target.Equals(""))
lblDestInfo.Text = HttpManager.A6_Target;
lblCharge3.Text = "充电桩3:" ;
lblCharge4.Text = "充电桩6:" ;
lblStandy1.Text = "4C待机位1:" ;
lblStandy2.Text = "4C待机位2:" ;
lblWarn.Text = AGVManager.warnMsg;
}));
InShhow = false;
}
/// <summary>
/// 删除绑定
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDeleteMission_Click(object sender, EventArgs e)
{
try
{
if (cmbBoxLineName.SelectedItem == null || cmbBoxLineName.SelectedIndex == 0)
{
return;
}
if (MessageBox.Show("确定删除产线任务[" + cmbBoxLineName.SelectedItem.ToString() + "]", "手动删除解绑任务", MessageBoxButtons.YesNo) == DialogResult.No)
return;
if (txtRfid.Text.ToUpper().StartsWith("D") || txtRfid.Text.ToUpper().StartsWith("C"))
{
int idx = AGVManager.nodeInfo.FindIndex(s => s.AliceName.Equals(cmbBoxLineName.SelectedItem.ToString()));
if (idx > -1)
{
if (AGVManager.unlockManager.DelMission(AGVManager.nodeInfo[idx].Name, txtRfid.Text.ToUpper()))
{
LogUtil.info(string.Format("手动删除任务成功:{0} {1}", cmbBoxLineName.SelectedItem.ToString(), txtRfid.Text.ToUpper()));
}
else
{
LogUtil.info("手动删除任务失败");
}
}
}
}
catch (Exception ex)
{
LogUtil.error("手动删除任务失败:" + ex.Message);
}
}
/// <summary>
/// 添加解绑任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAddMission_Click(object sender, EventArgs e)
{
try
{
if (cmbBoxLineName.SelectedItem == null || cmbBoxLineName.SelectedIndex == 0 || txtRfid.Text.Equals(""))
{
return;
}
if (cmbBoxLineName.SelectedItem.ToString().StartsWith("A"))
return;
if (MessageBox.Show("确定添加产线任务[" + cmbBoxLineName.SelectedItem.ToString() + "]", "手动添加解绑", MessageBoxButtons.YesNo) == DialogResult.No)
return;
if (txtRfid.Text.ToUpper().StartsWith(SettingString.SmallShelf_Prefix) || txtRfid.Text.ToUpper().StartsWith(SettingString.BigShelf_Prefix))
{
int idx = AGVManager.nodeInfo.FindIndex(s => s.AliceName.Equals(cmbBoxLineName.SelectedItem.ToString()));
if (idx > -1)
{
if (AGVManager.unlockManager.AddMission(AGVManager.nodeInfo[idx].Name, txtRfid.Text.ToUpper()))
{
LogUtil.info(string.Format("手动添加任务成功:{0} {1}", cmbBoxLineName.SelectedItem.ToString(), txtRfid.Text.ToUpper()));
}
else
{
LogUtil.info("手动添加任务失败");
}
}
}
}
catch (Exception ex)
{
LogUtil.error("手动添加任务失败:" + ex.Message);
}
}
private void btnWO_Click(object sender, EventArgs e)
{
try
{
Task.Factory.StartNew(new Action(() =>
{
if (HttpManager.FindCurSO(out HttpManager.WOData woData))
{
if (AGVManager.GetNodeNameByLineName(woData.line, out string loc))
{
AGVManager.doubleLine_WO = "工单料信息:" + woData.ToTxt(loc);
LogUtil.info(AGVManager.doubleLine_WO);
}
}
}));
}
catch (Exception ex)
{
MessageBox.Show("查询失败:" + ex.Message + "\r\n" + ex.StackTrace);
}
}
/// <summary>
/// 出料查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button5_Click(object sender, EventArgs e)
{
try
{
Task.Factory.StartNew(() =>
{
int idx = AGVManager.nodeInfo.FindIndex(s => s.Name.Equals(SettingString.A6));
if (idx > -1)
{
HttpManager.FindFullShelfTarget(AGVManager.nodeInfo[idx].RFID, out HttpManager.BoxDestInfo FullShelfDestInfo);
}
});
}
catch (Exception ex)
{
MessageBox.Show("查询失败:" + ex.Message + "\r\n" + ex.StackTrace);
}
}
private void btnUpdateStatus_Click(object sender, EventArgs e)
{
try
{
Task.Factory.StartNew(() =>
{
bool rtn = HttpManager.UpdateStatus(txtBoxRFID.Text.ToUpper(), txtBoxLineName.Text.ToUpper());
this.Invoke(new Action(() => { label11.Text = rtn ? "状态上报成功" : "状态上报失败"; }));
LogUtil.info(string.Format("手动上报状态 产线{0} 物料状态更新成功[{1}]", txtBoxLineName.Text.ToUpper(), txtBoxRFID.Text.ToUpper()));
txtBoxLineName.Text = "";
txtBoxRFID.Text = "";
});
}
catch (Exception ex)
{
MessageBox.Show("手动上报状态失败:" + ex.Message + "\r\n" + ex.StackTrace);
}
}
private void btnGetStationRfid_Click(object sender, EventArgs e)
{
if (txtBoxLineName.Text.Equals(""))
return;
try
{
Task.Factory.StartNew(new Action(() => {
string res = HttpManager.GetRFIDs(txtBoxLineName.Text.ToUpper());
this.Invoke(new Action(() => { label11.Text = string.Format("由里到外料架顺序:{0}", res); }));
}));
}
catch { }
}
private void btnClearStationRFID_Click(object sender, EventArgs e)
{
if (!txtBoxLineName.Text.Equals("") && !txtBoxRFID.Text.Equals("") && AGVManager.GetNodeNameByLineName(txtBoxLineName.Text.ToUpper(),out string nodename))
{
try
{
Task.Factory.StartNew(new Action(() => {
bool rtn = HttpManager.ClearRFID(nodename, txtBoxRFID.Text.ToUpper());
this.Invoke(new Action(() => { label11.Text = rtn ? "清除接驳RFID成功:" + txtBoxLineName.Text + " " + txtBoxRFID.Text : "清除接驳RFID失败:" + txtBoxLineName.Text + " " + txtBoxRFID.Text; }));
txtBoxLineName.Text = "";
txtBoxRFID.Text = "";
LogUtil.info(rtn ? "手动清除接驳RFID成功:" + txtBoxLineName.Text + " " + txtBoxRFID.Text : "手动清除接驳RFID失败:" + txtBoxLineName.Text + " " + txtBoxRFID.Text);
}));
}
catch { }
}
}
private void agvRemoveRfid_Click(object sender, EventArgs e)
{
try
{
Task.Factory.StartNew(() =>
{
if(txtBoxRFID.Text.StartsWith("C") || txtBoxRFID.Text.StartsWith("D"))
{
bool rtn = HttpManager.AgvRemoveRfid(txtBoxRFID.Text.ToUpper());
this.Invoke(new Action(() => { label11.Text = rtn ? "清理料架的缓存信息成功" : "清理料架的缓存信息失败"; }));
LogUtil.info(string.Format("手动清理料架的缓存信息成功[{0}]", txtBoxRFID.Text.ToUpper()));
}
txtBoxLineName.Text = "";
txtBoxRFID.Text = "";
});
}
catch (Exception ex)
{
}
}
private void AddForm(string text, Form form)
{
text = text.PadLeft(10, ' ');
TabPage lineTabPage = new TabPage(text);
// lineTabPage.AutoScroll = true;
// lineTabPage.Tag = lineBean;
Panel linePan = new Panel();
linePan.Dock = DockStyle.Fill;
linePan.AutoScroll = true;
lineTabPage.Controls.Add(linePan);
form.FormBorderStyle = FormBorderStyle.None;
form.TopLevel = false;
linePan.Controls.Add(form);
//form.Dock = DockStyle.Fill;
//linePan.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
//form.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
form.Show();
// tabPageList.Add(lineTabPage);
tabControlManual.Controls.Add(lineTabPage);
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 1)
{
LogUtil.logBox = this.richTextBox1;
}
}
}
}