FrmMain.cs
13.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
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Common;
using DeviceLibrary;
using System.Collections.Generic;
namespace AGVControl
{
public partial class FrmMain : Form
{
private bool exit = false;
private bool change;
private NotifyIcon notify;
private ContextMenuStrip notifyMenu;
private System.Timers.Timer showTimer;
public FrmMain()
{
InitializeComponent();
showTimer = new System.Timers.Timer();
showTimer.Interval = 2000;
showTimer.Enabled = true;
showTimer.AutoReset = true;
showTimer.Elapsed += ShowTimer_Elapsed;
showTimer.Start();
DeviceLibrary.Context.control.limitArea.ScopeLimitStateChangedEvent += LimitArea_ScopeLimitStateChangedEvent;
}
/// <summary>
/// 限制区域有小车
/// </summary>
/// <param name="ip"></param>
private void LimitArea_ScopeLimitStateChangedEvent(string ip, bool state)
{
Invoke(new Action(() =>
{
if (DeviceLibrary.Context.control.limitArea.Available)
lblLimit.Text = "限制区域车辆:";
else
{
lblLimit.Text = "限制区域车辆:" + ip;
}
}
));
}
static Dictionary<string, Form> agvManual = new Dictionary<string, Form>();
private void ShowConfig()
{
int n;
for (int i = 0; i < DeviceLibrary.Context.agvInfo.Count; i++)
{
MiR_API.Get_IO_Status(DeviceLibrary.Context.agvInfo[i], out bool[] input, out bool[] output);
if (input != null && input.Length == 4)
DeviceLibrary.Context.agvInfo[i].IsExistShelf = input[3];
flowPanelKanBan.Controls.Add(DeviceLibrary.Context.agvInfo[i].StateKanban);
//AddForm(DeviceLibrary.Context.agvInfo[i].Name, new Manual(DeviceLibrary.Context.agvInfo[i]));
DeviceLibrary.Context.agvInfo[i].StateKanban.Init();
Context.agvInfo[i].StateKanban.Click += StateKanban_Click;
agvManual.Add(DeviceLibrary.Context.agvInfo[i].Name, new Manual(DeviceLibrary.Context.agvInfo[i]));
}
for (int i = 0; i < DeviceLibrary.Context.nodeInfo.Count; i++)
{
Agv.ClientNode node = DeviceLibrary.Context.nodeInfo[i];
if (node.Name.StartsWith("MP"))
continue;
n = DgvNode.Rows.Add(node.LineName, node.Action, node.Shelf, node.RFID, node.Online, node.IsUse);
DgvNode.Rows[n].HeaderCell.Value = (n + 1).ToString();
if (i % 2 == 0)
DgvNode.Rows[n].DefaultCellStyle.BackColor = Color.LightBlue;
if (!DeviceLibrary.Context.nodeInfo[i].Online)
DgvNode.Rows[n].DefaultCellStyle.ForeColor = Color.Red;
}
}
private void StateKanban_Click(object sender, EventArgs e)
{
if (sender is AGV_UI.Status)
{
AGV_UI.Status status = (AGV_UI.Status)sender;
if (agvManual[status.AGVName].IsDisposed)
{
Agv_Info agv = Context.agvInfo.Find(s => s.Name.Equals(status.AGVName));
if(agv !=null)
{
agvManual[status.AGVName] = new Manual(agv);
agvManual[status.AGVName].Show();
}
}
else
agvManual[status.AGVName].Show();
}
}
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 DeviceLibrary.Context.agvInfo)
{
DeviceLibrary.Context.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();
change = true;
change = false;
DeviceLibrary.Context.server.NodeChanged += Server_NodeChanged; ;
DeviceLibrary.Context.server.NodeOnline += Server_NodeOnline; ;
string ip = AppConfigHelper.GetValue(SettingString.AGVServerIp);
int port = AppConfigHelper.GetIntValue(SettingString.AGVServerPort);
DeviceLibrary.Context.server.Start(ip, port);
LogUtil.logBox = richTextBox1;
}
private void Server_NodeOnline(string nodeName, bool online)
{
this.Invoke(new Action(() =>
{
int idx = DeviceLibrary.Context.nodeInfo.FindIndex(s => s.Name.Equals(nodeName));
if (idx > -1)
{
DeviceLibrary.Context.nodeInfo[idx].Online = online;
bool isuse = DeviceLibrary.Context.nodeInfo[idx].IsUse;
DgvNode.Rows[idx].DefaultCellStyle.ForeColor = online && isuse ? Color.Black : Color.Red;
DgvNode.Rows[idx].SetValues(DeviceLibrary.Context.nodeInfo[idx].LineName, DeviceLibrary.Context.nodeInfo[idx].Action, DeviceLibrary.Context.nodeInfo[idx].Shelf, DeviceLibrary.Context.nodeInfo[idx].RFID, DeviceLibrary.Context.nodeInfo[idx].Online, DeviceLibrary.Context.nodeInfo[idx].IsUse);
}
}
));
}
private void Server_NodeChanged(Agv.Node clientNode)
{
int idx = DeviceLibrary.Context.nodeInfo.FindIndex(s => s.Name.Equals(clientNode.Name));
if (idx > -1)
{
DeviceLibrary.Context.nodeInfo[idx].Action = clientNode.Action;
DeviceLibrary.Context.nodeInfo[idx].Shelf = clientNode.Shelf;
DeviceLibrary.Context.nodeInfo[idx].RFID = clientNode.RFID;
DgvNode.Rows[idx].SetValues(DeviceLibrary.Context.nodeInfo[idx].LineName, DeviceLibrary.Context.nodeInfo[idx].Action, DeviceLibrary.Context.nodeInfo[idx].Shelf, DeviceLibrary.Context.nodeInfo[idx].RFID, DeviceLibrary.Context.nodeInfo[idx].Online, DeviceLibrary.Context.nodeInfo[idx].IsUse);
}
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (!exit)
{
e.Cancel = true;
Hide();
}
foreach (var item in DeviceLibrary.Context.agvInfo)
{
DeviceLibrary.Context.WriteIni(item.Name, SettingString.RFID, item.RFID);
}
//showTimer.Enabled = false;
showTimer.Stop();
// CommonVar.control.AgvChanged -= Control_AgvChanged;
DeviceLibrary.Context.server.NodeChanged -= Server_NodeChanged;
DeviceLibrary.Context.server.NodeOnline -= Server_NodeOnline;
}
private void DgvNode_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1) return;
if (e.ColumnIndex == DgvNode.Columns.Count - 1) //调用
{
DeviceLibrary.Context.nodeInfo[e.RowIndex].IsUse = !DeviceLibrary.Context.nodeInfo[e.RowIndex].IsUse;
DgvNode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = DeviceLibrary.Context.nodeInfo[e.RowIndex].IsUse.ToString();
DeviceLibrary.Context.WriteIni(DeviceLibrary.Context.nodeInfo[e.RowIndex].Name, SettingString.IsUse, DeviceLibrary.Context.nodeInfo[e.RowIndex].IsUse.ToString());
Agv.ClientNode node = DeviceLibrary.Context.nodeInfo[e.RowIndex];
DgvNode.Rows[e.RowIndex].SetValues(node.LineName, node.Action, node.Shelf, node.RFID, node.Online, node.IsUse);
}
}
bool InShhow = false;
Dictionary<string, string> destInfoMap = new Dictionary<string, string>();
private void ShowTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//ShowEmptyTask();
if (InShhow)
return;
InShhow = true;
BoxDestInfo destInfo;
Agv.ClientNode node;
Invoke(new Action(() =>
{
node = DeviceLibrary.Context.nodeInfo.Find(s => s.Name.Equals(SettingString.D2));
if (!destInfoMap.ContainsKey(SettingString.D2))
{
if (RequestManager.FindFullShelfTarget(node.RFID, out destInfo))
{
label1.Text = destInfo.ToString();
destInfoMap.Add(SettingString.D2, node.RFID);
}
else
{
label1.Text = "";
}
}
else if (!destInfoMap[SettingString.D2].Equals(node.RFID))
{
if (RequestManager.FindFullShelfTarget(node.RFID, out destInfo))
{
label1.Text = destInfo.ToString();
destInfoMap[SettingString.D2] = node.RFID;
}
else
{
label1.Text = "";
}
}
node = DeviceLibrary.Context.nodeInfo.Find(s => s.Name.Equals(SettingString.D4));
if (!destInfoMap.ContainsKey(SettingString.D4))
{
if (RequestManager.FindFullShelfTarget(node.RFID, out destInfo))
{
label2.Text = destInfo.ToString();
destInfoMap.Add(SettingString.D4, node.RFID);
}
else
{
label2.Text = "";
}
}
else if (!destInfoMap[SettingString.D4].Equals(node.RFID))
{
if (RequestManager.FindFullShelfTarget(node.RFID, out destInfo))
{
label2.Text = destInfo.ToString();
destInfoMap[SettingString.D4] = node.RFID;
}
else
{
label2.Text = "";
}
}
}));
Application.DoEvents();
InShhow = false;
}
/// <summary>
/// 添加窗体
/// </summary>
/// <param name="text"></param>
/// <param name="form"></param>
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);
//tabControlAGV.Controls.Add(lineTabPage);
}
private void button1_Click(object sender, EventArgs e)
{
label3.Text = "";
if (textBox1.Text.Equals(""))
return;
if (RequestManager.AgvRemoveRfid(textBox1.Text.ToUpper()))
{
LogUtil.info("手动清理料架缓存:" + textBox1.Text.ToUpper());
label3.Text = "清理料架缓存成功:" + textBox1.Text.ToUpper();
label3.BackColor = Color.Green;
}
else
{
label3.Text = "清理料架缓存失败:" + textBox1.Text.ToUpper();
label3.BackColor = Color.Red;
}
textBox1.Text = "";
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 1)
LogUtil.logBox = richTextBox1;
}
}
}