AGVManager.cs
4.3 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AGVControl;
using System.Web.Script.Serialization;
namespace BLL
{
public class AGVManager
{
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; }
}
}