StockerExcute.cs
5.19 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
using HHECS.Bll;
using HHECS.Model;
using HHECS.OPC;
using S7.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HHECS.Common
{
public abstract class StockerExcute
{
/// <summary>
/// 对应的设备类型
/// </summary>
public EquipmentType EquipmentType { get; set; }
/// <summary>
/// 执行堆垛机处理逻辑
/// </summary>
/// <param name="stockers"></param>
/// <param name="plcs"></param>
/// <returns></returns>
public abstract BllResult Excute(List<Equipment> stockers, List<Plc> plcs);
/// <summary>
/// 下发数据到WCS交换区
/// </summary>
/// <param name="stocker"></param>
/// <param name="plc"></param>
/// <param name="forkAction"></param>
/// <param name="forkTaskFlag"></param>
/// <param name="forkRow"></param>
/// <param name="forkColumn"></param>
/// <param name="forkLayer"></param>
/// <param name="forkStation"></param>
/// <param name="taskNo"></param>
/// <returns></returns>
public BllResult SendTaskToStocker(Equipment stocker, Plc plc, ForkAction forkAction, ForkTaskFlag forkTaskFlag, string forkRow, string forkColumn, string forkLayer, string forkStation, string taskNo)
{
try
{
List<EquipmentProp> propsToWriter = new List<EquipmentProp>();
var props = stocker.EquipmentProps;
var action = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSForkAction");
action.Value = forkAction.GetIndexString();
var taskFlag = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1TaskFlag");
taskFlag.Value = forkTaskFlag.GetIndexString();
var row = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1Row");
row.Value = forkRow;
var column = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1Column");
column.Value = forkColumn;
var layer = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1Layer");
layer.Value = forkLayer;
var station = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1Station");
station.Value = forkStation;
var task = props.Find(t => t.EquipmentTypePropTemplateCode == "WCSFork1Task");
task.Value = taskNo;
propsToWriter.AddRange(new List<EquipmentProp>() { action, taskFlag, row, column, layer, station, task });
return S7Helper.PlcSplitWrite(plc, propsToWriter, 20);
}
catch (Exception ex)
{
return BllResultFactory.Error($"下发任务出现异常:{ex.Message}");
}
}
/// <summary>
/// 心跳
/// </summary>
/// <param name="stocker"></param>
/// <param name="plc"></param>
public void Heartbeat(Equipment stocker, Plc plc)
{
var prop = stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSHeartBeat");
prop.Value = "1";
var result = S7Helper.PlcSplitWrite(plc, new List<EquipmentProp>() { prop }, 20);
if (!result.Success)
{
Logger.Log($"发送堆垛机{stocker.Name}心跳数据失败:{result.Msg}", LogLevel.Error);
}
}
/// <summary>
/// 清理WCS交换区
/// </summary>
/// <param name="stocker"></param>
/// <param name="plc"></param>
/// <returns></returns>
public BllResult ClearWCSData(Equipment stocker, Plc plc)
{
//表示堆垛机已经收到WCS发送给他的任务完成信号,此时WCS可以清除自己的交换区地址
BllResult sendResult = SendTaskToStocker(stocker, plc, ForkAction.无, ForkTaskFlag.无任务, "0", "0", "0", "0", "0");
if (sendResult.Success)
{
Logger.Log($"任务完成后,清除堆垛机{stocker.Name}交换区地址成功", LogLevel.Info);
return BllResultFactory.Sucess();
}
else
{
Logger.Log($"任务完成后,清除堆垛机{stocker.Name}交换区地址失败", LogLevel.Error);
return BllResultFactory.Error();
}
}
/// <summary>
/// 通用条件验证
/// </summary>
/// <param name="stocker"></param>
/// <returns></returns>
public BllResult Validate(Equipment stocker)
{
//联机,无故障
if (stocker.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "OperationModel").Value == OperationModel.联机.GetIndexString() && stocker.EquipmentProps.Where(t => t.EquipmentTypePropTemplate.IsMonitor == true).Count(t => t.Value != t.EquipmentTypePropTemplate.MonitorCompareValue) == 0)
{
return BllResultFactory.Sucess();
}
else
{
return BllResultFactory.Error();
}
}
}
}