StationForStockerInExcute.cs
6.79 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HHECS.Bll;
using HHECS.Model;
using HHECS.Model.BllModel;
using HHECS.Model.Common;
using HHECS.Model.Entities;
using HHECS.Model.Enums;
using HHECS.OPC;
using S7.Net;
namespace HHECS.EquipmentExcute
{
/// <summary>
/// 标准堆垛机接入站台处理
/// 这里只处理位置到达
/// </summary>
public class StationForStockerInExcute : StationExcute
{
public override BllResult Excute(List<Equipment> equipments, OPCHelp plc)
{
List<Equipment> stations = equipments.Where(a => a.EquipmentType.Id == EquipmentType.Id).ToList();
foreach (var station in stations)
{
InnerExcute(station, plc);
}
return BllResultFactory.Sucess();
}
private void InnerExcute(Equipment station, OPCHelp plc)
{
//这里先直接回应一个响应
//如果PLC标记为3,则表示解析有误,这里报警
if (station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Flag").Value == "3")
{
Logger.Log("PLC解析站台" + station.Name + "数据失败,请检查基础数据!", LogLevel.Error);
return;
}
//PLC 有新消息标记 && WCS回复有新消息标记:此时WCS已经回复了消息,等待PLC响应,不做处理,如果PLC新标记为3,表示解析错误
if (station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Flag").Value == "1" &&
station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "WCSFlag").Value == "1")
{
return;
}
//PLC没有新消息标记 && WCS有新消息标记:此时PLC已经确认消息,清除WCS回复消息
if (station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Flag").Value != "1" &&
station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "WCSFlag").Value == "1")
{
var result = WriteWCSStationDataAddress(station, plc, "0", "0", "0", "0", "0", "0", "", "0", "0");
if (result.Success)
{
Logger.Log("清空" + station.Name + "WCS区地址成功", LogLevel.Success);
}
else
{
Logger.Log("清空" + station.Name + "WCS区地址失败:" + result.Msg, LogLevel.Error);
}
return;
}
//PLC有新消息标记 && WCS没有新消息标记:此时PLC发送了消息而WCS没有响应,写响应逻辑发送地址数据给PLC
if (station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Flag").Value == "1"
&& station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "WCSFlag").Value != "1"
//这里做一次校验防止与PLC扫描冲突
&& station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Type").Value != "0"
&& station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "PLCNo").Value != "0"
&& station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "StationNo").Value != "0"
&& !String.IsNullOrWhiteSpace(station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Barcode").Value))
{
//判断报文类型
if (station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Type").Value == "1")
{
//地址请求
Logger.Log("堆垛机接入站台" + station.Name + "暂时没有实现地址请求", LogLevel.Error);
return;
}
if (station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Type").Value == "2")
{
//响应一个位置到达请求
//更新任务状态为35
String palletCode = station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Barcode").Value;
var bllResult = AppSession.Bll.GetTaskUncompleteByPalletCode(palletCode);
if (!bllResult.Success)
{
Logger.Log("站台" + station.Name + "对应托盘" + palletCode + "没有查找到任务数据", LogLevel.Error);
return;
}
var task = bllResult.Data;
//if (task.LastStatus > 31)
//{
// Logger.Log("站台" + station.Name + "对应托盘" + palletCode + "没有查找到任务" + task.Id + "状态已经超过30,应已响应,请检查", LogLevel.Error);
// return;
//}
var plcNo = station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "PLCNo").Value;
var stationNo = station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "StationNo").Value;
var taskNo = station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "TaskNo").Value;
var barcode = station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Barcode").Value;
//给他回一个位置到达
var temp = WriteWCSStationDataAddress(station, plc, "1", "8", plcNo, "0", stationNo, taskNo, barcode, "0", "0");
if (temp.Success)
{
//位置到达回复成功后,更新任务状态
AppSession.Bll.SetTaskStatus(task.Id, TaskEntityStatus.响应接入口位置到达.GetIndexInt());
Logger.Log("位置到达:任务" + task.Id + "位置到达写入" + station.Name + "WCS区地址成功", LogLevel.Success);
}
else
{
Logger.Log("位置到达:写入" + station.Name + "WCS区地址失败:" + temp.Msg, LogLevel.Error);
}
return;
}
//判断报文类型
if (station.EquipmentProps.FirstOrDefault(t => t.EquipmentTypePropTemplateCode == "Type").Value == "3")
{
//地址请求
Logger.Log("堆垛机接入站台" + station.Name + "暂时没有控制指令请求", LogLevel.Warning);
return;
}
}
}
}
}