StationExcute.cs
9.53 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
using HHECS.Bll;
using HHECS.Model;
using HHECS.Model.BllModel;
using HHECS.Model.Entities;
using HHECS.Model.Enums;
using HHECS.OPC;
using S7.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HHECS.EquipmentExcute
{
public abstract class StationExcute
{
/// <summary>
/// 用于标记站台的类型
/// </summary>
public EquipmentType EquipmentType { get; set; }
/// <summary>
/// 具体的站台实现逻辑
/// </summary>
/// <param name="stations"></param>
/// <param name="plcs"></param>
/// <returns></returns>
public abstract BllResult Excute(List<Equipment> stations, OPCHelp plc);
/// <summary>
/// 实现地址回复
/// </summary>
/// <param name="station"></param>
/// <param name="plc"></param>
/// <param name="message"></param>
/// <param name="loadStatus"></param>
/// <param name="number"></param>
/// <param name="barcode"></param>
/// <param name="weight"></param>
/// <param name="lenght"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="address"></param>
/// <param name="backup"></param>
/// <returns></returns>
public BllResult SendAddressReplyToPlc(Equipment station, OPCHelp plc, string message, string loadStatus, string number, string barcode, string weight, string lenght, string width, string height, string address, string backup)
{
var prop1 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyMessage");
prop1.Value = message;
var prop2 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyLoadStatus");
prop2.Value = loadStatus;
var prop3 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyNumber");
prop3.Value = number;
var prop4 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyBarcode");
prop4.Value = barcode;
var prop5 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyWeight");
prop5.Value = weight;
var prop6 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyLength");
prop6.Value = lenght;
var prop7 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyWidth");
prop7.Value = width;
var prop8 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyHeight");
prop8.Value = height;
var prop9 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyAddress");
prop9.Value = address;
//var prop10 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSReplyBackUp");
//prop10.Value = backup;
List<EquipmentProp> props = new List<EquipmentProp> { prop2, prop3, prop4, prop5, prop6, prop7, prop8, prop9, prop1 };
//return S7Helper.PlcSplitWrite(plc, props, 20);
return plc.WriteAddress(props);
}
/// <summary>
/// 实现ACK回复,包括地址到达和控制指令
/// </summary>
/// <param name="station"></param>
/// <param name="plc"></param>
/// <param name="message"></param>
/// <param name="loadStatus"></param>
/// <param name="number"></param>
/// <param name="backup"></param>
/// <returns></returns>
public BllResult SendAckToPlc(Equipment station, OPCHelp plc, string message, string loadStatus, string number, string backup)
{
var prop1 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKMessage");
prop1.Value = message;
var prop2 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKLoadStatus");
prop2.Value = loadStatus;
var prop3 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKNumber");
prop3.Value = number;
//var prop4 = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSACKBackup");
//prop4.Value = backup;
List<EquipmentProp> props = new List<EquipmentProp>() { prop2, prop3, prop1 };
//return S7Helper.PlcSplitWrite(plc, props, 20);
return plc.WriteAddress(props);
}
/// <summary>
/// 地址请求时,回退
/// </summary>
/// <param name="station"></param>
/// <param name="plc"></param>
/// <param name="barcode"></param>
public void SendBack(Equipment station, OPCHelp plc, string barcode)
{
string number = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestNumber").Value;
string weight = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestWeight").Value;
string lenght = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestLength").Value;
string width = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestWidth").Value;
string height = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestHeight").Value;
var result = SendAddressReplyToPlc(station, plc, "6", "0", number, barcode, weight, lenght, width, height, station.BackAddress, "");
if (!result.Success)
{
Logger.Log($"{station.Name}回退失败", LogLevel.Error);
}
else
{
Logger.Log($"{station.Name}回退成功", LogLevel.Success);
}
}
#region 旧版本的站台处理方法
/// <summary>
/// 写入WCS站台区地址
/// </summary>
/// <param name="station"></param>
/// <param name="plc"></param>
/// <param name="flag"></param>
/// <param name="type"></param>
/// <param name="plcno"></param>
/// <param name="loadstatus"></param>
/// <param name="stationno"></param>
/// <param name="taskno"></param>
/// <param name="barcode"></param>
/// <param name="toaddress"></param>
/// <param name="backup"></param>
/// <returns></returns>
public BllResult WriteWCSStationDataAddress(Equipment station, OPCHelp plc, string flag, string type, string plcno, string loadstatus, string stationno, string taskno, string barcode, string toaddress, string backup)
{
List<EquipmentProp> props = new List<EquipmentProp>();
var wcsflag = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSFlag");
wcsflag.Value = flag;
var wcstype = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSType");
wcstype.Value = type;
var wcsplcno = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSPLCNo");
wcsplcno.Value = plcno;
var wcsloadstatus = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "LoadStatus");
wcsloadstatus.Value = loadstatus;
var wcsstationno = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSStationNo");
wcsstationno.Value = stationno;
var wcstaskno = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSTaskNo");
wcstaskno.Value = taskno;
var wcsbarcode = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSBarcode");
wcsbarcode.Value = barcode;
var wcstoaddress = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSToAddress");
wcstoaddress.Value = toaddress;
var wcsbackup = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "WCSBackUp");
wcsbackup.Value = backup;
props.Add(wcsflag);
props.Add(wcstype);
props.Add(wcsplcno);
props.Add(wcsloadstatus);
props.Add(wcsstationno);
props.Add(wcstaskno);
props.Add(wcsbarcode);
props.Add(wcstoaddress);
props.Add(wcsbackup);
return plc.WriteAddress(props);
}
/// <summary>
/// 入库口回退
/// </summary>
/// <param name="deviceAddresses"></param>
/// <returns></returns>
public void StationBack(Equipment station, OPCHelp plc)
{
var plcNo = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "PLCNo").Value;
var stationNo = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "StationNo").Value;
var taskNo = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "TaskNo").Value;
var barcode = station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "Barcode").Value;
var result = WriteWCSStationDataAddress(station, plc, "1", "6", plcNo, "0", stationNo, taskNo, barcode, station.BackAddress, "0");
if (result.Success)
{
Logger.Log($"{station.Name}回退成功", LogLevel.Success);
}
else
{
Logger.Log($"{station.Name}回退失败", LogLevel.Error);
}
}
#endregion
}
}