UCStoreMachine.cs
8.5 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
using ConfigHelper;
using DeviceLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
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 TheMachine
{
public partial class UCStoreMachine : UserControl
{
StoreMachine Machine;
SIOControls sio;
AxisControl ac;
uc_boxdebug bd;
StoreSettingControl sc;
public event EventHandler<ListView.ListViewItemCollection> UpdateStatusList;
public UCStoreMachine(StoreMachine machine)
{
Machine = machine;
Machine.ProcessMsgEvent += Machine_ProcessMsgEvent;
Machine.PauseEvent += Machine_PauseEvent;
InitializeComponent();
RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
sio = new SIOControls(Machine);
ac = new AxisControl(Machine);
bd = new uc_boxdebug(Machine);
sc = new StoreSettingControl(Machine);
bd.Config = Machine.Config;
sio.Config = Machine.Config;
Common.AlertListViewSet(listView);
this.Tag = "not";
crc.LanguageChangeEvent += Crc_LanguageChangeEvent;
Machine_PauseEvent(this, Machine.UserPause);
}
private void Crc_LanguageChangeEvent(object sender, EventArgs e)
{
crc.LanguageProcess(this);
Machine_PauseEvent(this, Machine.UserPause);
}
private void Machine_ProcessMsgEvent(List<Msg> msg)
{
if (!this.Created)
return;
if (msg == null)
return;
try
{
this.Invoke((EventHandler<List<Msg>>)delegate(object s,List<Msg> msgs) {
SetMsg(msg);
},null,msg);
}
catch (Exception e)
{
LogUtil.info("MainMachine_ProcessMsgEvent:" + e.ToString());
}
}
void SetMsg(List<Msg> msgs)
{
//this.SuspendLayout();
listView.Items.Clear();
msgs.Sort((a, b) =>
{
if (a == null)
return 4;
if (b == null)
return 4;
if (a.msgLevel == MsgLevel.alarm)
return 1;
if (a.msgLevel == MsgLevel.warning)
return 2;
return 3;
});
foreach (Msg msg in msgs)
{
if (string.IsNullOrEmpty(msg.msgtxt) || msg.datetime == null)
continue;
ListViewItem lvi = new ListViewItem(new string[] { "", msg.datetime.ToString("HH:mm:ss"), msg.msgtxt });
if (msg.msgLevel == MsgLevel.info)
lvi.ForeColor = Color.DarkGreen;
else
lvi.ForeColor = Color.Red;
listView.Items.Add(lvi);
if (msg.errInfo == ErrInfo.X09_BoxNotDetect)
{
//btn_IgnoreX09.Visible = true;
}
else if (msg.errInfo == ErrInfo.X09_Clear)
{
//btn_IgnoreX09.Visible = false;
}
else if (msg.errInfo == ErrInfo.RunBtn || msg.errInfo == ErrInfo.ResetBtn)
{
Task.Run(() => {
if (!RobotManage.isRunning)
btn_run_Click(this, EventArgs.Empty);
});
}
else if (msg.errInfo == ErrInfo.SuddenStop)
{
Task.Run(() => {
if (RobotManage.isRunning)
//btn_run_Click(this, EventArgs.Empty);
btn_stop_Click(this, EventArgs.Empty);
});
}
}
//this.ResumeLayout(true);
UpdateStatusList?.Invoke(Machine.MachineSide, listView.Items);
Machine_PauseEvent(this, Machine.UserPause);
}
private void RobotManage_LoadFinishEvent(bool state, string msg)
{
if (!state)
return;
}
private void UCStoreMachine_Load(object sender, EventArgs e)
{
Config.PropertyBind($"Device_{Machine.MachineSide}_Disable", checkBox_disable, "Checked", "CheckedChanged");
AddForm("tab_sio", crc.GetString("Form1_tabc_tab_io_Text","IO调试"), sio);
AddForm("tab_axis",crc.GetString("Res0192","伺服调试"), ac);
AddForm("tab_store", crc.GetString("Res0193","库位调试"), bd);
AddForm("tab_setting", crc.GetString("Res0194","相关设置"), sc);
crc.LanguageProcess(this);
}
private void AddForm(string id, string text, UserControl form)
{
foreach (TabPage tp in tabc.TabPages)
{
if (tp.Name == id)
{
tp.Text = text;
return;
}
}
TabPage lineTabPage = new TabPage(text);
lineTabPage.Name = id;
Panel linePan = new Panel();
linePan.Dock = DockStyle.Fill;
linePan.AutoScroll = true;
lineTabPage.Controls.Add(linePan);
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();
tabc.TabPages.Add(lineTabPage);
}
private void Machine_PauseEvent(object sender, bool e)
{
if (this.InvokeRequired)
{
this.Invoke((EventHandler<bool>)delegate
{
Machine_PauseEvent(sender, e);
}, sender, e);
return;
}
btn_stop.Text = crc.GetString("UCStoreMachine_btn_stop_Text", "停止");
if (!Machine.isRunning) {
btn_stop.Enabled = false;
btn_run.Text = crc.GetString("Res0195","启动");
btn_run.BackColor = Color.Transparent;
return;
}
if (e)
{
//Machine.UserPause = true;
(btn_run as Button).Text = crc.GetString("Res0196","恢复运行");
(btn_run as Button).BackColor = Color.LightGreen;
}
else
{
//Machine.UserPause = false;
(btn_run as Button).Text = crc.GetString("Res0197","暂停运行");
(btn_run as Button).BackColor = Color.Yellow;
btn_stop.Enabled = true;
}
}
private void btn_run_Click(object sender, EventArgs e)
{
if (!Machine.isRunning)
{
//if (Machine.IOValue(IO_Type.SuddenStop_BTN, RobotManage.Config).Equals(IO_VALUE.LOW))
//{
// Machine.Msg.add(crc.GetString("Res0182","急停中,无法启动"), MsgLevel.warning);
// Machine_ProcessMsgEvent(Machine.Msg.get()[Machine.MachineSide]);
// return;
//}
RobotManage.Start(Machine.MachineSide);
if (Machine.isRunning)
{
btn_stop.Enabled = true;
Machine_PauseEvent(this, false);
//(sender as Button).Text = "暂停运行";
}
LogUtil.info("用户按下启动");
}
else {
Machine.UserPause=!Machine.UserPause;
}
}
private void btn_stop_Click(object sender, EventArgs e)
{
if (this.InvokeRequired)
{
this.Invoke((EventHandler)delegate
{
btn_stop_Click(sender, e);
}, sender, e);
return;
}
Task.Run(() => { Machine.Stop(); });
Machine_PauseEvent(this, Machine.UserPause);
//btn_stop.Enabled = false;
//btn_run.Text = "启动";
//btn_run.BackColor = Color.Transparent;
}
}
}