uc_boxdebug.cs
16.3 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
using DeviceLibrary;
using log4net;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TheMachine
{
public partial class uc_boxdebug : UserControl
{
private Robot_Config _Config;
public Robot_Config Config
{
get { return _Config; }
set
{
if (value == null)
return;
_Config = value;
storePosControl1.Config = _Config;
Init();
}
}
Dictionary<string,PosState> posState = new Dictionary<string, PosState>();
//如果总配置文件存在,保存到总的配置文件
static string appPath = Application.StartupPath;
string positionConfigFile { get; }
class PosState {
public int InStoreCheck = 0;
public int OutStoreCheck = 0;
}
public uc_boxdebug()
{
InitializeComponent();
Setting_Init.Device_DisableUpdownProtect=false;
positionConfigFile = Path.Combine(appPath, "config\\Magzine.csv");
}
public void Init()
{
try
{
FillBoxPos();
RobotManage.mainMachine.InOutEndProcessEvent += Store_InOutEndProcessEvent;
timer1.Enabled = true;
}
catch(Exception ex) {
MessageBox.Show(crc.GetString("Res0211","库位表解析错误"));
LogUtil.error(Name + " " + ex.ToString());
}
if (!RobotManage.haveFixpos)
cb_fixpos.Visible = false;
return;
}
private void Store_InOutEndProcessEvent(string arg1, StoreMoveType arg2, bool arg3)
{
//LogUtil.info($"出入库完成状态:{arg2},库位:{arg1}");
int InStoreCheck = 0;
int OutStoreCheck = 0;
if (arg2 == StoreMoveType.PutReel)
InStoreCheck = 1;
else if (arg2 == StoreMoveType.OutStore)
OutStoreCheck = 1;
var pps = SavePosCheck(arg1, InStoreCheck, OutStoreCheck);
if (htpp.ContainsKey(arg1))
{
var pp = (PosPos)htpp[arg1];
var cells = dataGridView1.Rows[pp.row].Cells[pp.col];
cells.Style = GetStyle(arg1);
}
checkVerify();
}
DataGridViewCellStyle GetStyle(string posid) {
if (htpp.ContainsKey(posid) && posState.ContainsKey(posid))
{
var pp = (PosPos)htpp[posid];
var pps = (PosState)posState[posid];
var cells = dataGridView1.Rows[pp.row].Cells[pp.col];
cells.Selected = true;
if (pps.InStoreCheck == 1 && pps.OutStoreCheck == 1)
return dgv_ok;
else if (pps.InStoreCheck == 1)
return dgv_oin;
else if (pps.OutStoreCheck == 1)
return dgv_oout;
}
return dgv_none;
}
void checkVerify()
{
int finish = 0;
for (int i = 0; i < RobotManage.AllPosList.Count; i++)
{
var posid = RobotManage.AllPosList[i];
if (htpp.ContainsKey(posid) && posState.ContainsKey(posid))
{
var pps = (PosState)posState[posid];
if (pps.InStoreCheck == 1 && pps.OutStoreCheck == 1)
{
finish++;
}
}
}
double s = (double)finish * 100 / RobotManage.AllPosList.Count;
label_verify.Text = s.ToString("0.0") + "%";
}
Hashtable htpp = new Hashtable();
class PosPos {
public string Posid;
public int index;
public int row;
public int col;
}
void LoadPosCheck() {
var poscheckfile = positionConfigFile + ".check";
if (File.Exists(poscheckfile))
{
try
{
posState = JsonHelper.DeserializeJsonToObject<Dictionary<string, PosState>>(File.ReadAllText(poscheckfile));
File.Copy(poscheckfile, poscheckfile + ".backup", true);
}
catch {
if (File.Exists(poscheckfile + ".backup"))
{
File.Copy(poscheckfile + ".backup", poscheckfile, true);
File.Delete(poscheckfile + ".backup");
LoadPosCheck();
}
}
}
else
{
File.WriteAllText(poscheckfile, JsonHelper.SerializeObject(posState));
}
}
PosState SavePosCheck(string posid,int inStoreCheck,int outStoreCheck) {
if (!posState.ContainsKey(posid))
posState.Add(posid, new PosState());
if (inStoreCheck>0)
posState[posid].InStoreCheck = inStoreCheck;
if (outStoreCheck > 0)
posState[posid].OutStoreCheck = outStoreCheck;
var poscheckfile = positionConfigFile + ".check";
File.WriteAllText(poscheckfile, JsonHelper.SerializeObject(posState));
return posState[posid];
}
static Font font = new Font("宋体",10);
DataGridViewCellStyle dgv_ok = new DataGridViewCellStyle() { BackColor = Color.LightGreen, Font = font };
DataGridViewCellStyle dgv_oin = new DataGridViewCellStyle() { BackColor = Color.LightGray, Font = font };
DataGridViewCellStyle dgv_oout = new DataGridViewCellStyle() { BackColor = Color.LightSeaGreen, Font = font };
DataGridViewCellStyle dgv_none = new DataGridViewCellStyle() { BackColor = Color.White,Font= font };
void FillBoxPos()
{
htpp.Clear();
dataGridView1.Columns.Clear();
dataGridView1.Rows.Clear();
LoadPosCheck();
int colcount = 6;
for (int i = 0; i < colcount; i++)
{
dataGridView1.Columns.Add("Col" + i, "Col" + i);
}
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
dataGridView1.Rows.Add();
int currentRowIndex = 0;
int currentColIndex = -1;
string lastAB = "";
for (int i = 0; i < RobotManage.AllPosList.Count; i++)
{
string posname = RobotManage.AllPosList[i];
string ab = posname.Substring(0, 2);
//if (posname.StartsWith("Sca") || posname.StartsWith("Doo"))
//{
// ab = "aa";
//}
//string memo = "";
//string memo = CSVPositionReader<ACStorePosition>.allPositionMap[posname].memo;
var showname = posname;
if (ab != lastAB)
{
currentRowIndex = 0;
currentColIndex++;
string headerText = crc.GetString("Res0090", "其他取放料口");
headerText = ab;
lastAB = ab;
string[] posArray = posname.Split('_');
//if (posArray.Length >= 2)
//{
// headerText = posArray[0];
//}
//if (posname.StartsWith("L"))
//{
// dataGridView1.Columns[currentColIndex].HeaderText = crc.GetString(memo, memo) + "(" + posname.Substring(0, 2) + ")";
//}
//else
{
dataGridView1.Columns[currentColIndex].HeaderText = headerText;
}
}
//if (!posname.StartsWith("L"))
{
showname = posname ;
}
var currentRow = dataGridView1.Rows[currentRowIndex];
currentRow.Cells[currentColIndex].Value = showname;
currentRow.Cells[currentColIndex].Tag = posname;
htpp.Add(posname, new PosPos() { Posid = posname, index = i, row = currentRowIndex, col = currentColIndex });
currentRow.Cells[currentColIndex].Style = GetStyle(posname);
currentRowIndex++;
if (currentRowIndex >= dataGridView1.Rows.Count)
dataGridView1.Rows.Add();
}
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
if (dataGridView1.Rows[0].Cells[i].Value == null)
{
dataGridView1.Columns[i].Width = 0;
}
}
if (dataGridView1.Rows[0].Cells[dataGridView1.Columns.Count - 1].Value != null)
{
dataGridView1.Rows[0].Cells[dataGridView1.Columns.Count - 1].Selected = true;
}
else if (dataGridView1.Rows[0].Cells[dataGridView1.Columns.Count - 2].Value != null)
{
dataGridView1.Rows[0].Cells[dataGridView1.Columns.Count - 2].Selected = true;
}
dataGridView1.Rows.RemoveAt(dataGridView1.Rows.Count - 1);
if (dataGridView1.SelectedCells.Count > 0)
setData(dataGridView1.SelectedCells[0].Tag.ToString());
checkVerify();
}
void setData(string posid) {
ACStorePosition ktkPosition = CSVPositionReader<ACStorePosition>.GetPositon(posid);
cmbPosition.Text = posid;
label_size.Text = $"[{ktkPosition.BagWidth}x{ktkPosition.BagHigh}]";
storePosControl1.LoadPos(ktkPosition);
if (ktkPosition.PosType.Equals(1))
{
groupInout.Enabled = false;
}
else
{
groupInout.Enabled = true;
}
}
private void btnInStore_Click(object sender, EventArgs e)
{
if (RobotManage.mainMachine.runStatus == RunStatus.Running)
{
string posName = cmbPosition.Text;
LogUtil.info($"入库位:{cmbPosition.Text},posName:{posName}");
string startPosname = "IN_1";
if (radioButton2.Checked)
{
startPosname = "IN_2";
}
if (RobotManage.mainMachine.ManualTest(startPosname, posName, out string errmsg))
{
LogUtil.info($"手动入库:{posName}");
}
else
{
MessageBox.Show(errmsg);
}
}
else
{
MessageBox.Show(crc.GetString("Res0213","请先启动料仓!"));
}
}
private void btnOutStore_Click(object sender, EventArgs e)
{
//if (RobotManage.mainMachine.runStatus == RunStatus.Running)
//{
// int posindex = RobotManage.AllPosList.IndexOf(cmbPosition.Text);
// LogUtil.info($"出库位:{cmbPosition.Text},index:{posindex}");
// if (RobotManage.mainMachine.ManualOut(posindex,out string errmsg)) {
// LogUtil.info($"手动出库:{posindex}");
// }
// else
// {
// MessageBox.Show(errmsg);
// }
//}
//else
//{
// MessageBox.Show(crc.GetString("Res0213","请先启动料仓!"));
//}
}
bool preOpen = false;
private void timer1_Tick(object sender, EventArgs e)
{
if (!Visible)
return;
if (!cb_inoutdebugmode.Checked)
return;
if (RobotManage.mainMachine.AutoInOutTest)
{
btnOutStore.Enabled = false;
btnInStore.Enabled = false;
btn_autoinout.Text = crc.GetString("Res0214","停止自动库位测试");
}
else
{
btnOutStore.Enabled = true;
btnInStore.Enabled = true;
btn_autoinout.Text = crc.GetString("Res0215","自动库位测试");
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex<0 || dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag == null)
return;
var posid = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag.ToString();
setData(posid);
}
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex < 0 || dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag == null)
return;
var posid = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag.ToString();
setData(posid);
}
private void cb_inoutdebugmode_CheckedChanged(object sender, EventArgs e)
{
RobotManage.InoutDebugMode = cb_inoutdebugmode.Checked;
if (!cb_inoutdebugmode.Checked)
{
RobotManage.mainMachine.AutoInOutTest = false;
}
btnInStore.Enabled= cb_inoutdebugmode.Checked;
btnOutStore.Enabled= cb_inoutdebugmode.Checked;
btn_autoinout.Enabled=cb_inoutdebugmode.Checked;
}
private void btn_autoinout_Click(object sender, EventArgs e)
{
if (RobotManage.mainMachine.AutoInOutTest)
{
RobotManage.mainMachine.StopAutoInOutTest();
MessageBox.Show(crc.GetString("Res0216","自动出入库过程会再料盘送至出口后自动停止."));
return;
}
if (RobotManage.mainMachine.runStatus == RunStatus.Running)
{
if (RobotManage.mainMachine.IOValue(IO_Type.IN_1_Reel_Check).Equals(IO_VALUE.LOW)|| RobotManage.mainMachine.IOValue(IO_Type.IN_2_Reel_Check).Equals(IO_VALUE.LOW))
{
MessageBox.Show(crc.GetString("Res0217","料盘没有准备好,请先点击[上料准备],无法启动"));
return;
}
DialogResult res = MessageBox.Show(crc.GetString("Res0218","确定开始自动库位测试?\n请确保料架库位全部为空."), crc.GetString("Res0167","提示"), MessageBoxButtons.YesNo);
if (res == DialogResult.No)
{
return;
}
string posName = cmbPosition.Text;
//int posindex = RobotManage.AllPosList.IndexOf(cmbPosition.Text);
LogUtil.info($"库位:{cmbPosition.Text},index:{posName}");
if (!RobotManage.mainMachine.StartAutoTest(posName, out string errmsg))
{
MessageBox.Show(errmsg);
return;
}
(sender as Button).Text = crc.GetString("Res0219","停止自动库位测试!");
}
else
{
MessageBox.Show(crc.GetString("Res0213","请先启动料仓!"));
}
}
private void cb_disableupdownprotect_CheckedChanged(object sender, EventArgs e)
{
//RobotManage.DisableUpdownProtect = cb_disableupdownprotect.Checked;
//LogUtil.info("手动点击屏蔽升降轴旋转轴安全检测:"+ cb_disableupdownprotect.Checked.ToString());
}
private void cb_fixpos_SelectedIndexChanged(object sender, EventArgs e)
{
if (cb_fixpos.SelectedItem!=null)
setData(cb_fixpos.SelectedItem.ToString());
}
}
}