AGVManager.cs
6.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
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
using BLL.BLL;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace BLL
{
public class AGVManager
{
//public static string Add_emptyMsg = "http://10.85.199.1/BenQMIR/Webservice/AGVService.asmx/CreateEmptyRecycleTask";//"http://localhost:11111/BenQMIR/Webservice/AGVService.asmx/CreateEmptyRecycleTask";//
public static string CreateEmptyTask(string Add_emptyMsg, string line)
{
try
{
//Dictionary<string, string> paramMap = new Dictionary<string, string>();
//paramMap.Add("emptyStation", "D1");
string path = Add_emptyMsg;
//foreach (string paramName in paramMap.Keys)
//{
// string par = System.Web.HttpUtility.UrlEncode(paramMap[paramName], System.Text.Encoding.UTF8);
// path += paramName + "=" + par + "&";
//}
//path = path.Substring(0, path.Length - 1);
string resultStr = HttpUtil.Post(path, "emptyStation=" + line);//HttpHelper.Post(path, "");
//Common.log.Debug("【" + path + "】【" + resultStr + "】");
//Result data = JsonHelper.DeserializeJsonToObject<Result>(resultStr);
return resultStr;
//if (data == null)
//{
// return " updateDeviceAlarmMsg 没有收到服务器反馈";
//}
//else
//{
// return data.Succeed;
//}
}
catch (Exception e)
{
return e.ToString();
}
}
public static Result GetWebservice(string Add_emptyMsg,string id)
{
Result rb = new Result();
try
{
//http://10.85.36.156/BenQMIR/Webservice/AGVService.asmx
string strURL = Add_emptyMsg + "?emptyStation=" + id;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
//request.Method="get";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
XmlTextReader Reader = new XmlTextReader(s);
Reader.MoveToContent();
string strValue = Reader.ReadInnerXml();
strValue = strValue.Replace("<", "<");
strValue = strValue.Replace(">", ">");
//{"Succeed":false,"ResultData":null,"ErrorMessage":"无法通过[Feederaaaa]lineCode找到小车停靠点"}
rb = JsonConvert.DeserializeObject<Result>(strValue);
Reader.Close();
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
return rb;
}
/// <summary>
/// 获取大料架解绑情况
/// </summary>
/// <param name="rfid"></param>
/// <param name="lineName"></param>
/// <returns></returns>
public static bool GetRackBy(string rfid, out string lineName)
{
lineName = "";
//GET /ESMTCommonInterface/CommonService.asmx/GetRackBy?id=string HTTP/1.1
//Host: 10.85.17.233
string addr = "http://10.85.17.233/ESMTCommonInterface/CommonService.asmx/GetRackBy?id=" + rfid;
//[{"msg":"1OKD1"}]
//[{"msg":"0NGFeeder"}]
try
{
string result = HttpUtil.Get(addr);
if (!result.Equals(""))
{
List<Msg> msgs = JsonHelper.DeserializeJsonToList<Msg>(result);
if (msgs == null || msgs.Count == 0)
return false;
int.TryParse(msgs[0].msg.Substring(0, 1), out int resCode);
string resStr = msgs[0].msg.Substring(1, 2);
lineName = msgs[0].msg.Substring(3);
//Common.log.Debug(string.Format("resCode={0},resStr={1},lineName={2}", resCode, resStr, lineName));
if (lineName.Equals("").Equals(true))
return false;
return true;
}
}
catch { return false; }
return false;
}
/// <summary>
/// 物料状态上报
/// </summary>
/// <param name="rfid"></param>
/// <param name="lineName"></param>
/// <returns></returns>
public static bool UpdateStatus(string rfid, string lineName)
{
//GET /ESMTCommonInterface/CommonService.asmx/UpdateStatusBy?id=string&location=string HTTP/1.1
//Host: 10.85.17.233
string addr = "http://10.85.17.233/ESMTCommonInterface/CommonService.asmx/UpdateStatusBy?id=" + rfid + "&location=" + lineName;
//[{"msg":"1更新成功"}]
try
{
string result = HttpUtil.Get(addr);
if (!result.Equals(""))
{
List<Msg> msgs = JsonHelper.DeserializeJsonToList<Msg>(result);
if (msgs == null || msgs.Count == 0)
return false;
bool resRtn = int.TryParse(msgs[0].msg.Substring(0, 1), out int resCode);
if (resRtn)
{
if (resCode.Equals(1))
{
System.Windows.Forms.MessageBox.Show(string.Format("{0}物料状态更新成功[{1}]", lineName, rfid));
return true;
}
else
return false;
}
return false;
}
}
catch { return false; }
return false;
}
private class Msg
{
public string msg { get; set; }
}
}
public class Result
{
public string Succeed { get; set; }
public string ResultData { get; set; }
public string ErrorMessage { get; set; }
}
}