AGVManager.cs
7.4 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
200
201
202
203
204
205
206
207
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AGVControl;
namespace BLL
{
public class AGVManager
{
/// <summary>
/// 小车从B区域离开前检查出库任务是否完成
/// </summary>
/// <param name="rfid"></param>
/// <returns>true:可以离开</returns>
public static bool LeaveCheck(Agv_Info agv, out int taskCount)
{
taskCount = 0;
try
{
//Common.log.OutInfo("URL:" + Common.webService["URL"]);
string url = ConfigAppSettings.GetValue(Setting_Init.http_server) + "rest/api/qisda/device/shelfTaskCount? rfid =" + agv.RFID;
var client = new RestSharp.RestClient(url) { Timeout = -1 };
var request = new RestSharp.RestRequest(RestSharp.Method.GET);
RestSharp.IRestResponse response = client.Execute(request);
string json = response.Content;
Common.log.OutInfo(agv.Name + " [URL: " + url+"] [Return: " + json+"]");
if (string.IsNullOrWhiteSpace(json)) return true; //可以离开
ShelfTaskCount serverResult = JsonHelper.DeserializeJsonToObject<ShelfTaskCount>(json);
if (serverResult == null)
{
Common.log.OutInfo(" 没有收到服务器反馈");
return true;
}
if (serverResult.code != 0) return true;
if (serverResult.shelfTaskData.taskCount == 0) //该料架出库完成
{
Common.log.OutInfo(agv.Name+" 料架【" + agv.RFID + "】 无剩余出库任务,serverResult.shelfTaskData.taskCount=" + serverResult.shelfTaskData.taskCount.ToString());
return true;
}
else //该料架的出库任务未完成
{
// foreach (ShelfLockData item in serverResult.data)
// {
taskCount = serverResult.shelfTaskData.taskCount;
Common.log.OutInfo(agv.Name + " [RFID=" + serverResult.shelfTaskData.rfid + "] [taskCount=" + serverResult.shelfTaskData.taskCount + "]");
// }
return false;
}
}
catch (Exception ex)
{
Common.log.OutError(ex);
return true;
}
}
private static string Addr_getShelfLockInfo = "/rest/api/qisda/device/getShelfLockInfo"; //包装仓获取料架锁定状态地址
public static bool GetShelfLockInfo(string rfid, out List<string> shelfLockNodeNames)
{
string msg = "";
shelfLockNodeNames = null;
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("rfid", rfid);
string server = GetAddr(Addr_getShelfLockInfo, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
Common.log.OutInfo("料架锁定状态 " + " 【" + server + "】【" + resultStr + "】");
ShelfLockInfo serverResult = JsonHelper.DeserializeJsonToObject<ShelfLockInfo>(resultStr);
if (serverResult == null)
{
msg = " 没有收到服务器反馈";
Common.log.OutInfo(msg);
return false;
}
if (serverResult.data.Count == 0) //该料架未锁定
{
msg = " 料架【" + rfid + "】 没有锁定库位的料";
Common.log.OutInfo(msg);
return false;
}
else //该料架存在锁定库位的料
{
shelfLockNodeNames = new List<string>();
foreach (ShelfLockData item in serverResult.data)
{
if (!shelfLockNodeNames.Contains(Common.webService[item.cid]))
{
shelfLockNodeNames.Add(Common.webService[item.cid]);
Common.log.OutInfo("锁定的CID=" + item.cid + ";节点名称=" + Common.webService[item.cid]);
}
}
Common.log.OutInfo("获取料架上的料仓信息完成");
return true;
}
}
catch (Exception ex)
{
Common.log.OutInfo(ex.Message);
}
return false;
}
private static string GetAddr(string addr, Dictionary<string, string> paramsMap)
{
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
if (server.EndsWith("/"))
{
server = server.Substring(0, server.Length - 1);
}
string path = server + addr.Trim() + "?";
foreach (string paramName in paramsMap.Keys)
{
string par = System.Web.HttpUtility.UrlEncode(paramsMap[paramName], System.Text.Encoding.UTF8);
path += paramName + "=" + par + "&";
}
path = path.Substring(0, path.Length - 1);
return path;
}
}
public class ShelfLockInfo
{
//返回: {"code":0,"msg":"ok","data":
//[{"barcode":"S20052301213","cid":"packing-20","rfid":"A12","rfidLoc":"3","lockPos":"4D2001AA0006","lockPosId":"1231"}]}
/// <summary>
/// 返回码,0为正常,其他为异常
/// </summary>
public int code { get; set; }
/// <summary>
/// 消息
/// </summary>
public string msg { get; set; }
public List<ShelfLockData> data { get; set; }
}
public class ShelfLockData
{
/// <summary>
/// 库位中料盘的条码
/// </summary>
public string barcode { get; set; }
/// <summary>
/// 库位中料盘的锁定库位对应的料仓编
/// </summary>
public string cid { get; set; }
/// <summary>
/// 料架RFID
/// </summary>
public string rfid { get; set; }
/// <summary>
/// 料架的库位
/// </summary>
public int rfidLoc { get; set; }
/// <summary>
/// 库位中料盘的锁定库位
/// </summary>
public string lockPos { get; set; }
/// <summary>
/// 料架出库的剩余数量
/// </summary>
public int taskCount { get; set; }
}
/// <summary>
/// 获取料架中的任务数
/// </summary>
public class ShelfTaskCount
{
// {"code":0,"msg":"ok","data":{"taskCount":0,"rfid":"A2"}}
/// <summary>
/// 0为正常,其他为异常
/// </summary>
public int code { get; set; }
/// <summary>
/// 消息
/// </summary>
public string msg { get; set; }
public ShelfTaskData shelfTaskData { get; set; }
}
public struct ShelfTaskData
{
/// <summary>
/// 当前料架剩余任务数(即还有几盘料没放上去)
/// </summary>
public int taskCount { get; set; }
/// <summary>
/// 料架RFID
/// </summary>
public string rfid { get; set; }
}
}