Manual.cs
7.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DeviceLibrary;
using Common;
namespace AGVControl
{
public partial class Manual : Form
{
public Manual(Agv_Info agv)
{
InitializeComponent();
Agv = agv;
chkBxAuto.Checked = agv.IsUse;
btnReSendTask.Enabled = agv.IsUse;
btnAssignTask.Enabled = !agv.IsUse;
}
Agv_Info Agv;
bool isInit = false;
private void Manual_Load(object sender, EventArgs e)
{
lblInfo.Text = string.Format("[{0}]", Agv.IP);
cmbBxMission.Items.AddRange(DeviceLibrary.Context.showNameMissionName.Values.ToArray());
cmbBxMission.SelectedIndex = 0;
InState.AddRange(new PictureBox[] { pictureBox1,pictureBox2,pictureBox3,pictureBox4});
OutState.AddRange(new PictureBox[] { pictureBox5, pictureBox6, pictureBox7, pictureBox8 });
timer1.Enabled = true;
isInit = true;
}
private void chkBxAuto_CheckedChanged(object sender, EventArgs e)
{
if (!isInit) return;
this.Invoke(new Action(() =>
{
btnReSendTask.Enabled = chkBxAuto.Checked;
btnAssignTask.Enabled = !chkBxAuto.Checked;
if (!chkBxAuto.Checked)//自动-》手动
{
if (Agv.IsCon)
{
MiR_API.Del_Mission(Agv);
//添加Init任务
LogUtil.info(string.Format("{0} 运行模式改变:自动-》手动", Agv.Name));
Agv.AssignTask(SettingString.Init);
}
DeviceLibrary.Context.Standby.DelOccupyInfo(Agv.Name);
DeviceLibrary.Context.Charge.DelOccupyInfo(Agv.Name);
}
else
{
//if (Agv.IsExistShelf)
//{
// LogUtil.error(string.Format("{0} 车上有负载,无法开启自动模式,请先清空小车负载!", Agv.Name));
// return;
//}
// if (MessageBox.Show(this, "是否继续上一次的任务?\r\n" + Agv.Msg, "提示", MessageBoxButtons.YesNo).Equals(DialogResult.No))
{
LogUtil.info(string.Format("{0} 运行模式改变:手动-》自动【不继续上一次任务:{1}】", Agv.Name, Agv.Msg));
Agv.CurJob = null;
if (Agv.Place.Equals(SettingString.Standby) || Agv.Place.Equals(SettingString.AutoCharge))
Agv.Place = "";
if (Agv.IsCon)
{
MiR_API.Del_Mission(Agv);
}
Agv.RFID = "";
}
//else
//{
// if (Agv.IsCon)
// {
// Agv.Resend();
// LogUtil.info(string.Format("{0} 运行模式改变:手动-》自动【继续上一次任务:{1}】", Agv.Name, Agv.Msg));
// }
//}
}
Agv.IsUse = chkBxAuto.Checked;
}));
}
private void btnReSendTask_Click(object sender, EventArgs e)
{
if (Agv.IsCon)
{
if (MessageBox.Show("确定对小车重发任务?", Agv.Name, MessageBoxButtons.YesNo) == DialogResult.No)
return;
Task.Factory.StartNew(new Action(()=> {
MiR_API.Clear_Error(Agv);
System.Threading.Thread.Sleep(1000);
MiR_API.State_Ready(Agv);
Agv.Resend();
LogUtil.info(string.Format("{0} 手动重发任务", Agv.Name));
}));
}
}
private void btnReady_Click(object sender, EventArgs e)
{
if (Agv.IsCon)
{
MiR_API.State_Ready(Agv);
LogUtil.info(string.Format("{0} 手动点击运行", Agv.Name));
}
}
private void btnPause_Click(object sender, EventArgs e)
{
if (Agv.IsCon)
{
MiR_API.State_Pause(Agv);
LogUtil.info(string.Format("{0} 手动点击暂停", Agv.Name));
}
}
private void btnClearErr_Click(object sender, EventArgs e)
{
if (Agv.IsCon)
{
MiR_API.Clear_Error(Agv);
LogUtil.info(string.Format("{0} 手动点击清除按钮", Agv.Name));
}
}
private void btnAssignTask_Click(object sender, EventArgs e)
{
if (Agv.IsCon)
{
try
{
var key = Context.showNameMissionName.Where(qq => qq.Value == cmbBxMission.SelectedItem.ToString()).Select(qq => qq.Key);
string taskName = key.ToList()[0];
if(!DeviceLibrary.Context.agvMission.Keys.Contains(taskName))
{
LogUtil.error("无选定任务: "+ taskName);
return;
}
if (taskName.Equals(SettingString.Enter) || taskName.Equals(SettingString.Leave))
if (MessageBox.Show("确定对小车发送进/出任务?", Agv.Name, MessageBoxButtons.YesNo) == DialogResult.No)
return;
Agv.AssignTask(taskName);
Agv.StateKanban.ShowInfo("目的地", "");
LogUtil.info(string.Format("{0} 手动发任务 {1}", Agv.Name, taskName));
}
catch(Exception ex)
{
LogUtil.error("手动发任务 ",ex);
}
}
}
private void btnExit_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
Close();
Dispose();
}
List<PictureBox> InState = new List<PictureBox>();
List<PictureBox> OutState = new List<PictureBox>();
private void timer1_Tick(object sender, EventArgs e)
{
this.Invoke(new Action(() => {
try
{
if (Agv.IOInState != null && Agv.IOInState.Length == 4)
{
for (int i = 0; i < Agv.IOInState.Length; i++)
{
if (Agv.IOInState[i])
{
InState[i].Image = AGVDispatch.Properties.Resources.green1;
}
else
{
InState[i].Image = AGVDispatch.Properties.Resources.gray2;
}
}
}
if (Agv.IOOutState != null && Agv.IOOutState.Length == 4)
{
for (int i = 0; i < Agv.IOOutState.Length; i++)
{
if (Agv.IOOutState[i])
{
OutState[i].Image = AGVDispatch.Properties.Resources.green1;
}
else
{
OutState[i].Image = AGVDispatch.Properties.Resources.gray2;
}
}
}
}
catch { }
}));
}
}
}