StationExcute.cs
5.75 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
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 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)
{
var result = SendAddressReplyToPlc(station, plc, "6", "0", station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestNumber").Value, barcode,
station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestWeight").Value,
station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestLength").Value,
station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestWidth").Value,
station.EquipmentProps.Find(t => t.EquipmentTypePropTemplateCode == "RequestHeight").Value,
station.BackAddress, station.BackAddress);//电气的请进地址和后退地址其实都是一个地址
if (!result.Success)
{
Logger.Log($"{station.Name}回退失败", LogLevel.Error);
}
else
{
Logger.Log($"{station.Name}回退成功", LogLevel.Success);
}
}
}
}