liufu
authored
|
1
|
using HHWCS.Bll;
|
liufu
authored
|
2
|
using HHWCS.Model;
|
liufu
authored
|
3
4
|
using HHWCSHost.Controls;
using OPCHelper;
|
liufu
authored
|
5
|
using System;
|
liufu
authored
|
6
|
using System.Collections.Generic;
|
liufu
authored
|
7
|
using System.Configuration;
|
liufu
authored
|
8
|
using System.Linq;
|
liufu
authored
|
9
|
using System.Threading;
|
liufu
authored
|
10
|
using System.Threading.Tasks;
|
liufu
authored
|
11
|
using System.Timers;
|
liufu
authored
|
12
13
|
using System.Windows;
using System.Windows.Controls;
|
liufu
authored
|
14
|
using System.Windows.Media;
|
liufu
authored
|
15
|
using LEDhelp;
|
liufu
authored
|
16
17
18
19
20
21
22
23
|
namespace HHWCSHost.View
{
/// <summary>
/// Frm_Main.xaml 的交互逻辑
/// </summary>
public partial class Frm_Main : Window
{
|
liufu
authored
|
24
25
|
#region 属性
|
liufu
authored
|
26
27
|
//const string plcAdressPrefix = "S7:[S7 connection_1]";
private object locker = new object();
|
liufu
authored
|
28
|
|
liufu
authored
|
29
30
|
//所有子窗口
Dictionary<string, Window> windows = new Dictionary<string, Window>();
|
liufu
authored
|
31
|
private System.Timers.Timer timer = new System.Timers.Timer();
|
liufu
authored
|
32
33
34
35
36
37
38
|
int inTimer = 0;
//OPC相关
/// <summary>
/// OPC地址
/// </summary>
public string PLCIP { get; set; }
|
liufu
authored
|
39
|
public OPCHelp PLC { get; set; }
|
liufu
authored
|
40
41
42
|
/// <summary>
/// 创建item后返回的索引值,需要用到这个去进行数据读取
/// </summary>
|
liufu
authored
|
43
|
public int[] ServerHandle { get; set; }
|
liufu
authored
|
44
45
|
//堆垛机
|
liufu
authored
|
46
|
//public List<StockerMonitor> StockerMonitors { get; set; }
|
liufu
authored
|
47
48
49
50
51
52
53
|
public LogInfo LogInfo { get; set; }
public List<DeviceAddressEntity> DeviceAddressEntities { get; set; }
public List<DeviceEntity> DeviceEntities { get; set; }
public List<DevicePropEntity> DevicePropEntities { get; set; }
public List<DeviceTypeEntity> DeviceTypeEntities { get; set; }
|
liufu
authored
|
54
|
|
liufu
authored
|
55
56
57
58
59
|
/// <summary>
/// 时钟控制器
/// </summary>
bool stop = false;
|
liufu
authored
|
60
|
public LEDHelper led { get; set; }
|
liufu
authored
|
61
|
#endregion
|
liufu
authored
|
62
|
|
liufu
authored
|
63
|
public Frm_Main()
|
liufu
authored
|
64
65
|
{
InitializeComponent();
|
liufu
authored
|
66
|
//日志组件最先初始化
|
liufu
authored
|
67
|
LogInfo = new LogInfo(450, 500);
|
liufu
authored
|
68
69
|
panel_Bottom.Children.Add(LogInfo);
|
liufu
authored
|
70
71
|
InitMenu();
InitStatusBar();
|
liufu
authored
|
72
|
InitTimer();
|
liufu
authored
|
73
|
InitOPC();
|
liufu
authored
|
74
|
InitDeviceData();
|
liufu
authored
|
75
|
led = new LEDHelper(AppCommon.LedIP, AppCommon.LedPort, AppCommon.LedTimer);
|
liufu
authored
|
76
|
//InitStockerAndStationMonitor();
|
liufu
authored
|
77
78
79
80
81
|
}
#region 初始化
private void InitDeviceData()
{
|
liufu
authored
|
82
83
84
85
86
|
var temp = Bll.GetAllDevice();
var temp2 = Bll.GetAllDeviceAddress();
var temp3 = Bll.GetAllDeviceProp();
var temp4 = Bll.GetAllDeviceType();
if (!temp.Success || !temp2.Success || !temp3.Success || !temp4.Success)
|
liufu
authored
|
87
88
89
90
91
92
93
94
95
96
97
|
{
btn_OpenPLCConnect.IsEnabled = false;
MessageBox.Show("获取设备数据出错");
AddLogToUI("获取设备数据出错", 2);
return;
}
DeviceEntities = temp.Data;
DeviceAddressEntities = temp2.Data;
DevicePropEntities = temp3.Data;
DeviceTypeEntities = temp4.Data;
//属性地址校验
|
liufu
authored
|
98
99
100
101
102
|
foreach (var item in DeviceEntities)
{
if (DeviceAddressEntities.Count(t => t.DeviceId == item.Id) == 0)
{
String msg = "错误:设备" + item.Code + " " + item.Name + "无属性地址";
|
liufu
authored
|
103
|
MessageBox.Show(msg);
|
liufu
authored
|
104
105
106
107
108
109
110
111
|
AddLogToUI(msg, 2);
btn_OpenPLCConnect.IsEnabled = false;
return;
}
//todo:校验属性是否都存在
if (DevicePropEntities.Count(t => t.DeviceTypeId == item.DeviceTypeId) != DeviceAddressEntities.Count(t => t.DeviceId == item.Id))
{
String msg = "错误:设备" + item.Code + " " + item.Name + "属性地址与类型属性规定不一致";
|
liufu
authored
|
112
|
MessageBox.Show(msg);
|
liufu
authored
|
113
114
115
116
117
|
AddLogToUI(msg, 2);
btn_OpenPLCConnect.IsEnabled = false;
return;
}
}
|
liufu
authored
|
118
|
//属性地址获取无误后初始化监控
|
liufu
authored
|
119
|
InitStockerAndStationMonitor();
|
liufu
authored
|
120
121
|
}
|
liufu
authored
|
122
|
private void InitStockerAndStationMonitor()
|
liufu
authored
|
123
|
{
|
liufu
authored
|
124
125
|
//堆垛机
var stockers = FindDevByType("stocker").Data;
|
liufu
authored
|
126
127
|
foreach (var item in stockers)
{
|
liufu
authored
|
128
|
StockerMonitor stockerMonitor = new StockerMonitor(32, false, false, 1200, 100)
|
liufu
authored
|
129
130
131
132
|
{
ControlName = item.Name,
Name = item.Code
};
|
liufu
authored
|
133
|
this.RegisterName(item.Code, stockerMonitor);
|
liufu
authored
|
134
|
panel_Stocker.Children.Add(stockerMonitor);
|
liufu
authored
|
135
136
137
138
139
140
|
StockerInfo stockerInfo = new StockerInfo(450, 500)
{
ControlName = item.Name,
Name = item.Code
};
stockerInfo.DoubleInEvent += this.DoubleInHandle;
|
liufu
authored
|
141
|
stockerInfo.EmptyOutEvent += this.EmptyOutHandle;
|
liufu
authored
|
142
|
panel_Bottom.Children.Add(stockerInfo);
|
liufu
authored
|
143
|
}
|
liufu
authored
|
144
|
|
liufu
authored
|
145
146
147
148
|
//接入站台
var staionForStockerIn = FindDevByType("stationForStockerIn").Data;
foreach (var item in staionForStockerIn)
{
|
liufu
authored
|
149
150
151
152
153
|
StationInfo stationInfo = new StationInfo(450, 500)
{
ControlName = item.Name,
Name = item.Code
};
|
liufu
authored
|
154
155
|
panel_Bottom.Children.Add(stationInfo);
}
|
liufu
authored
|
156
|
|
liufu
authored
|
157
158
159
160
|
//接出站台
var staionForStockerOut = FindDevByType("stationForStockerOut").Data;
foreach (var item in staionForStockerOut)
{
|
liufu
authored
|
161
162
163
164
165
|
StationInfo stationInfo = new StationInfo(450, 500)
{
ControlName = item.Name,
Name = item.Code
};
|
liufu
authored
|
166
167
168
169
170
171
172
|
panel_Bottom.Children.Add(stationInfo);
}
//出入站台
var station = FindDevByType("station").Data;
foreach (var item in station)
{
|
liufu
authored
|
173
174
175
176
177
|
StationInfo stationInfo = new StationInfo(450, 500)
{
ControlName = item.Name,
Name = item.Code
};
|
liufu
authored
|
178
179
|
panel_Bottom.Children.Add(stationInfo);
}
|
liufu
authored
|
180
|
|
liufu
authored
|
181
182
183
184
|
//出入站台
var stationIn = FindDevByType("stationIn").Data;
foreach (var item in stationIn)
{
|
liufu
authored
|
185
186
187
188
189
|
StationInfo stationInfo = new StationInfo(450, 500)
{
ControlName = item.Name,
Name = item.Code
};
|
liufu
authored
|
190
191
|
panel_Bottom.Children.Add(stationInfo);
}
|
liufu
authored
|
192
193
|
}
|
liufu
authored
|
194
|
private void InitOPC()
|
liufu
authored
|
195
|
{
|
liufu
authored
|
196
|
try
|
liufu
authored
|
197
|
{
|
liufu
authored
|
198
|
PLCIP = ConfigurationManager.AppSettings["OPCServerIP"];
|
liufu
authored
|
199
|
PLC = new OPCHelp(PLCIP);
|
liufu
authored
|
200
|
}
|
liufu
authored
|
201
|
catch (Exception)
|
liufu
authored
|
202
|
{
|
liufu
authored
|
203
|
MessageBox.Show("未能获取到OPC配置,请检查。", "注意", MessageBoxButton.OK, MessageBoxImage.Error);
|
liufu
authored
|
204
|
}
|
liufu
authored
|
205
206
207
208
|
}
private void InitStatusBar()
{
|
liufu
authored
|
209
|
statusBar.Items.Add("欢迎:" + AppCommon.User.UserName + " 登录时间:" + DateTime.Now.ToString());
|
liufu
authored
|
210
211
212
213
214
215
|
}
private void InitMenu()
{
//构建菜单
//系统
|
liufu
authored
|
216
217
218
219
220
221
222
223
|
MenuItem menu_sys = new MenuItem
{
Header = "系统"
};
MenuItem menu_sys_exit = new MenuItem
{
Header = "退出"
};
|
liufu
authored
|
224
225
226
227
|
menu_sys_exit.Click += Menu_sys_exit_Click;
menu_sys.Items.Add(menu_sys_exit);
//设备
|
liufu
authored
|
228
229
230
231
232
233
234
235
|
MenuItem menu_device = new MenuItem
{
Header = "设备管理"
};
MenuItem menu_device_info = new MenuItem
{
Header = "设备信息管理"
};
|
liufu
authored
|
236
237
|
menu_device_info.Click += Menu_device_info_Click;
menu_device.Items.Add(menu_device_info);
|
liufu
authored
|
238
239
240
241
|
MenuItem menu_device_OPCTest = new MenuItem
{
Header = "OPC测试"
};
|
liufu
authored
|
242
243
|
menu_device_OPCTest.Click += Menu_device_OPCTest_Click;
menu_device.Items.Add(menu_device_OPCTest);
|
liufu
authored
|
244
245
|
//任务
|
liufu
authored
|
246
247
248
249
250
251
252
253
|
MenuItem menu_task = new MenuItem
{
Header = "任务管理"
};
MenuItem menu_task_info = new MenuItem
{
Header = "任务查看"
};
|
liufu
authored
|
254
255
256
|
menu_task_info.Click += Menu_task_info_Click;
menu_task.Items.Add(menu_task_info);
|
liufu
authored
|
257
|
//仓库
|
liufu
authored
|
258
259
260
261
262
263
264
265
|
MenuItem menu_warehouse = new MenuItem
{
Header = "仓库信息"
};
MenuItem menu_location = new MenuItem
{
Header = "货位"
};
|
liufu
authored
|
266
|
menu_location.Click += Menu_location_Click;
|
liufu
authored
|
267
268
269
270
|
MenuItem menu_pallet = new MenuItem
{
Header = "托盘"
};
|
liufu
authored
|
271
272
273
274
275
|
menu_pallet.Click += Menu_pallet_Click;
menu_warehouse.Items.Add(menu_location);
menu_warehouse.Items.Add(menu_pallet);
|
liufu
authored
|
276
277
278
279
|
menu.Items.Add(menu_sys);
menu.Items.Add(menu_device);
menu.Items.Add(menu_task);
|
liufu
authored
|
280
|
menu.Items.Add(menu_warehouse);
|
liufu
authored
|
281
282
283
284
|
//工具栏
btn_OpenPLCConnect.IsEnabled = true;
btn_ClosePLCConnect.IsEnabled = false;
|
liufu
authored
|
285
286
|
}
|
liufu
authored
|
287
|
|
liufu
authored
|
288
289
290
291
292
293
|
/// <summary>
/// 打开监控
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_OpenPLCConnect_Click(object sender, RoutedEventArgs e)
|
liufu
authored
|
294
|
{
|
liufu
authored
|
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
if (PLC == null)
{
MessageBox.Show("PLC连接初始化失败! 请检查PLC配置然后重启本程序", "注意", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (PLC.OpenConn() == false)
{
MessageBox.Show("打开PLC连接失败");
return;
}
PLC.CreateGroup("group1");
AddOPCItems();
//
btn_ClosePLCConnect.IsEnabled = true;
btn_OpenPLCConnect.IsEnabled = false;
|
liufu
authored
|
310
|
//同步锁置0
|
liufu
authored
|
311
|
stop = false;
|
liufu
authored
|
312
313
314
315
316
317
318
319
320
|
timer.Enabled = true;
}
private void AddOPCItems()
{
ServerHandle = new int[DeviceAddressEntities.Count];
for (int i = 0; i < DeviceAddressEntities.Count; i++)
{
var temp = DeviceAddressEntities[i];
|
liufu
authored
|
321
|
ServerHandle[i] = PLC.AddAddr(temp.Address, i);
|
liufu
authored
|
322
323
324
325
326
327
328
329
330
331
332
|
temp.ServerHandle = ServerHandle[i];
}
}
/// <summary>
/// 关闭监控
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_ClosePLCConnect_Click(object sender, RoutedEventArgs e)
{
|
liufu
authored
|
333
334
335
336
337
338
339
340
341
342
|
//if (PLC.GetConnStatus())
//{
// if (!PLC.CloseConn())
// {
// MessageBox.Show("关闭失败请稍后重试");
// };
//}
//btn_ClosePLCConnect.IsEnabled = false;
//btn_OpenPLCConnect.IsEnabled = true;
//timer.Enabled = false;
|
liufu
authored
|
343
|
//同步锁置1
|
liufu
authored
|
344
|
stop = true;
|
liufu
authored
|
345
346
347
348
|
}
private void InitTimer()
{
|
liufu
authored
|
349
|
timer.Interval = 1000; //3秒触发一次
|
liufu
authored
|
350
351
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
timer.AutoReset = true;//每到指定时间Elapsed事件是到时间就触发
|
liufu
authored
|
352
|
timer.Enabled = false; //指示 Timer 是否应引发 Elapsed 事件。
|
liufu
authored
|
353
|
}
|
liufu
authored
|
354
|
#endregion
|
liufu
authored
|
355
356
357
|
/// <summary>
/// 程序主时钟
|
liufu
authored
|
358
|
/// 出库优先
|
liufu
authored
|
359
360
361
362
363
364
|
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
//同步线程防止重入
|
liufu
authored
|
365
366
367
|
//if (Interlocked.Exchange(ref inTimer, 1) == 0)
//{
lock (locker)
|
liufu
authored
|
368
|
{
|
liufu
authored
|
369
370
371
372
373
374
375
376
|
#region 是否结束处理
if (stop)
{
if (PLC.GetConnStatus())
{
PLC.CloseConn();
}
|
liufu
authored
|
377
378
379
380
381
382
|
Dispatcher.Invoke(() =>
{
btn_ClosePLCConnect.IsEnabled = false;
btn_OpenPLCConnect.IsEnabled = true;
timer.Enabled = false;
});
|
liufu
authored
|
383
|
|
liufu
authored
|
384
385
386
387
|
return;
}
#endregion
|
liufu
authored
|
388
|
|
liufu
authored
|
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
|
#region 检查是否连接正常
if (PLC.GetConnStatus())
{
this.Dispatcher.Invoke(new Action(() =>
{
if (this.grid.Background == Brushes.Red)
{
this.grid.Background = Brushes.White;
}
}));
}
else
{
this.Dispatcher.Invoke(new Action(() =>
{
if (this.grid.Background != Brushes.Red)
{
this.grid.Background = Brushes.Red;
}
if (!((TextBlock)this.LogInfo.list_Log.SelectedItem).Text.Contains("失去通讯连接,请关闭连接后重新打开"))
{
this.LogInfo.AddLogs("失去通讯连接,请关闭连接后重新打开", 2);
}
}));
//这里直接retrun,并没有更改inTimer的值,后续不会再次进入这个循环,需要关闭连接然后重新打开连接来重置这个参数;
return;
}
#endregion
|
liufu
authored
|
418
419
|
#region 测试监控赋值
|
liufu
authored
|
420
421
422
423
424
425
426
427
|
//测试值读取
var readAllAddressDataResult = ReadAllAddressData();
if (!readAllAddressDataResult.Success)
{
AddLogToUI("读取地址数据失败,请尝试关闭连接后重新连接;", 2);
return;
}
|
liufu
authored
|
428
429
430
431
|
//日志
DeviceEntities.ForEach(item => DeviceAddressEntities.FindAll(t => t.DeviceId == item.Id).Join(DevicePropEntities.FindAll(t => t.DeviceTypeId == item.DeviceTypeId && t.IsMonitor == 1), t => t.DevicePropCode, a => a.Code, (a, b) => new { a, b }).Where(t => t.a.value != t.b.MonitorCompareValue).Select(t => t.b).ToList().ForEach(t => AddLogToUI("报警:" + t.Name + " 信息:" + t.MonitorFailure, 2)));
//底部面板
Dispatcher.Invoke(new Action(() =>
|
liufu
authored
|
432
433
434
435
|
{
foreach (var item in panel_Bottom.Children)
{
if (item is StockerInfo temp)
|
liufu
authored
|
436
|
{
|
liufu
authored
|
437
438
|
var a = DeviceEntities.Find(t => t.Code == temp.Name);
temp.SetProps(DeviceEntities.Find(t => t.Code == temp.Name), DevicePropEntities.FindAll(t => t.DeviceTypeId == a.DeviceTypeId), DeviceAddressEntities.FindAll(t => t.DeviceId == a.Id));
|
liufu
authored
|
439
|
}
|
liufu
authored
|
440
|
if (item is StationInfo station)
|
liufu
authored
|
441
442
443
444
|
{
var a = DeviceEntities.Find(t => t.Code == station.Name);
station.SetProp(DeviceAddressEntities.FindAll(t => t.DeviceId == a.Id));
}
|
liufu
authored
|
445
446
|
};
}
|
liufu
authored
|
447
448
449
450
451
452
453
454
455
|
));
//图形监控
Dispatcher.Invoke(new Action(() =>
{
foreach (var item in FindDevByType("stocker").Data)
{
//货架监控方面先不实现
var addressEntities = DeviceAddressEntities.FindAll(t => t.DeviceId == item.Id);
var stockerMonitor = (StockerMonitor)panel_Stocker.FindName(item.Code);
|
liufu
authored
|
456
|
stockerMonitor.SetProp(addressEntities);
|
liufu
authored
|
457
458
459
|
}
foreach (var item in FindDevByType("conveyor").Data)
{
|
liufu
authored
|
460
|
var cv = this.FindName(item.Code);
|
liufu
authored
|
461
|
if (cv is StationV stationV)
|
liufu
authored
|
462
463
464
|
{
stationV.SetProp(DeviceAddressEntities.FindAll(t => t.DeviceId == item.Id));
}
|
liufu
authored
|
465
|
if (cv is StationH stationH)
|
liufu
authored
|
466
467
468
|
{
stationH.SetProp(DeviceAddressEntities.FindAll(t => t.DeviceId == item.Id));
}
|
liufu
authored
|
469
470
|
}
}));
|
liufu
authored
|
471
|
|
liufu
authored
|
472
473
|
#endregion
|
liufu
authored
|
474
475
|
#region 堆垛机操作
//找出所有堆垛机
|
liufu
authored
|
476
|
var stockersResult = FindDevByType("stocker");
|
liufu
authored
|
477
478
479
480
481
|
if (stockersResult.Success)
{
var stockers = stockersResult.Data;
//遍历所有出库性质的任务
ExcuteTaskOut(stockers);
|
liufu
authored
|
482
|
//响应任务完成
|
liufu
authored
|
483
484
|
ExcuteTaskComplete(stockers);
|
liufu
authored
|
485
486
487
|
//响应入库任务
ExcuteTaskIn(stockers);
|
liufu
authored
|
488
489
490
|
//同巷道内的移库,当堆垛机状态为0,1,2时,均可以响应巷道内的移库
ExcuteTaskTransferInRoadway(stockers);
|
liufu
authored
|
491
492
493
494
495
496
|
}
#endregion
#region 响应堆垛机接入站台
|
liufu
authored
|
497
|
var stationForStockerInResult = FindDevByType("stationForStockerIn");
|
liufu
authored
|
498
499
500
501
|
if (stationForStockerInResult.Success)
{
foreach (var stationForStockerIn in stationForStockerInResult.Data)
{
|
liufu
authored
|
502
503
504
|
var addresses = DeviceAddressEntities.FindAll(t => t.DeviceId == stationForStockerIn.Id);
var readResult = ReadAddress(addresses);
if (readResult.Success)
|
liufu
authored
|
505
|
{
|
liufu
authored
|
506
507
508
|
//这里先直接回应一个响应
//如果PLC标记为3,则表示解析有误,这里报警
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "3")
|
liufu
authored
|
509
|
{
|
liufu
authored
|
510
511
512
|
AddLogToUI("PLC解析站台" + stationForStockerIn + "数据失败,请检查基础数据!", 2);
continue;
}
|
liufu
authored
|
513
|
|
liufu
authored
|
514
515
516
517
518
|
//PLC 有新消息标记 && WCS回复有新消息标记:此时WCS已经回复了消息,等待PLC响应,不做处理,如果PLC新标记为3,表示解析错误
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1")
{
continue;
}
|
liufu
authored
|
519
|
|
liufu
authored
|
520
521
522
523
524
|
//PLC没有新消息标记 && WCS有新消息标记:此时PLC已经确认消息,清除WCS回复消息
if (addresses.Find(t => t.DevicePropCode == "Flag").value != "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1")
{
var result = WriteWCSStationDataAddress(addresses, "0", "0", "0", "0", "0", "0", "", "0", "0");
if (result.Success)
|
liufu
authored
|
525
|
{
|
liufu
authored
|
526
527
528
529
530
531
532
533
|
AddLogToUI("清空" + stationForStockerIn + "WCS区地址成功", 1);
}
else
{
AddLogToUI("清空" + stationForStockerIn + "WCS区地址失败:" + result.Msg, 2);
}
continue;
}
|
liufu
authored
|
534
|
|
liufu
authored
|
535
|
//PLC有新消息标记 && WCS没有新消息标记:此时PLC发送了消息而WCS没有响应,写响应逻辑发送地址数据给PLC
|
liufu
authored
|
536
537
538
539
540
541
542
|
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1"
&& addresses.Find(t => t.DevicePropCode == "WCSFlag").value != "1"
//这里做一次校验防止与PLC扫描冲突
&& addresses.Find(t => t.DevicePropCode == "Type").value != "0"
&& addresses.Find(t => t.DevicePropCode == "PLCNo").value != "0"
&& addresses.Find(t => t.DevicePropCode == "StationNo").value != "0"
&& !String.IsNullOrWhiteSpace(addresses.Find(t => t.DevicePropCode == "Barcode").value))
|
liufu
authored
|
543
544
545
546
547
|
{
//判断报文类型
if (addresses.Find(t => t.DevicePropCode == "Type").value == "1")
{
//地址请求
|
liufu
authored
|
548
|
AddLogToUI("堆垛机接入站台" + stationForStockerIn + "暂时没有实现地址请求", 3);
|
liufu
authored
|
549
550
551
552
|
continue;
}
if (addresses.Find(t => t.DevicePropCode == "Type").value == "2")
{
|
liufu
authored
|
553
554
555
556
557
558
559
560
561
|
//响应一个位置到达请求
//更新任务状态为35
String palletCode = addresses.Find(t => t.DevicePropCode == "Barcode").value;
var bllResult = Bll.GetTaskUncompleteByPalletCode(palletCode);
if (!bllResult.Success)
{
AddLogToUI("站台" + stationForStockerIn + "对应托盘" + palletCode + "没有查找到任务数据", 2);
continue;
}
|
liufu
authored
|
562
563
564
|
var task = bllResult.Data;
if (task.Status > 31)
{
|
liufu
authored
|
565
|
AddLogToUI("站台" + stationForStockerIn + "对应托盘" + palletCode + "没有查找到任务" + task.Id + "状态已经超过30,应已响应,请检查", 2);
|
liufu
authored
|
566
567
|
continue;
}
|
liufu
authored
|
568
|
//给他回一个位置到达
|
liufu
authored
|
569
|
var temp = WriteWCSStationDataAddress(addresses, "1", "8", addresses.Find(t => t.DevicePropCode == "PLCNo").value, "0", addresses.Find(t => t.DevicePropCode == "StationNo").value, addresses.Find(t => t.DevicePropCode == "TaskNo").value, addresses.Find(t => t.DevicePropCode == "Barcode").value, "0", "0");
|
liufu
authored
|
570
571
|
if (temp.Success)
{
|
liufu
authored
|
572
573
|
//位置到达回复成功后,更新任务状态
Bll.SetTaskStatus(task.Id, 35);
|
liufu
authored
|
574
|
AddLogToUI("位置到达:任务" + task.Id + "位置到达写入" + stationForStockerIn + "WCS区地址成功", 1);
|
liufu
authored
|
575
|
}
|
liufu
authored
|
576
577
|
else
{
|
liufu
authored
|
578
|
AddLogToUI("位置到达:写入" + stationForStockerIn + "WCS区地址失败:" + temp.Msg, 2);
|
liufu
authored
|
579
580
|
}
continue;
|
liufu
authored
|
581
|
}
|
liufu
authored
|
582
583
584
585
586
587
588
|
//判断报文类型
if (addresses.Find(t => t.DevicePropCode == "Type").value == "3")
{
//地址请求
AddLogToUI("堆垛机接入站台" + stationForStockerIn + "暂时没有控制指令请求", 3);
continue;
}
|
liufu
authored
|
589
590
|
}
}
|
liufu
authored
|
591
592
593
594
|
else
{
AddLogToUI(readResult.Msg, 2);
}
|
liufu
authored
|
595
596
597
598
599
600
601
|
}
}
#endregion
#region 响应堆垛机接出站台
|
liufu
authored
|
602
|
var stationForStockerOutResult = FindDevByType("stationForStockerOut");
|
liufu
authored
|
603
604
605
606
|
if (stationForStockerOutResult.Success)
{
foreach (var stationForStockerOut in stationForStockerOutResult.Data)
{
|
liufu
authored
|
607
608
609
|
var addresses = DeviceAddressEntities.FindAll(t => t.DeviceId == stationForStockerOut.Id);
var readResult = ReadAddress(addresses);
if (readResult.Success)
|
liufu
authored
|
610
|
{
|
liufu
authored
|
611
612
613
614
615
616
|
//如果PLC标记为3,则表示解析有误,这里报警
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "3")
{
AddLogToUI("PLC解析站台" + stationForStockerOut + "数据失败,请检查基础数据!", 2);
continue;
}
|
liufu
authored
|
617
|
|
liufu
authored
|
618
|
//PLC 有新消息标记 && WCS回复有新消息标记:此时WCS已经回复了消息,等待PLC响应,不做处理,如果PLC新标记为3,表示解析错误
|
liufu
authored
|
619
620
621
622
|
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1")
{
continue;
}
|
liufu
authored
|
623
624
|
//PLC没有新消息标记 && WCS有新消息标记:此时PLC已经确认消息,清除WCS回复消息
|
liufu
authored
|
625
626
|
if (addresses.Find(t => t.DevicePropCode == "Flag").value != "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1")
{
|
liufu
authored
|
627
|
var result = WriteWCSStationDataAddress(addresses, "0", "0", "0", "0", "0", "0", "", "0", "0");
|
liufu
authored
|
628
629
630
631
632
633
634
635
636
637
|
if (result.Success)
{
AddLogToUI("清空" + stationForStockerOut + "WCS区地址成功", 1);
}
else
{
AddLogToUI("清空" + stationForStockerOut + "WCS区地址失败:" + result.Msg, 2);
}
continue;
}
|
liufu
authored
|
638
639
|
//PLC有新消息标记 && WCS没有新消息标记:此时PLC发送了消息而WCS没有响应,写响应逻辑发送地址数据给PLC
|
liufu
authored
|
640
|
//加入地址校验,防止PLC写入与WCS读取冲突;堆垛机接出站台,地址请求时时没有带条码的,需要我们写入
|
liufu
authored
|
641
642
643
644
645
|
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1"
&& addresses.Find(t => t.DevicePropCode == "WCSFlag").value != "1"
&& addresses.Find(t => t.DevicePropCode == "Type").value != "0"
&& addresses.Find(t => t.DevicePropCode == "PLCNo").value != "0"
&& addresses.Find(t => t.DevicePropCode == "StationNo").value != "0"
|
liufu
authored
|
646
|
)
|
liufu
authored
|
647
648
649
650
651
|
{
//判断报文类型
if (addresses.Find(t => t.DevicePropCode == "Type").value == "1")
{
//表示地址请求
|
liufu
authored
|
652
653
654
655
656
|
//hack:假设没有移库任务
//获取任务状态为25的任务
var tasksResult = Bll.GetTasks("25", null, null, null, null);
if (!tasksResult.Success || tasksResult.Data.Count == 0)
{
|
liufu
authored
|
657
|
AddLogToUI("未找到站台" + stationForStockerOut + "对应的任务,无法响应地址请求", 2);
|
liufu
authored
|
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
|
continue;
}
int roadWay = stationForStockerOut.Roadway;
string palletCode = "";
TaskEntity task = null;
foreach (var item in tasksResult.Data)
{
var locationResult = Bll.GetAllLocations(item.ContainerCode, null, null, null, null, null, null);
if (locationResult.Success)
{
LocationEntity locationEntity = locationResult.Data[0];
if (locationEntity.Roadway == roadWay)
{
//说明这个任务是这个巷道的,则获取他的托盘号
palletCode = item.ContainerCode;
task = item;
break;
}
}
}
if (string.IsNullOrEmpty(palletCode))
{
AddLogToUI("未找到站台" + stationForStockerOut + "对应的任务,无法响应地址请求", 2);
continue;
}
|
liufu
authored
|
684
685
|
//判断是不是移库,如果是移库则是去堆垛机接入站台
if (task.Type == 800)
|
liufu
authored
|
686
|
{
|
liufu
authored
|
687
688
689
690
691
692
693
|
//todo:移库堆垛机接入站台处理
}
else
{
//获取一个站台
var station = DeviceEntities.Join(DeviceTypeEntities, a => a.DeviceTypeId, b => b.Id, (a, b) => new { a, b }).Where(t => t.b.Code == "stationOut" || t.b.Code == "station").Select(t => t.a).FirstOrDefault();
if (station != null)
|
liufu
authored
|
694
|
{
|
liufu
authored
|
695
696
697
698
699
700
701
702
703
704
705
706
|
//写入响应数据
var result = WriteWCSStationDataAddress(addresses, "1", "6", addresses.Find(t => t.DevicePropCode == "PLCNo").value, "0", addresses.Find(t => t.DevicePropCode == "StationNo").value, addresses.Find(t => t.DevicePropCode == "TaskNo").value, palletCode, station.SelfAddress.ToString(), "0");
if (result.Success)
{
//更新任务状态为28,表示这条任务已经响应了地址请求
Bll.SetTaskStatus(task.Id, 28);
AddLogToUI("写入" + stationForStockerOut + "WCS区地址成功", 1);
}
else
{
AddLogToUI("写入" + stationForStockerOut + "WCS区地址失败:" + result.Msg, 2);
}
|
liufu
authored
|
707
708
709
|
}
else
{
|
liufu
authored
|
710
|
AddLogToUI("未找到出库站台", 2);
|
liufu
authored
|
711
712
713
|
}
}
}
|
liufu
authored
|
714
715
716
717
718
719
720
721
722
723
724
725
|
if (addresses.Find(t => t.DevicePropCode == "Type").value == "2")
{
//地址请求
AddLogToUI("堆垛机接入站台" + stationForStockerOut + "暂时没有实现位置到达请求", 3);
continue;
}
if (addresses.Find(t => t.DevicePropCode == "Type").value == "3")
{
//地址请求
AddLogToUI("堆垛机接入站台" + stationForStockerOut + "暂时没有实现控制指令请求", 3);
continue;
}
|
liufu
authored
|
726
|
|
liufu
authored
|
727
728
729
730
731
732
733
|
}
}
else
{
AddLogToUI("读取" + stationForStockerOut + "地址失败:" + readResult.Msg, 2);
}
|
liufu
authored
|
734
735
736
737
738
|
}
}
#endregion
|
liufu
authored
|
739
|
#region 响应出入库站台(拣选台)
|
liufu
authored
|
740
741
|
//todo:与接出站台类似,整出则完成任务、扫描到托盘号则请求任务、连接LED设备等,待确认后再写
|
liufu
authored
|
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
|
//目前立体库中只有station
var stations = FindDevByType("station");
if (stations.Success)
{
foreach (var station in stations.Data)
{
var addresses = DeviceAddressEntities.FindAll(t => t.DeviceId == station.Id);
var readResult = ReadAddress(addresses);
if (readResult.Success)
{
//如果PLC标记为3,则表示解析有误,这里报警
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "3")
{
AddLogToUI("PLC解析站台" + station + "数据失败,请检查基础数据!", 2);
continue;
}
|
liufu
authored
|
758
|
|
liufu
authored
|
759
760
761
762
763
|
//PLC 有新消息标记 && WCS回复有新消息标记:此时WCS已经回复了消息,等待PLC响应,不做处理,如果PLC新标记为3,表示解析错误
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1")
{
continue;
}
|
liufu
authored
|
764
|
|
liufu
authored
|
765
766
767
|
//PLC没有新消息标记 && WCS有新消息标记:此时PLC已经确认消息,清除WCS回复消息
if (addresses.Find(t => t.DevicePropCode == "Flag").value != "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1")
{
|
liufu
authored
|
768
|
var result = WriteWCSStationDataAddress(addresses, "0", "0", "0", "0", "0", "0", "", "0", "0");
|
liufu
authored
|
769
770
771
772
773
774
775
776
777
778
779
780
|
if (result.Success)
{
AddLogToUI("清空" + station + "WCS区地址成功", 1);
}
else
{
AddLogToUI("清空" + station + "WCS区地址失败:" + result.Msg, 2);
}
continue;
}
//PLC有新消息标记 && WCS没有新消息标记:此时PLC发送了消息而WCS没有响应,写响应逻辑发送地址数据给PLC
|
liufu
authored
|
781
|
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1"
|
liufu
authored
|
782
783
784
785
786
|
&& addresses.Find(t => t.DevicePropCode == "WCSFlag").value != "1"
&& addresses.Find(t => t.DevicePropCode == "Type").value != "0"
&& addresses.Find(t => t.DevicePropCode == "PLCNo").value != "0"
&& addresses.Find(t => t.DevicePropCode == "StationNo").value != "0"
&& !String.IsNullOrWhiteSpace(addresses.Find(t => t.DevicePropCode == "Barcode").value))
|
liufu
authored
|
787
788
|
{
//获取任务
|
liufu
authored
|
789
|
string pallet = addresses.Find(t => t.DevicePropCode == "Barcode").value;
|
liufu
authored
|
790
791
792
793
794
795
796
797
798
799
800
801
|
var taskResult = Bll.GetTaskUncompleteByPalletCode(pallet);
if (!taskResult.Success)
{
AddLogToUI(station + " 根据" + pallet + "获取任务失败:" + taskResult.Msg, 2);
continue;
}
TaskEntity taskEntity = taskResult.Data;
//判断报文类型
if (addresses.Find(t => t.DevicePropCode == "Type").value == "1")
{
//表示地址请求,此时可能是分拣回库,也可能是新入库,也可能是空托入库,这里空托入库如果没有任务就自动生成任务(自动生成空托盘入库暂时不实现)
//获取目标库位
|
liufu
authored
|
802
|
//hack:这里临时加个判断,如果任务状态不是31,则不响应
|
liufu
authored
|
803
804
|
//if (taskEntity.Status == 31)
//{
|
liufu
authored
|
805
806
|
LocationEntity location;
if (taskEntity.Type == 100 || taskEntity.Type == 500)
|
liufu
authored
|
807
|
{
|
liufu
authored
|
808
809
810
811
812
813
814
|
var locationResult = Bll.GetAllLocations(null, null, null, null, null, null, taskEntity.DestinationLocation);
if (!locationResult.Success)
{
AddLogToUI("未找到任务" + taskEntity.Id + "对应的" + taskEntity.DestinationLocation + "库位", 2);
continue;
}
location = locationResult.Data[0];
|
liufu
authored
|
815
|
}
|
liufu
authored
|
816
|
else if (taskEntity.Type == 200 || taskEntity.Type == 400 || taskEntity.Type == 700)
|
liufu
authored
|
817
|
{
|
liufu
authored
|
818
819
820
821
822
823
824
825
826
827
828
|
var locationResult = Bll.GetAllLocations(null, null, null, null, null, null, taskEntity.SourceLocation);
if (!locationResult.Success)
{
AddLogToUI("未找到任务" + taskEntity.Id + "对应的" + taskEntity.SourceLocation + "库位", 2);
continue;
}
location = locationResult.Data[0];
}
else
{
AddLogToUI("任务" + taskEntity.Id + "对应的类型" + taskEntity.Type + "不符合地址请求要求", 2);
|
liufu
authored
|
829
830
|
continue;
}
|
liufu
authored
|
831
832
833
|
//获取这个库位的目标巷道,从而得出对应的接入站台
var stockerStationIns = DeviceEntities.Join(DeviceTypeEntities, t => t.DeviceTypeId, a => a.Id, (a, b) => new { a, b }).Where(t => t.b.Code == "stationForStockerIn" && t.a.Roadway == location.Roadway).Select(t => t.a).ToList();
if (stockerStationIns.Count == 0)
|
liufu
authored
|
834
|
{
|
liufu
authored
|
835
836
|
AddLogToUI("未找到任务" + taskEntity.Id + "对应的堆垛机接入站台,巷道:" + location.Roadway + ",托盘:" + taskEntity.ContainerCode, 2);
continue;
|
liufu
authored
|
837
838
839
|
}
else
{
|
liufu
authored
|
840
841
842
843
844
|
var stockerStationIn = stockerStationIns[0];
//写入响应地址
var result = WriteWCSStationDataAddress(addresses, "1", "06", addresses.Find(t => t.DevicePropCode == "PLCNo").value, "0", addresses.Find(t => t.DevicePropCode == "StationNo").value, addresses.Find(t => t.DevicePropCode == "TaskNo").value, addresses.Find(t => t.DevicePropCode == "Barcode").value, stockerStationIn.SelfAddress.ToString(), "0");
if (result.Success)
{
|
liufu
authored
|
845
846
|
//这里清空led显示
led.SendLedInfo(" ");
|
liufu
authored
|
847
|
AddLogToUI("写入" + station + "WCS区地址成功;任务:" + taskEntity.Id.ToString(), 1);
|
liufu
authored
|
848
849
850
|
}
else
{
|
liufu
authored
|
851
|
AddLogToUI("写入" + station + "WCS区地址失败,任务:" + taskEntity.Id.ToString() + "消息:" + result.Msg, 2);
|
liufu
authored
|
852
|
}
|
liufu
authored
|
853
|
}
|
liufu
authored
|
854
|
//}
|
liufu
authored
|
855
856
857
858
|
}
if (addresses.Find(t => t.DevicePropCode == "Type").value == "2")
{
|
liufu
authored
|
859
|
//表示位置到达,此时检查任务,如果是整出、空出则完成任务
|
liufu
authored
|
860
861
|
//写给PLC的一个标志位,当为1时,表示托盘到此中止;当为2时,表示托盘还需要回库;
int flag = 0;
|
liufu
authored
|
862
863
864
865
866
|
if (taskEntity.Status != 28)
{
AddLogToUI("站台" + station + "位置到达,但是任务" + taskEntity.Id + "状态为" + taskEntity.Status + ",此处要求状态为28才会处理", 2);
continue;
}
|
liufu
authored
|
867
868
869
870
871
|
if (taskEntity.Type == 300 || taskEntity.Type == 600)
{
var result = Bll.CompleteTask(taskEntity.Id.ToString());
if (result.Success)
{
|
liufu
authored
|
872
|
flag = 1;
|
liufu
authored
|
873
874
875
876
877
878
879
880
881
882
883
884
885
886
|
AddLogToUI("站台" + station + ",完成" + taskEntity.Id.ToString() + "成功", 1);
}
else
{
AddLogToUI("完成任务" + taskEntity.Id.ToString() + "失败:" + result.Msg, 2);
continue;
}
}
else
{
//如果是其他类型的任务则更新状态为到达站台并响应
var result = Bll.SetTaskStatus(taskEntity.Id, 30);
if (result.Success)
{
|
liufu
authored
|
887
|
flag = 2;
|
liufu
authored
|
888
|
AddLogToUI("站台" + station + ",更新任务" + taskEntity.Id.ToString() + "状态30成功", 1);
|
liufu
authored
|
889
890
891
|
}
else
{
|
liufu
authored
|
892
|
AddLogToUI("站台" + station + ",更新任务" + taskEntity.Id.ToString() + "状态30失败:" + result.Msg, 2);
|
liufu
authored
|
893
894
895
896
|
continue;
}
}
//响应一个位置请求
|
liufu
authored
|
897
|
var temp = WriteWCSStationDataAddress(addresses, "1", "8", addresses.Find(t => t.DevicePropCode == "PLCNo").value, "0", addresses.Find(t => t.DevicePropCode == "StationNo").value, addresses.Find(t => t.DevicePropCode == "TaskNo").value, addresses.Find(t => t.DevicePropCode == "Barcode").value, "0", flag.ToString());
|
liufu
authored
|
898
899
|
if (temp.Success)
{
|
liufu
authored
|
900
901
|
//发送电子屏
SendToLED(taskEntity);
|
liufu
authored
|
902
903
904
905
906
907
908
|
AddLogToUI("位置到达写入" + station + "WCS区地址成功", 1);
}
else
{
AddLogToUI("位置到达写入" + station + "WCS区地址失败:" + temp.Msg, 2);
}
continue;
|
liufu
authored
|
909
910
911
912
913
914
|
}
if (addresses.Find(t => t.DevicePropCode == "Type").value == "3")
{
//表示控制指令
//todo:控制指令先不弄
|
liufu
authored
|
915
|
AddLogToUI("控制指令暂时没有实现", 1);
|
liufu
authored
|
916
917
918
919
920
921
922
923
924
925
|
}
}
}
else
{
AddLogToUI("读取" + station + "地址失败:" + readResult.Msg, 2);
}
}
}
|
liufu
authored
|
926
927
|
#endregion
|
liufu
authored
|
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
|
#region 响应只入站台
var stationIns = FindDevByType("stationIn");
if (stationIns.Success)
{
foreach (var stationIn in stationIns.Data)
{
var addresses = DeviceAddressEntities.FindAll(t => t.DeviceId == stationIn.Id);
var readResult = ReadAddress(addresses);
if (readResult.Success)
{
//如果PLC标记为3,则表示解析有误,这里报警
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "3")
{
AddLogToUI("PLC解析站台" + stationIn + "数据失败,请检查基础数据!", 2);
continue;
}
//PLC 有新消息标记 && WCS回复有新消息标记:此时WCS已经回复了消息,等待PLC响应,不做处理,如果PLC新标记为3,表示解析错误
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1")
{
continue;
}
//PLC没有新消息标记 && WCS有新消息标记:此时PLC已经确认消息,清除WCS回复消息
if (addresses.Find(t => t.DevicePropCode == "Flag").value != "1" && addresses.Find(t => t.DevicePropCode == "WCSFlag").value == "1")
{
var result = WriteWCSStationDataAddress(addresses, "0", "0", "0", "0", "0", "0", "", "0", "0");
if (result.Success)
{
AddLogToUI("清空" + stationIn + "WCS区地址成功", 1);
}
else
{
AddLogToUI("清空" + stationIn + "WCS区地址失败:" + result.Msg, 2);
}
continue;
}
//PLC有新消息标记 && WCS没有新消息标记:此时PLC发送了消息而WCS没有响应,写响应逻辑发送地址数据给PLC
if (addresses.Find(t => t.DevicePropCode == "Flag").value == "1"
&& addresses.Find(t => t.DevicePropCode == "WCSFlag").value != "1"
&& addresses.Find(t => t.DevicePropCode == "Type").value != "0"
&& addresses.Find(t => t.DevicePropCode == "PLCNo").value != "0"
&& addresses.Find(t => t.DevicePropCode == "StationNo").value != "0"
&& !String.IsNullOrWhiteSpace(addresses.Find(t => t.DevicePropCode == "Barcode").value))
{
if (addresses.Find(t => t.DevicePropCode == "Type").value == "1")
{
//获取任务
string pallet = addresses.Find(t => t.DevicePropCode == "Barcode").value;
|
liufu
authored
|
980
981
982
|
if (pallet == "??????" || pallet == "NoRead")
{
AddLogToUI(stationIn + "未识别的条码", 3);
|
liufu
authored
|
983
|
StationBack(addresses, stationIn);
|
liufu
authored
|
984
985
|
continue;
}
|
liufu
authored
|
986
987
988
989
|
var taskResult = Bll.GetTaskUncompleteByPalletCode(pallet);
if (!taskResult.Success)
{
AddLogToUI(stationIn + " 根据" + pallet + "获取任务失败:" + taskResult.Msg, 2);
|
liufu
authored
|
990
|
StationBack(addresses, stationIn);
|
liufu
authored
|
991
992
993
|
continue;
}
TaskEntity taskEntity = taskResult.Data;
|
liufu
authored
|
994
|
if (taskEntity.Status >= 30)
|
liufu
authored
|
995
996
|
{
AddLogToUI(stationIn + " 根据" + pallet + "获取任务成功,但任务状态已超过30", 2);
|
liufu
authored
|
997
|
StationBack(addresses, stationIn);
|
liufu
authored
|
998
999
|
continue;
}
|
liufu
authored
|
1000
|
//判断任务,这里只允许整入和空入库任务,如果托盘带有其他类型任务则报错
|
liufu
authored
|
1001
|
if (taskEntity.Type != 100 && taskEntity.Type != 500)
|
liufu
authored
|
1002
1003
|
{
AddLogToUI("站台" + stationIn + ",任务" + taskEntity.Id + ",任务类型不符合要求,入库站台只能整入或者空入", 2);
|
liufu
authored
|
1004
|
StationBack(addresses, stationIn);
|
liufu
authored
|
1005
1006
1007
1008
1009
|
continue;
}
if (taskEntity.Station > 20)
{
AddLogToUI("站台" + stationIn + ",任务" + taskEntity.Id + ",任务状态不符合,入库站台任务状态是刚下达或开始执行状态", 2);
|
liufu
authored
|
1010
|
StationBack(addresses, stationIn);
|
liufu
authored
|
1011
1012
1013
1014
1015
|
continue;
}
var locationResult = Bll.GetAllLocations(null, null, null, null, null, null, taskEntity.DestinationLocation);
if (!locationResult.Success)
{
|
liufu
authored
|
1016
|
AddLogToUI("站台" + stationIn + "未找到任务" + taskEntity.Id + ",托盘:" + taskEntity.ContainerCode + ",目标库位编码:" + taskEntity.DestinationLocation + "的库位;请检查库位编码是否正确", 2);
|
liufu
authored
|
1017
|
StationBack(addresses, stationIn);
|
liufu
authored
|
1018
1019
1020
1021
1022
1023
1024
|
continue;
}
var location = locationResult.Data[0];
//获取这个库位的目标巷道,从而得出对应的接入站台
var stockerStationIns = DeviceEntities.Join(DeviceTypeEntities, t => t.DeviceTypeId, a => a.Id, (a, b) => new { a, b }).Where(t => t.b.Code == "stationForStockerIn" && t.a.Roadway == location.Roadway).Select(t => t.a).ToList();
if (stockerStationIns.Count == 0)
{
|
liufu
authored
|
1025
|
AddLogToUI("站台" + stationIn + "未找到任务" + taskEntity.Id + "对应的堆垛机接入站台,巷道:" + location.Roadway + ",托盘:" + taskEntity.ContainerCode, 2);
|
liufu
authored
|
1026
|
StationBack(addresses, stationIn);
|
liufu
authored
|
1027
1028
1029
1030
1031
1032
|
continue;
}
var stockerStationIn = stockerStationIns[0];
var result = WriteWCSStationDataAddress(addresses, "1", "06", addresses.Find(t => t.DevicePropCode == "PLCNo").value, "0", addresses.Find(t => t.DevicePropCode == "StationNo").value, addresses.Find(t => t.DevicePropCode == "TaskNo").value, addresses.Find(t => t.DevicePropCode == "Barcode").value, stockerStationIn.SelfAddress.ToString(), "0");
if (result.Success)
{
|
liufu
authored
|
1033
|
//这里将任务状态更新为30,表示达到了站台,即入库进行整个流程的后一半
|
liufu
authored
|
1034
|
SendToLED(taskEntity);
|
liufu
authored
|
1035
|
Bll.SetTaskStatus(taskEntity.Id, 30);
|
liufu
authored
|
1036
|
AddLogToUI("写入" + stationIn + "WCS区地址成功,任务:" + taskEntity.Id, 1);
|
liufu
authored
|
1037
1038
1039
|
}
else
{
|
liufu
authored
|
1040
|
AddLogToUI("写入" + stationIn + "WCS区地址失败,任务:" + taskEntity.Id + ",消息:" + result.Msg, 2);
|
liufu
authored
|
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
|
}
}
if (addresses.Find(t => t.DevicePropCode == "Type").value == "2")
{
//地址请求
AddLogToUI("入库站台" + stationIn + "暂时没有实现位置到达请求", 3);
continue;
}
if (addresses.Find(t => t.DevicePropCode == "Type").value == "3")
{
//地址请求
AddLogToUI("入库站台" + stationIn + "暂时没有实现控制指令请求", 3);
continue;
}
}
}
else
{
AddLogToUI("读取" + stationIn + "地址失败:" + readResult.Msg, 2);
}
}
}
#endregion
#region 响应只出站台
//这个目前不涉及
#endregion
|
liufu
authored
|
1071
|
|
liufu
authored
|
1072
|
}
|
liufu
authored
|
1073
|
//Interlocked.Exchange(ref inTimer, 0);
|
liufu
authored
|
1074
|
//}
|
liufu
authored
|
1075
1076
|
}
|
liufu
authored
|
1077
1078
1079
1080
|
#region 功能函数
/// <summary>
|
liufu
authored
|
1081
1082
1083
1084
1085
1086
1087
|
/// 入库口回退
/// </summary>
/// <param name="deviceAddresses"></param>
/// <returns></returns>
private void StationBack(List<DeviceAddressEntity> addresses,DeviceEntity device)
{
//获取地址
|
liufu
authored
|
1088
|
var result = WriteWCSStationDataAddress(addresses, "1", "06", addresses.Find(t => t.DevicePropCode == "PLCNo").value, "0", addresses.Find(t => t.DevicePropCode == "StationNo").value, addresses.Find(t => t.DevicePropCode == "TaskNo").value, addresses.Find(t => t.DevicePropCode == "Barcode").value,device.BackAddress, "0");
|
liufu
authored
|
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
|
if (result.Success)
{
AddLogToUI($"{device}回退成功",1);
}
else
{
AddLogToUI($"{device}回退写入失败,请人工处理", 2);
}
}
/// <summary>
|
liufu
authored
|
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
|
/// 处理重入
/// </summary>
/// <param name="location"></param>
/// <param name="device"></param>
/// <returns></returns>
public BllResult DoubleInHandle(LocationEntity location, DeviceEntity device)
{
if (PLC == null || PLC.GetConnStatus() == false || DeviceAddressEntities == null || DeviceAddressEntities.Count == 0)
{
//AddLogToUI("地址读取失败,请检查通讯连接", 2);
return BllResultFactory.Error(null, "地址读取失败,请检查通讯连接");
}
var addresses = DeviceAddressEntities.FindAll(t => t.DeviceId == device.Id);
//获取任务和是否重入
var taskProp = addresses.Find(t => t.DevicePropCode == "TaskNo1");
var doubleInProp = addresses.Find(t => t.DevicePropCode == "DoubleIn");
if (taskProp == null | doubleInProp == null)
{
return BllResultFactory.Error(null, $"未找到堆垛机{device}的任务和重入属性");
}
if (doubleInProp.value != "True")
{
return BllResultFactory.Error(null, $"堆垛机{device}未报重入错误");
}
var taskResult = Bll.GetTasks(null, taskProp.value, null, null, null);
if (taskResult.Success)
{
var task = taskResult.Data[0];
if (task.Status < 40)
{
|
liufu
authored
|
1131
|
BllResult temp = Bll.TaskDoubleInHandle("1", location.Code, task.Id);
|
liufu
authored
|
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
|
if (temp.Success)
{
BllResult sendResult = SendTaskToStocker(addresses, "5", "0", "0", "0", "0", location.Row.ToString(), location.Layer.ToString(), location.Column.ToString(), task.Id.ToString(), "0");
if (sendResult.Success)
{
return BllResultFactory.Sucess(null, "成功");
}
else
{
//回滚
Bll.TaskDoubleInHandle("0", "", task.Id);
return BllResultFactory.Error(null, $"处理{device}重入失败:{sendResult.Msg}");
}
}
else
{
return BllResultFactory.Error(null, $"处理{device}重入失败:{temp.Msg}");
}
}
else
{
return BllResultFactory.Error(null, $"{device}对应的任务Id:{taskProp.value}已完成");
}
}
else
{
return BllResultFactory.Error(null, $"未找到{device}对应的任务Id:{taskProp.value}");
}
}
|
liufu
authored
|
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
|
/// <summary>
/// 处理空出
/// 1.标记任务
/// 2.完成空出任务
/// 3.清空堆垛机交换区
/// </summary>
/// <param name="device"></param>
/// <returns></returns>
public BllResult EmptyOutHandle(DeviceEntity device)
{
if (PLC == null || PLC.GetConnStatus() == false || DeviceAddressEntities == null || DeviceAddressEntities.Count == 0)
{
//AddLogToUI("地址读取失败,请检查通讯连接", 2);
return BllResultFactory.Error(null, "地址读取失败,请检查通讯连接");
}
var addresses = DeviceAddressEntities.FindAll(t => t.DeviceId == device.Id);
//获取任务和是否重入
var taskProp = addresses.Find(t => t.DevicePropCode == "TaskNo1");
var emptyOutProp = addresses.Find(t => t.DevicePropCode == "EmptyOut");
if (taskProp == null | emptyOutProp == null)
{
return BllResultFactory.Error(null, $"未找到堆垛机{device}的任务和空出属性");
}
if (emptyOutProp.value != "True")
{
return BllResultFactory.Error(null, $"堆垛机{device}未报空出错误");
}
var taskResult = Bll.GetTasks(null, taskProp.value, null, null, null);
if (taskResult.Success)
{
var task = taskResult.Data[0];
if (task.Status < 40)
{
|
liufu
authored
|
1197
|
BllResult temp = Bll.EmptyOutHandle("1","40",task);
|
liufu
authored
|
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
|
if (temp.Success)
{
//清空WCS交换区
BllResult sendResult = SendTaskToStocker(addresses, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0");
if (sendResult.Success)
{
return BllResultFactory.Sucess(null, "成功");
}
else
{
//回滚
|
liufu
authored
|
1209
|
Bll.EmptyOutHandle("0",task.Status.ToString(), task);
|
liufu
authored
|
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
|
return BllResultFactory.Error(null, "空出处理失败:" + sendResult.Msg);
}
}
else
{
return temp;
}
}
else
{
return BllResultFactory.Error(null, $"{device}对应的任务Id:{taskProp.value}已完成");
}
}
else
{
return BllResultFactory.Error(null, $"未找到{device}对应的任务Id:{taskProp.value}");
}
}
|
liufu
authored
|
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
|
/// <summary>
/// 同巷道内移库
/// </summary>
/// <param name="stockers"></param>
private void ExcuteTaskTransferInRoadway(List<DeviceEntity> stockers)
{
List<TaskEntity> taskEntities = GetAllTaskOut();
foreach (var task in taskEntities)
{
if (task.Type == 800)
{
var temp1 = Bll.GetAllLocations(null, null, null, null, null, null, task.SourceLocation);
var temp2 = Bll.GetAllLocations(null, null, null, null, null, null, task.DestinationLocation);
if (!temp1.Success || !temp2.Success)
{
AddLogToUI("执行移库任务:" + task.Id + ",未找到移库库位" + task.SourceLocation + "或" + task.DestinationLocation, 2);
continue;
}
var location1 = temp1.Data[0];
var location2 = temp2.Data[0];
if (location1.Roadway == location2.Roadway)
{
//如果是同一个巷道
//查看巷道堆垛机
int stockerCount = stockers.Count(t => t.Roadway == location1.Roadway);
if (stockerCount != 1)
{
AddLogToUI("任务" + task.Id + "获取巷道堆垛机失败,巷道:" + location1.Roadway + " 对应:" + stockerCount + "个", 2);
continue;
}
var stocker = stockers.Find(t => t.Roadway == location1.Roadway);
//获取这个堆垛机的地址
//地址校验交由初始化完成
var props = DeviceAddressEntities.Where(t => t.DeviceId == stocker.Id).ToList();
//堆垛机出库任务校验
var result = ReadAddress(props);
if (result.Success)
{
if (ValidateStockerTransferInRoadway(props))
{
var tempResult = SendTaskToStocker(props, "3", "0", location1.Row.ToString(), location1.Layer.ToString(), location1.Column.ToString(), location2.Row.ToString(), location2.Layer.ToString(), location2.Column.ToString(), task.Id.ToString(), "0");
if (!tempResult.Success)
{
AddLogToUI("堆垛机" + stocker.ToString() + "下发任务失败:" + tempResult.Msg, 2);
}
else
{
//同巷道的移库,更新任务状态到38
Bll.SetTaskStatus(task.Id, 38);
AddLogToUI("堆垛机" + stocker.ToString() + "下发任务成功,任务号:" + task.Id, 1);
}
}
}
else
{
AddLogToUI("读取" + stocker + "地址数据失败", 2);
}
}
}
}
}
|
liufu
authored
|
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
|
private void SendToLED(TaskEntity taskEntity)
{
string taskType = AppCommon.GetTaskType(taskEntity.Type.ToString());
string locationCode = "";
if (!String.IsNullOrEmpty(taskEntity.SourceLocation))
{
locationCode += taskEntity.SourceLocation;
}
if (!string.IsNullOrEmpty(taskEntity.DestinationLocation))
{
if (string.IsNullOrEmpty(locationCode))
{
locationCode += taskEntity.DestinationLocation;
}
else
{
locationCode += "->" + taskEntity.DestinationLocation;
}
}
|
liufu
authored
|
1311
|
string text = String.Format("任务号:{0}\\n任务类型:{1}\\n托盘条码:{2}\\n仓位:{3}", taskEntity.Id, taskType, taskEntity.ContainerCode, locationCode);
|
liufu
authored
|
1312
1313
1314
|
led.SendLedInfo(text);
}
|
liufu
authored
|
1315
|
/// <summary>
|
liufu
authored
|
1316
|
/// 响应堆垛机入库任务
|
liufu
authored
|
1317
1318
1319
1320
|
/// </summary>
/// <param name="stockers"></param>
private void ExcuteTaskIn(List<DeviceEntity> stockers)
{
|
liufu
authored
|
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
|
//查询状态为35的任务
var result = Bll.GetTasks("35", null, null, null, null);
if (result.Success)
{
var tasks = result.Data;
foreach (var task in tasks)
{
LocationEntity locationEntity = null;
if (task.Type == 100 || task.Type == 500 || task.Type == 800)
{
var locationResult = Bll.GetAllLocations(null, null, null, null, null, null, task.DestinationLocation);
if (locationResult.Success)
{
locationEntity = locationResult.Data[0];
}
else
{
AddLogToUI("任务" + task.Id + "对应货位" + task.DestinationLocation + "未找到", 2);
continue;
}
|
liufu
authored
|
1341
|
|
liufu
authored
|
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
|
}
else if (task.Type == 200 || task.Type == 400 || task.Type == 700)
{
var locationResult = Bll.GetAllLocations(null, null, null, null, null, null, task.SourceLocation);
if (locationResult.Success)
{
locationEntity = locationResult.Data[0];
}
else
{
AddLogToUI("任务" + task.Id + "对应货位" + task.SourceLocation + "未找到", 2);
continue;
}
}
else
{
AddLogToUI("任务" + task.Id + "类型不符合堆垛机执行入库,类型:" + task.Type, 2);
continue;
}
//通过货位所在巷道来查询堆垛机
var stocker = stockers.Find(t => t.Roadway == locationEntity.Roadway);
if (stocker == null)
{
AddLogToUI("未配置巷道" + locationEntity.Roadway + "对应的堆垛机,无法执行入库任务" + task.Id, 2);
continue;
}
//校验这个堆垛机是否可以执行入库任务
var addresses = DeviceAddressEntities.FindAll(t => t.DeviceId == stocker.Id);
var readResult = ReadAddress(addresses);
if (!readResult.Success)
{
AddLogToUI("读取地址失败,堆垛机:" + stocker, 2);
continue;
}
if (ValidateStockerIn(addresses))
{
//下发任务
|
liufu
authored
|
1379
|
var sendResult = SendTaskToStocker(addresses, "1", "0", "0", "0", "0", locationEntity.Row.ToString(), locationEntity.Layer.ToString(), locationEntity.Column.ToString(), task.Id.ToString(), "0");
|
liufu
authored
|
1380
1381
1382
1383
1384
1385
1386
1387
1388
|
if (!sendResult.Success)
{
AddLogToUI("下发堆垛机" + stocker + "任务" + task.Id + "失败:" + sendResult.Msg, 2);
continue;
}
else
{
//刷新任务状态到38
Bll.SetTaskStatus(task.Id, 38);
|
liufu
authored
|
1389
|
AddLogToUI("下发堆垛机" + stocker + "任务" + task.Id + "成功。", 1);
|
liufu
authored
|
1390
1391
1392
1393
|
}
}
}
}
|
liufu
authored
|
1394
1395
1396
|
}
/// <summary>
|
liufu
authored
|
1397
|
/// 响应堆垛机任务完成
|
liufu
authored
|
1398
1399
1400
1401
1402
1403
1404
|
/// </summary>
/// <param name="stockers"></param>
private void ExcuteTaskComplete(List<DeviceEntity> stockers)
{
foreach (var stocker in stockers)
{
var propDatas = DeviceAddressEntities.FindAll(t => t.DeviceId == stocker.Id);
|
liufu
authored
|
1405
1406
|
var result = ReadAddress(propDatas);
if (result.Success)
|
liufu
authored
|
1407
|
{
|
liufu
authored
|
1408
|
if (ValidateStockerForCompleteTask(propDatas))
|
liufu
authored
|
1409
|
{
|
liufu
authored
|
1410
1411
|
//获取任务号
var propData = propDatas.Find(t => t.DevicePropCode == "TaskNo1");
|
liufu
authored
|
1412
1413
1414
|
//判断任务状态
var taskResult = Bll.GetTasks(null, propData.value, null, null, null);
if (!taskResult.Success)
|
liufu
authored
|
1415
|
{
|
liufu
authored
|
1416
|
AddLogToUI("堆垛机" + stocker + "任务" + propData.value + ",未获取到任务", 2);
|
liufu
authored
|
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
|
continue;
}
TaskEntity taskEntity = taskResult.Data[0];
if (taskEntity.Status < 25)
{
//说明堆垛机是在执行出库任务,更新任务到25
var temp1 = Bll.SetTaskStatus(taskEntity.Id, 25);
if (!temp1.Success)
{
AddLogToUI("堆垛机" + stocker + "完成任务" + taskEntity.Id + "时,更新任务状态失败:" + temp1.Msg, 2);
continue;
}
else
|
liufu
authored
|
1430
|
{
|
liufu
authored
|
1431
|
AddLogToUI("堆垛机" + stocker + "完成任务" + taskEntity.Id + "时,更新任务状态成功" + temp1.Msg, 1);
|
liufu
authored
|
1432
1433
1434
1435
|
}
}
else
{
|
liufu
authored
|
1436
1437
1438
1439
1440
1441
1442
1443
1444
|
//说明堆垛机是在执行入的,此时完成任务
var temp1 = Bll.CompleteTask(taskEntity.Id.ToString());
if (!temp1.Success)
{
AddLogToUI("堆垛机" + stocker + "完成任务" + taskEntity.Id + "时失败:" + temp1.Msg, 2);
continue;
}
else
{
|
liufu
authored
|
1445
|
AddLogToUI("堆垛机" + stocker + "完成任务" + taskEntity.Id + "成功", 1);
|
liufu
authored
|
1446
1447
1448
1449
1450
1451
|
}
}
//任务完成成功:任务执行完成后由PLC向WCS发送任务完成消息,WCS清除任务信息,随后PLC更新堆垛机状态为待机
//清除任务,hack:这里暂时只清除了任务号
|
liufu
authored
|
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
|
//var temp2 = propDatas.Where(t => t.DevicePropCode == "TaskNo1" || t.DevicePropCode == "TaskNo2").ToList();
//temp2.ForEach(t => t.value = "0");
//var writeResult = WriteAddress(temp2);
//if (!writeResult.Success)
//{
// AddLogToUI("完成任务" + propData.value + "成功,但是清除堆垛机" + stocker.ToString() + "任务失败", 2);
//}
//这里清除wcs区
var sendResult = SendTaskToStocker(propDatas, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0");
if (sendResult.Success)
{
|
liufu
authored
|
1463
|
AddLogToUI("清除堆垛机" + stocker.ToString() + "任务" + taskEntity.Id + "成功", 1);
|
liufu
authored
|
1464
1465
|
}
else
|
liufu
authored
|
1466
|
{
|
liufu
authored
|
1467
|
AddLogToUI("清除堆垛机" + stocker.ToString() + "任务" + taskEntity.Id + "失败", 2);
|
liufu
authored
|
1468
1469
1470
|
}
}
}
|
liufu
authored
|
1471
1472
1473
1474
|
else
{
AddLogToUI("读取" + stocker + "地址数据失败:" + result.Msg, 2);
}
|
liufu
authored
|
1475
1476
1477
1478
|
}
}
/// <summary>
|
liufu
authored
|
1479
|
/// 数据类型转换WCS-->PLC
|
liufu
authored
|
1480
1481
1482
1483
|
/// </summary>
/// <param name="type"></param>
/// <param name="v"></param>
/// <returns></returns>
|
liufu
authored
|
1484
|
private BllResult TansforWCSDataToAddressData(string type, string data)
|
liufu
authored
|
1485
|
{
|
liufu
authored
|
1486
1487
1488
1489
1490
1491
1492
1493
|
try
{
object obj = null;
switch (type)
{
case "BYTE": obj = Convert.ToUInt16(data); break;
case "DWORD": obj = Convert.ToUInt32(data); break;
case "BOOL": obj = Convert.ToBoolean(data); break;
|
liufu
authored
|
1494
|
case "WORD": obj = Convert.ToUInt16(data); break;
|
liufu
authored
|
1495
|
case "CHAR": obj = Bll.StringToASCII(data+"\u0003"); break;
|
liufu
authored
|
1496
1497
1498
1499
1500
1501
1502
|
default:
obj = data;
break;
}
return BllResultFactory.Sucess(obj, "成功");
}
catch (Exception ex)
|
liufu
authored
|
1503
|
{
|
liufu
authored
|
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
|
return BllResultFactory.Error(null, "WCS到PLC数据转换出现异常,值:" + data + " 目标类型:" + type + " 异常:" + ex.ToString());
}
}
/// <summary>
/// 数据类型转换PLC-->WCS
/// </summary>
/// <param name="type"></param>
/// <param name="data"></param>
/// <returns></returns>
private BllResult<String> TransforAddressDataToWCSData(string type, object data)
{
string str;
try
{
switch (type)
{
case "BYTE":
case "DWORD":
case "BOOL":
case "WORD": str = data.ToString(); break;
|
liufu
authored
|
1525
|
case "CHAR": str = Bll.ASCIIToString((short[])data).Trim().Replace("\u0003",""); break;
|
liufu
authored
|
1526
1527
1528
1529
1530
1531
1532
1533
1534
|
default:
str = data.ToString();
break;
}
return BllResultFactory.Sucess<string>(str, "成功");
}
catch (Exception ex)
{
return BllResultFactory.Error<string>(null, "PLC到WCS数据转换出现异常,值:" + data + " 目标类型:" + type + " 异常:" + ex.ToString());
|
liufu
authored
|
1535
1536
1537
1538
|
}
}
/// <summary>
|
liufu
authored
|
1539
|
/// 校验堆垛机是否可以进行任务完成
|
liufu
authored
|
1540
1541
1542
|
/// </summary>
/// <param name="stocker"></param>
/// <returns></returns>
|
liufu
authored
|
1543
|
private bool ValidateStockerForCompleteTask(List<DeviceAddressEntity> addresses)
|
liufu
authored
|
1544
|
{
|
liufu
authored
|
1545
1546
1547
1548
|
if (addresses.Find(t => t.DevicePropCode == "TaskExcuteStatus").value == "3"
//这里加上WCS交换区检测,防止PLC来不及反应重复完成任务,交换区数据是会在完成任务后才会清除
&& addresses.First(t => t.DevicePropCode == "WCSTaskFlag").value != "0"
)
|
liufu
authored
|
1549
1550
1551
1552
1553
1554
1555
|
{
return true;
}
else
{
return false;
}
|
liufu
authored
|
1556
1557
1558
1559
|
}
/// <summary>
/// 堆垛机执行出库任务
|
liufu
authored
|
1560
|
/// hack:这里需要和电气讨论任务校验失败的情况
|
liufu
authored
|
1561
1562
1563
1564
1565
1566
|
/// </summary>
/// <param name="taskEntities"></param>
/// <param name="stockers"></param>
private void ExcuteTaskOut(List<DeviceEntity> stockers)
{
List<TaskEntity> taskEntities = GetAllTaskOut();
|
liufu
authored
|
1567
|
taskEntities = taskEntities.OrderBy(t => t.LastUpdated).ToList();
|
liufu
authored
|
1568
1569
1570
|
foreach (var task in taskEntities)
{
//获取任务所在巷道,即库位对应的巷道
|
liufu
authored
|
1571
|
var BllResult = Bll.GetAllLocations(task.ContainerCode, null, null, null, null, null, null);
|
liufu
authored
|
1572
|
if (!BllResult.Success)
|
liufu
authored
|
1573
|
{
|
liufu
authored
|
1574
|
AddLogToUI("任务" + task.Id + "获取库位失败,消息:" + BllResult.Msg, 2);
|
liufu
authored
|
1575
1576
|
continue;
}
|
liufu
authored
|
1577
|
var location = BllResult.Data[0];
|
liufu
authored
|
1578
|
//查看巷道堆垛机
|
liufu
authored
|
1579
1580
1581
1582
1583
1584
|
int stockerCount = stockers.Count(t => t.Roadway == location.Roadway);
if (stockerCount != 1)
{
AddLogToUI("任务" + task.Id + "获取巷道堆垛机失败,巷道:" + location.Roadway + " 对应:" + stockerCount + "个", 2);
continue;
}
|
liufu
authored
|
1585
|
var stocker = stockers.Find(t => t.Roadway == location.Roadway);
|
liufu
authored
|
1586
1587
1588
1589
|
//获取这个堆垛机的地址
//地址校验交由初始化完成
var props = DeviceAddressEntities.Where(t => t.DeviceId == stocker.Id).ToList();
//堆垛机出库任务校验
|
liufu
authored
|
1590
1591
|
var result = ReadAddress(props);
if (result.Success)
|
liufu
authored
|
1592
|
{
|
liufu
authored
|
1593
|
if (ValidateStockerOut(props))
|
liufu
authored
|
1594
|
{
|
liufu
authored
|
1595
|
//判断任务是不是移库,如果是移库,判断两个库位是不是在同一个巷道
|
liufu
authored
|
1596
|
if (task.Type == 800)
|
liufu
authored
|
1597
1598
1599
|
{
var temp1 = Bll.GetAllLocations(null, null, null, null, null, null, task.SourceLocation);
var temp2 = Bll.GetAllLocations(null, null, null, null, null, null, task.DestinationLocation);
|
liufu
authored
|
1600
|
if (!temp1.Success || !temp2.Success)
|
liufu
authored
|
1601
|
{
|
liufu
authored
|
1602
|
AddLogToUI("堆垛机" + stocker + "执行移库任务时" + task.Id + "未找到移库库位" + task.SourceLocation + "或" + task.DestinationLocation, 2);
|
liufu
authored
|
1603
1604
1605
1606
1607
1608
1609
|
continue;
}
var location1 = temp1.Data[0];
var location2 = temp2.Data[0];
if (location1.Roadway == location2.Roadway)
{
//如果是同一个巷道
|
liufu
authored
|
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
|
//var tempResult = SendTaskToStocker(props, "3", "0", location1.Row.ToString(), location1.Layer.ToString(), location1.Column.ToString(), location2.Row.ToString(), location2.Layer.ToString(), location2.Column.ToString(), task.Id.ToString(), "0");
//if (!tempResult.Success)
//{
// AddLogToUI("堆垛机" + stocker.ToString() + "下发任务失败:" + tempResult.Msg, 2);
//}
//else
//{
// //同巷道的移库,更新任务状态到38
// Bll.SetTaskStatus(task.Id, 38);
// AddLogToUI("堆垛机" + stocker.ToString() + "下发任务成功,任务号:" + task.Id, 1);
//}
|
liufu
authored
|
1621
1622
1623
|
continue;
}
}
|
liufu
authored
|
1624
1625
|
//这里不再校验出库站台是否空闲,判断堆垛机工作状态即可;
//可用,下发任务
|
liufu
authored
|
1626
|
BllResult sendResult = SendTaskToStocker(props, "2", "0", location.Row.ToString(), location.Layer.ToString(), location.Column.ToString(), "0", "0", "0", task.Id.ToString(), "0");
|
liufu
authored
|
1627
|
if (!BllResult.Success)
|
liufu
authored
|
1628
|
{
|
liufu
authored
|
1629
1630
1631
1632
|
AddLogToUI("堆垛机" + stocker.ToString() + "下发任务失败:" + sendResult.Msg, 2);
}
else
{
|
liufu
authored
|
1633
1634
|
//更新任务到开始执行
Bll.SetTaskStatus(task.Id, 20);
|
liufu
authored
|
1635
|
AddLogToUI("堆垛机" + stocker.ToString() + "下发任务成功,任务号:" + task.Id, 1);
|
liufu
authored
|
1636
1637
1638
|
}
}
}
|
liufu
authored
|
1639
1640
1641
1642
|
else
{
AddLogToUI("读取" + stocker + "地址数据失败", 2);
}
|
liufu
authored
|
1643
1644
1645
1646
|
}
}
/// <summary>
|
liufu
authored
|
1647
|
/// 下发任务,校验码先不做
|
liufu
authored
|
1648
|
/// </summary>
|
liufu
authored
|
1649
1650
|
/// <param name="addresses"></param>
/// <param name="task"></param>
|
liufu
authored
|
1651
|
/// <returns></returns>
|
liufu
authored
|
1652
|
private BllResult SendTaskToStocker(List<DeviceAddressEntity> addresses, string flag, string stop, string fromRow, string fromLayer, string fromColumn, string toRow, string toLayer, string toColumn, string taskNo, string validateCode)
|
liufu
authored
|
1653
|
{
|
liufu
authored
|
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
|
try
{
List<DeviceAddressEntity> temp = new List<DeviceAddressEntity>();
var wcsFlag = addresses.Find(t => t.DevicePropCode == "WCSTaskFlag");
wcsFlag.value = flag;
var wcsStop = addresses.Find(t => t.DevicePropCode == "WCSStop");
wcsStop.value = stop;
var wcsFromRow = addresses.Find(t => t.DevicePropCode == "WCSFromRow");
wcsFromRow.value = fromRow;
var wcsFromLayer = addresses.Find(t => t.DevicePropCode == "WCSFromLayer");
wcsFromLayer.value = fromLayer;
var wcsFromColumn = addresses.Find(t => t.DevicePropCode == "WCSFromColumn");
wcsFromColumn.value = fromColumn;
var wcsToRow = addresses.Find(t => t.DevicePropCode == "WCSToRow");
wcsToRow.value = toRow;
var wcsToLayer = addresses.Find(t => t.DevicePropCode == "WCSToLayer");
wcsToLayer.value = toLayer;
var wcsToColumn = addresses.Find(t => t.DevicePropCode == "WCSToColumn");
wcsToColumn.value = toColumn;
var wcsTaskNo = addresses.Find(t => t.DevicePropCode == "WCSTaskNo");
wcsTaskNo.value = taskNo;
|
liufu
authored
|
1675
|
var wcsValidateCode = addresses.Find(t => t.DevicePropCode == "WCSValidateCode");
|
liufu
authored
|
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
|
wcsValidateCode.value = validateCode;
temp.Add(wcsFlag);
temp.Add(wcsStop);
temp.Add(wcsFromRow);
temp.Add(wcsFromLayer);
temp.Add(wcsFromColumn);
temp.Add(wcsToColumn);
temp.Add(wcsToLayer);
temp.Add(wcsToRow);
temp.Add(wcsTaskNo);
temp.Add(wcsValidateCode);
return WriteAddress(temp);
}
catch (Exception ex)
{
return BllResultFactory.Error(null, "异常:" + ex.ToString());
}
|
liufu
authored
|
1693
1694
1695
|
}
/// <summary>
|
liufu
authored
|
1696
|
/// 获取所有未完成的出库任务,注意这里只会返回状态为10的任务
|
liufu
authored
|
1697
1698
1699
1700
1701
|
/// </summary>
/// <returns></returns>
private static List<TaskEntity> GetAllTaskOut()
{
List<TaskEntity> taskEntities = new List<TaskEntity>();
|
liufu
authored
|
1702
|
var result = Bll.GetTasks("10", null, null, null, null);
|
liufu
authored
|
1703
1704
1705
1706
1707
1708
1709
1710
1711
|
if (result.Success)
{
taskEntities = result.Data.Where(t => t.Type == 300 || t.Type == 400 || t.Type == 600 || t.Type == 700 || t.Type == 800).ToList();
}
return taskEntities;
}
/// <summary>
|
liufu
authored
|
1712
|
/// 添加界面日志,1绿色,2红色,3黄色
|
liufu
authored
|
1713
1714
1715
|
/// </summary>
/// <param name="log"></param>
/// <param name="level"></param>
|
liufu
authored
|
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
|
private void AddLogToUI(string log, int level)
{
this.Dispatcher.Invoke(new Action(() =>
{
this.LogInfo.AddLogs(log, level);
}));
}
/// <summary>
/// 读取所有地址数据
/// </summary>
|
liufu
authored
|
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
|
private BllResult ReadAllAddressData()
{
return ReadAddress(DeviceAddressEntities);
}
/// <summary>
/// 读取特定地址
/// </summary>
/// <param name="deviceAddressEntities"></param>
private BllResult ReadAddress(List<DeviceAddressEntity> deviceAddressEntities)
|
liufu
authored
|
1737
|
{
|
liufu
authored
|
1738
|
if (PLC == null || PLC.GetConnStatus() == false || deviceAddressEntities == null || deviceAddressEntities.Count == 0)
|
liufu
authored
|
1739
|
{
|
liufu
authored
|
1740
1741
|
//AddLogToUI("地址读取失败,请检查通讯连接", 2);
return BllResultFactory.Error(null, "地址读取失败,请检查通讯连接");
|
liufu
authored
|
1742
|
}
|
liufu
authored
|
1743
1744
|
var temp = deviceAddressEntities.Join(DeviceEntities, a => a.DeviceId, b => b.Id, (a, b) => new { a, b }).Join(DevicePropEntities, a => new { a = a.a.DevicePropCode, b = a.b.DeviceTypeId }, b => new { a = b.Code, b = b.DeviceTypeId }, (a, b) => new { address = a.a, b = b.Type }).ToList();
if (temp.Count != deviceAddressEntities.Count)
|
liufu
authored
|
1745
|
{
|
liufu
authored
|
1746
|
return BllResultFactory.Error(null, "读取地址时,传入地址与实际属性不匹配,请检查基础数据");
|
liufu
authored
|
1747
|
}
|
liufu
authored
|
1748
1749
1750
1751
|
int[] handles = temp.Select(t => t.address.ServerHandle).ToArray();
var array = PLC.ReadData(handles);
for (int i = 0; i < temp.Count; i++)
|
liufu
authored
|
1752
|
{
|
liufu
authored
|
1753
1754
|
var result = TransforAddressDataToWCSData(temp[i].b, array.GetValue(i + 1));
if (!result.Success)
|
liufu
authored
|
1755
|
{
|
liufu
authored
|
1756
|
return BllResultFactory.Error(null, "转换PLC数据到WCS类型错误,值:" + array.GetValue(i + 1) + " 类型:" + temp[i].b);
|
liufu
authored
|
1757
|
}
|
liufu
authored
|
1758
|
temp[i].address.value = result.Data;
|
liufu
authored
|
1759
|
}
|
liufu
authored
|
1760
|
return BllResultFactory.Sucess(null, "成功");
|
liufu
authored
|
1761
1762
1763
|
}
/// <summary>
|
liufu
authored
|
1764
|
/// 写入PLC数据
|
liufu
authored
|
1765
1766
|
/// </summary>
/// <param name="deviceAddressEntities"></param>
|
liufu
authored
|
1767
1768
|
/// <returns></returns>
private BllResult WriteAddress(List<DeviceAddressEntity> deviceAddressEntities)
|
liufu
authored
|
1769
1770
1771
|
{
if (PLC == null || PLC.GetConnStatus() == false || deviceAddressEntities == null || deviceAddressEntities.Count == 0)
{
|
liufu
authored
|
1772
|
return BllResultFactory.Error(null, "地址读取失败,请检查通讯连接");
|
liufu
authored
|
1773
|
}
|
liufu
authored
|
1774
1775
1776
1777
1778
1779
1780
1781
|
var temp = deviceAddressEntities.Join(DeviceEntities, a => a.DeviceId, b => b.Id, (a, b) => new { a, b }).Join(DevicePropEntities, a => new { a = a.a.DevicePropCode, b = a.b.DeviceTypeId }, b => new { a = b.Code, b = b.DeviceTypeId }, (a, b) => new { address = a.a, b = b.Type }).ToList();
if (temp.Count != deviceAddressEntities.Count)
{
return BllResultFactory.Error(null, "写入地址数据时,传入地址与实际属性不匹配,请检查基础数据");
}
var serverHandel = deviceAddressEntities.Select(t => t.ServerHandle).ToArray();
object[] values = new object[serverHandel.Count<int>()];
for (int i = 0; i < temp.Count; i++)
|
liufu
authored
|
1782
|
{
|
liufu
authored
|
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
|
var result = TansforWCSDataToAddressData(temp[i].b, temp[i].address.value);
if (!result.Success)
{
return BllResultFactory.Error(null, "转换WCS数据到PLC类型错误,值:" + temp[i].address.value + " 类型:" + temp[i].b);
}
values[i] = result.Data;
}
if (PLC.WriteData(serverHandel, values))
{
return BllResultFactory.Sucess(null, "成功");
|
liufu
authored
|
1793
|
}
|
liufu
authored
|
1794
1795
1796
1797
1798
|
else
{
return BllResultFactory.Error(null, "写入失败!");
}
|
liufu
authored
|
1799
1800
1801
|
}
/// <summary>
|
liufu
authored
|
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
|
/// 写入WCS站台区地址
/// </summary>
/// <param name="addresses"></param>
/// <param name="flag"></param>
/// <param name="type"></param>
/// <param name="loadstatus"></param>
/// <param name="stationno"></param>
/// <param name="taskno"></param>
/// <param name="barcode"></param>
/// <param name="backup"></param>
/// <returns></returns>
private BllResult WriteWCSStationDataAddress(List<DeviceAddressEntity> addresses, string flag, string type, string plcno, string loadstatus, string stationno, string taskno, string barcode, string toaddress, string backup)
{
List<DeviceAddressEntity> temp = new List<DeviceAddressEntity>();
var wcsflag = addresses.Find(t => t.DevicePropCode == "WCSFlag");
wcsflag.value = flag;
var wcstype = addresses.Find(t => t.DevicePropCode == "WCSType");
wcstype.value = type;
var wcsplcno = addresses.Find(t => t.DevicePropCode == "WCSPLCNo");
wcsplcno.value = plcno;
var wcsloadstatus = addresses.Find(t => t.DevicePropCode == "LoadStatus");
wcsloadstatus.value = loadstatus;
var wcsstationno = addresses.Find(t => t.DevicePropCode == "WCSStationNo");
wcsstationno.value = stationno;
var wcstaskno = addresses.Find(t => t.DevicePropCode == "WCSTaskNo");
wcstaskno.value = taskno;
var wcsbarcode = addresses.Find(t => t.DevicePropCode == "WCSBarcode");
wcsbarcode.value = barcode;
var wcstoaddress = addresses.Find(t => t.DevicePropCode == "WCSToAddress");
wcstoaddress.value = toaddress;
var wcsbackup = addresses.Find(t => t.DevicePropCode == "WCSBackUp");
wcsbackup.value = backup;
temp.Add(wcsflag);
temp.Add(wcstype);
temp.Add(wcsplcno);
temp.Add(wcsloadstatus);
temp.Add(wcsstationno);
temp.Add(wcstaskno);
temp.Add(wcsbarcode);
temp.Add(wcstoaddress);
temp.Add(wcsbackup);
return WriteAddress(temp);
}
/// <summary>
|
liufu
authored
|
1847
1848
1849
1850
|
/// 堆垛机出库任务校验
/// 堆垛机接收任务(入库、出库、拣选、转库)条件:
///1. 工作模式=2 联机;
///2. 操作模式=5 联机;
|
liufu
authored
|
1851
|
///3. 工作状态=0 待机,或者等于2 出库;
|
liufu
authored
|
1852
1853
1854
1855
|
///4. DB101.DBB19=1 待机; 执行状态
///5. 叉原位,叉上无货;
///6. 堆垛机无故障;hack:?????哪个地址???
///7. 写入任务,任务号,任务标志=1—4
|
liufu
authored
|
1856
|
///hack:根据协议,出入库堆垛机条件其实是一样的,只是写入的任务和标志不同,工作状态不同
|
liufu
authored
|
1857
1858
1859
1860
1861
1862
1863
1864
1865
|
/// </summary>
/// <param name="deviceAddressEntities"></param>
/// <returns></returns>
private bool ValidateStockerOut(List<DeviceAddressEntity> deviceAddressEntities)
{
try
{
if (deviceAddressEntities.First(t => t.DevicePropCode == "WorkModel").value == "2"
&& deviceAddressEntities.First(t => t.DevicePropCode == "OperationModel").value == "5"
|
liufu
authored
|
1866
|
&& (deviceAddressEntities.First(t => t.DevicePropCode == "WorkStatus").value == "0" || deviceAddressEntities.First(t => t.DevicePropCode == "WorkStatus").value == "2" )
|
liufu
authored
|
1867
1868
1869
|
&& deviceAddressEntities.First(t => t.DevicePropCode == "TaskExcuteStatus").value == "1"
&& deviceAddressEntities.First(t => t.DevicePropCode == "HasPallet").value == "1"
&& deviceAddressEntities.First(t => t.DevicePropCode == "TaskNo1").value == "0"
|
liufu
authored
|
1870
1871
|
//这里加上WCS交换区检测,防止PLC来不及反应重复写入任务
&& deviceAddressEntities.First(t => t.DevicePropCode == "WCSTaskFlag").value == "0"
|
liufu
authored
|
1872
1873
1874
1875
1876
|
)
{
return true;
}
}
|
liufu
authored
|
1877
|
catch (ArgumentNullException)
|
liufu
authored
|
1878
1879
1880
|
{
AddLogToUI("堆垛机属性地址不明确", 2);
}
|
liufu
authored
|
1881
|
catch (Exception)
|
liufu
authored
|
1882
1883
1884
1885
1886
1887
|
{
AddLogToUI("堆垛机属性地址不明确", 2);
}
return false;
}
|
liufu
authored
|
1888
|
/// <summary>
|
liufu
authored
|
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
|
/// 巷道内移库任务校验条件
/// </summary>
/// <param name="deviceAddressEntities"></param>
/// <returns></returns>
private bool ValidateStockerTransferInRoadway(List<DeviceAddressEntity> deviceAddressEntities)
{
try
{
if (deviceAddressEntities.First(t => t.DevicePropCode == "WorkModel").value == "2"
&& deviceAddressEntities.First(t => t.DevicePropCode == "OperationModel").value == "5"
|
liufu
authored
|
1899
|
&& (deviceAddressEntities.First(t => t.DevicePropCode == "WorkStatus").value == "0" || deviceAddressEntities.First(t => t.DevicePropCode == "WorkStatus").value == "3")
|
liufu
authored
|
1900
1901
1902
|
&& deviceAddressEntities.First(t => t.DevicePropCode == "TaskExcuteStatus").value == "1"
&& deviceAddressEntities.First(t => t.DevicePropCode == "HasPallet").value == "1"
&& deviceAddressEntities.First(t => t.DevicePropCode == "TaskNo1").value == "0"
|
liufu
authored
|
1903
1904
|
//这里加上WCS交换区检测,防止PLC来不及反应重复写入任务
&& deviceAddressEntities.First(t => t.DevicePropCode == "WCSTaskFlag").value == "0"
|
liufu
authored
|
1905
1906
1907
1908
1909
|
)
{
return true;
}
}
|
liufu
authored
|
1910
|
catch (ArgumentNullException)
|
liufu
authored
|
1911
1912
1913
|
{
AddLogToUI("堆垛机属性地址不明确", 2);
}
|
liufu
authored
|
1914
|
catch (Exception)
|
liufu
authored
|
1915
1916
1917
1918
1919
1920
1921
|
{
AddLogToUI("堆垛机属性地址不明确", 2);
}
return false;
}
/// <summary>
|
liufu
authored
|
1922
1923
1924
1925
|
/// 堆垛机入库任务校验
/// </summary>
/// <param name="deviceAddressEntities"></param>
/// <returns></returns>
|
liufu
authored
|
1926
1927
1928
1929
1930
1931
1932
|
private bool ValidateStockerIn(List<DeviceAddressEntity> deviceAddressEntities)
{
try
{
if (deviceAddressEntities.First(t => t.DevicePropCode == "WorkModel").value == "2"
&& deviceAddressEntities.First(t => t.DevicePropCode == "OperationModel").value == "5"
&& (deviceAddressEntities.First(t => t.DevicePropCode == "WorkStatus").value == "0" || deviceAddressEntities.First(t => t.DevicePropCode == "WorkStatus").value == "1")
|
liufu
authored
|
1933
1934
1935
|
&& deviceAddressEntities.First(t => t.DevicePropCode == "TaskExcuteStatus").value == "1"
&& deviceAddressEntities.First(t => t.DevicePropCode == "HasPallet").value == "1"
&& deviceAddressEntities.First(t => t.DevicePropCode == "TaskNo1").value == "0"
|
liufu
authored
|
1936
1937
|
//这里加上WCS交换区检测,防止PLC来不及反应重复写入任务
&& deviceAddressEntities.First(t => t.DevicePropCode == "WCSTaskFlag").value == "0"
|
liufu
authored
|
1938
1939
1940
1941
1942
|
)
{
return true;
}
}
|
liufu
authored
|
1943
|
catch (ArgumentNullException)
|
liufu
authored
|
1944
1945
1946
|
{
AddLogToUI("堆垛机属性地址不明确", 2);
}
|
liufu
authored
|
1947
|
catch (Exception)
|
liufu
authored
|
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
|
{
AddLogToUI("堆垛机属性地址不明确", 2);
}
return false;
}
/// <summary>
/// 查找指定设备类型
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
|
liufu
authored
|
1959
|
private BllResult<List<DeviceEntity>> FindDevByType(string type)
|
liufu
authored
|
1960
1961
1962
|
{
try
{
|
liufu
authored
|
1963
|
var temp = DeviceEntities.Join(DeviceTypeEntities, a => a.DeviceTypeId, b => b.Id, (a, b) => new
|
liufu
authored
|
1964
1965
1966
1967
|
{
a,
b
}).Where(c => c.b.Code == type).Select(d => d.a).ToList();
|
liufu
authored
|
1968
|
return BllResultFactory.Sucess<List<DeviceEntity>>(temp, "成功");
|
liufu
authored
|
1969
1970
1971
|
}
catch (Exception)
{
|
liufu
authored
|
1972
|
return BllResultFactory.Error<List<DeviceEntity>>(new List<DeviceEntity>(), "异常或没有数据");
|
liufu
authored
|
1973
1974
1975
1976
1977
1978
1979
|
}
}
#endregion
#region 窗体事件
|
liufu
authored
|
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
|
private void Menu_pallet_Click(object sender, RoutedEventArgs e)
{
Frm_Pallet frm_Pallet = (Frm_Pallet)windows.FirstOrDefault(t => t.Key == "frm_Pallet").Value;
if (frm_Pallet == null)
{
frm_Pallet = new Frm_Pallet();
windows.Add("frm_Pallet", frm_Pallet);
}
frm_Pallet.Show();
if (frm_Pallet.WindowState == WindowState.Minimized)
frm_Pallet.WindowState = WindowState.Normal;
frm_Pallet.Activate();
}
private void Menu_location_Click(object sender, RoutedEventArgs e)
{
Frm_Location frm_Location = (Frm_Location)windows.FirstOrDefault(t => t.Key == "frm_Location").Value;
if (frm_Location == null)
{
frm_Location = new Frm_Location();
windows.Add("frm_Location", frm_Location);
}
frm_Location.Show();
if (frm_Location.WindowState == WindowState.Minimized)
frm_Location.WindowState = WindowState.Normal;
frm_Location.Activate();
}
|
liufu
authored
|
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
|
private void Menu_device_OPCTest_Click(object sender, RoutedEventArgs e)
{
Frm_OPCTest frm_OPCTest = (Frm_OPCTest)windows.FirstOrDefault(t => t.Key == "frm_OPCTest").Value;
if (frm_OPCTest == null)
{
frm_OPCTest = new Frm_OPCTest();
windows.Add("frm_OPCTest", frm_OPCTest);
}
frm_OPCTest.Show();
if (frm_OPCTest.WindowState == WindowState.Minimized)
frm_OPCTest.WindowState = WindowState.Normal;
frm_OPCTest.Activate();
}
|
liufu
authored
|
2022
2023
|
private void Menu_task_info_Click(object sender, RoutedEventArgs e)
{
|
liufu
authored
|
2024
|
Frm_TaskInfo frm_TaskInfo = (Frm_TaskInfo)windows.FirstOrDefault(t => t.Key == "frm_taskinfo").Value;
|
liufu
authored
|
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
|
if (frm_TaskInfo == null)
{
frm_TaskInfo = new Frm_TaskInfo();
windows.Add("frm_taskinfo", frm_TaskInfo);
}
frm_TaskInfo.Show();
if (frm_TaskInfo.WindowState == WindowState.Minimized)
frm_TaskInfo.WindowState = WindowState.Normal;
frm_TaskInfo.Activate();
|
liufu
authored
|
2035
2036
2037
2038
|
}
private void Menu_device_info_Click(object sender, RoutedEventArgs e)
{
|
liufu
authored
|
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
|
Frm_DeviceInfo frm_DeviceInfo = (Frm_DeviceInfo)windows.FirstOrDefault(t => t.Key == "frm_DeviceInfo").Value;
if (frm_DeviceInfo == null)
{
frm_DeviceInfo = new Frm_DeviceInfo();
windows.Add("frm_DeviceInfo", frm_DeviceInfo);
}
frm_DeviceInfo.Show();
if (frm_DeviceInfo.WindowState == WindowState.Minimized)
frm_DeviceInfo.WindowState = WindowState.Normal;
frm_DeviceInfo.Activate();
|
liufu
authored
|
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
|
}
private void Menu_sys_exit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void Window_Closed(object sender, EventArgs e)
{
Application.Current.Shutdown();
}
|
liufu
authored
|
2060
2061
2062
|
private void btn_UpdateTask_Click(object sender, RoutedEventArgs e)
{
|
liufu
authored
|
2063
2064
|
timer.Enabled = !timer.Enabled;
inTimer = 0;
|
liufu
authored
|
2065
|
//dgv_1.ItemsSource = Bill.GetTasks(null, null, null, DateTime.Now.AddDays(-7), null).Data.OrderBy(t => t.Status).ThenBy(t => t.Created).Take(100);
|
liufu
authored
|
2066
2067
2068
|
}
#endregion
|
liufu
authored
|
2069
2070
2071
|
private void btn_GoBack_Click(object sender, RoutedEventArgs e)
{
|
liufu
authored
|
2072
|
if (PLC == null || PLC.GetConnStatus() == false)
|
liufu
authored
|
2073
|
{
|
liufu
authored
|
2074
|
MessageBox.Show("地址读取失败,请检查通讯连接");
|
liufu
authored
|
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
|
}
else
{
var a = DeviceAddressEntities.FindAll(t => t.DeviceId == 11);
var b = ReadAddress(a);
if (b.Success)
{
string pallet = a.Find(t => t.DevicePropCode == "Barcode").value;
var c = Bll.GetTaskUncompleteByPalletCode(pallet);
if (c.Success)
{
var d = c.Data;
if (d.Status != 30)
{
MessageBox.Show($"托盘{pallet}对应的任务{d.Id}状态为{d.Status},状态非30,请检查");
}
else
{
|
liufu
authored
|
2093
|
var df = Bll.SetTaskStatus(d.Id, 31);
|
liufu
authored
|
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
|
if (df.Success)
{
AddLogToUI($"任务{d.Id}回库成功", 1);
}
else
{
MessageBox.Show($"任务{d.Id}回库失败,消息:{df.Msg}");
}
}
}
else
{
MessageBox.Show($"未获取到{pallet}对应的任务");
}
}
else
{
MessageBox.Show("读取地址失败");
}
}
}
|
liufu
authored
|
2115
2116
|
}
}
|