TheLine.cs
13.2 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
using ConfigHelper;
using Newtonsoft.Json;
using OnlineStore;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace RemoteSheardObject
{
public class TheLine
{
public enum LineStatusE {
INLINE,
INROBOT,
BOXDOOR,
FINISHED,
BOXDOOR_NOREEL
}
public static bool UpdateLocInfo(string taskId, string barcode, LineStatusE status, string locInfo)
{
if (barcode.Count(c => c == '#') == 3)
{
barcode = barcode.Split('#')[1].Substring(1);
}
var postData = new Dictionary<string, string>()
{
{"taskId", taskId},
{"barcode", barcode},
{"status", status.ToString()},
{"locInfo", locInfo}
};
return !string.IsNullOrEmpty(SubmitPostData("/service/store/robotBox/updateLocInfo", postData));
}
public static bool emptyOut(string barcode)
{
//料盘空出后直接结束任务
return true;
if (barcode.Count(c => c == '#') == 3)
{
barcode = barcode.Split('#')[1].Substring(1);
}
var postData = new Dictionary<string, string>()
{
{"barcode", barcode}
};
return !string.IsNullOrEmpty(SubmitPostData("/service/store/robotBox/emptyOut", postData));
}
/// <summary>
/// 获取正在进行的任务数量
/// </summary>
/// <returns></returns>
public static Dictionary<string,int> GetTaskCount()
{
//pizzaBox,pcb,tray,reel
var postData = new Dictionary<string, string>()
{
};
Dictionary<string, int> taskdata = new Dictionary<string, int>();
taskdata["pizzaBox"] = 0;
taskdata["pcb"] = 0;
taskdata["tray"] = 0;
taskdata["reel"] = 0;
var result= JsonConvert.DeserializeObject<ResultData>(SubmitPostData("/rest/micron/device/getTaskCount", postData));
if (result==null || result.code != 0)
return taskdata;
foreach (var k in taskdata.Keys.ToArray())
{
if (result.data.ContainsKey(k+"_out"))
taskdata[k] = int.Parse(result.data[k + "_out"].ToString());
}
return taskdata;
}
public static string CombineUrl(string baseUrl, string relativeUrl)
{
if (string.IsNullOrEmpty(baseUrl))
{
return relativeUrl;
}
if (string.IsNullOrEmpty(relativeUrl))
{
return baseUrl;
}
baseUrl = baseUrl.TrimEnd('/');
relativeUrl = relativeUrl.TrimStart('/');
return string.Format("{0}/{1}", baseUrl, relativeUrl);
}
public static T GetReelSize<T>(string barcode)
{
if (barcode.Count(c => c == '#') == 3)
{
barcode = barcode.Split('#')[1].Substring(1);
}
var postData = new Dictionary<string, string>()
{
{"barcode", barcode},
};
var result = SubmitPostData( "/service/store/robotBox/getSize", postData);
if (result != null)
return JsonConvert.DeserializeObject<T>(result);
else
return default;
}
public static void UploadStatus(EquipMsgData equipMsgData)
{
string url = CombineUrl(Config.Get("Device_Server_Address"), "/rest/micron/device/updateStatus");
var resultStr = HttpHelper.Post<EquipMsgData, ResultData2>(url, equipMsgData);
}
public static void uploadNgReel(NgMsgData ngMsgData)
{
string url = CombineUrl(Config.Get("Device_Server_Address"), "/rest/micron/device/uploadNgReel");
var resultStr = HttpHelper.Post<NgMsgData, ResultData2>(url, ngMsgData,5000,true);
}
/// <summary>
/// 上传mycronic库存信息
/// </summary>
/// <param name="equipMsgData"></param>
public static void UploadCarrierInformation(List<CarrierInformationData> equipMsgData)
{
string url = CombineUrl(Config.Get("Device_Server_Address"), "/rest/micron/device/updateMInventory");
var resultStr = HttpHelper.Post<List<CarrierInformationData>, ResultData2>(url, equipMsgData);
}
/// <summary>
/// NG口位置,1=左侧,2=右侧
/// </summary>
/// <param name="ngPos"></param>
public static void ClearNgPos(int ngPos)
{
var postData = new Dictionary<string, string>()
{
{"ngPos",ngPos.ToString() }
};
string url = "/rest/micron/device/clearNgPos";
var resultStr = SubmitPostData(url, postData);
}
/// <summary>
/// 上传自定义数据
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public static void UploadCustData(string key,string value)
{
var postData = new Dictionary<string, string>()
{
{"key",key },
{"value",value }
};
string url = "/rest/micron/device/updateData";
var resultStr = SubmitPostData(url, postData);
}
/// <summary>
/// 上传自定义数据
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public static string GetCustData(string key)
{
var postData = new Dictionary<string, string>()
{
{"key",key}
};
string url = "/rest/micron/device/getData";
var resultStr = SubmitPostData(url, postData);
var r= JsonConvert.DeserializeObject<ResultData2>(resultStr);
if (!string.IsNullOrWhiteSpace(r.data)) {
return r.data;
}
return null;
}
public class ResultData2
{
//{"code":0,"msg":"ok","data":"7"}
public int code { get; set; }
public string msg { get; set; }
public string data { get; set; }
}
public class ResultData
{
//{"code":0,"msg":"ok","data":"7"}
public int code { get; set; }
public string msg { get; set; }
public Dictionary<string, object> data { get; set; }
}
public static string SubmitPostData(string url, Dictionary<string, string> postData)
{
url = CombineUrl(Config.Get("Device_Server_Address"), url);
//创建WebClient对象
using (var client = new WebClient())
{
//设置提交数据的方式为"application/x-www-form-urlencoded"
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
try
{
//将POST请求参数字典转换为参数字符串
var postDataString = new StringBuilder();
foreach (var item in postData)
{
if (!string.IsNullOrEmpty(item.Value))
{
postDataString.AppendFormat("{0}={1}&", item.Key, Uri.EscapeDataString(item.Value));
}
}
//去掉最后一个"&"符号
if (postDataString.Length>0)
postDataString.Length--;
//将POST请求参数转换为字节数组
byte[] bytes = Encoding.UTF8.GetBytes(postDataString.ToString());
//提交POST请求并获取响应
byte[] response = client.UploadData(url, "POST", bytes);
//将响应转换为字符串并输出
return Encoding.UTF8.GetString(response);
}
catch (Exception ex)
{
// 捕获任何网络异常,并输出错误信息
//Console.WriteLine(crc.GetString("Res0071","提交POST请求时发生错误:") + ex.Message);
// 请求失败,返回false
return "";
}
}
}
/// <summary>
/// 料仓离线后二次重新获取物料库位
/// </summary>
/// <param name="reelParam"></param>
/// <param name="traytype"></param>
/// <param name="msg"></param>
/// <returns></returns>
public static ReelParam Regetposid(ReelParam reelParam,string traytype, out string msg)
{
msg = "";
var barcode = reelParam.WareCode;
if (barcode.Count(c => c == '#') == 3)
{
barcode = barcode.Split('#')[1].Substring(1);
}
try
{
Dictionary<string, string> nameValue = new Dictionary<string, string>();
nameValue.Add("code", barcode);
nameValue.Add("preCid", reelParam.cid);
if (reelParam.PlateW == 13 && reelParam.PlateH < 44)
nameValue.Add("cids", "AMH-SBDH3-2,AMH-SBSH1,AMH-SBSH2,AMH-SBDH2-1,AMH-SBDH2-2,AMH-SBDH1-1,AMH-SBDH1-2,003040,003048,003039,003043,003035,003036,003041,003042");
else //不包含 AMH-SBDH3-1
nameValue.Add("cids", "AMH-SBDH3-1,AMH-SBDH3-2,AMH-SBSH1,AMH-SBSH2,AMH-SBDH2-1,AMH-SBDH2-2,AMH-SBDH1-1,AMH-SBDH1-2,003040,003048,003039,003043,003035,003036,003041,003042");
var data = SubmitPostData("/service/store/robotBox/renewPosForPutin", nameValue);
msg += "Regetposid code: " + reelParam.WareCode + ",preCid: " + reelParam.cid + ",cids:" + nameValue["cids"] + ",Result: " + data + "\r\n";
emptyPosForPutin result = JsonConvert.DeserializeObject<emptyPosForPutin>(data);
if (result != null && (result.result == "0" || result.result == "98"))
{
if (string.IsNullOrEmpty(result.cid))
{
msg += "no cid\r\n";
reelParam.cid = traytype == "MTP1" ? "AMH-ML5-2" : "AMH-ML5-1";
reelParam.IsNg = true;
reelParam.NgMsg = result.msg;
return reelParam;
}
var mid = "";
if ("003040,003048,003039,003043".IndexOf(result.cid) >= 0)
{
mid = "AMH-MI1";
}
else if ("003035,003036,003041,003042".IndexOf(result.cid) >= 0)
{
mid = "AMH-MI2";
}
//if (reel.PlateW == 7 || reel.PlateW == 13 && reel.PlateH < 44 || reel.PlateW == 15)
if (mid == "AMH-MI1" || mid == "AMH-MI2")
{
var micode = $"P{reelParam.PN}#S{reelParam.RI}#{reelParam.QTY}#{reelParam.DC}";
msg += $"送往MI物料重组2dcode:" + micode;
reelParam.SubCID = result.cid;
reelParam.WareCode = micode;
reelParam.PosID = result.cid;
reelParam.cid = mid;
//RobotManage.SendTrayRequest("003039", micode, "AMH-MI1");
//RobotManage.SendTrayRequest(result.cid, micode, mid);
}
else
{
reelParam.cid = result.cid;
reelParam.PosID = result.pos;
}
return reelParam;
//RobotManage.SendTrayRequest(result.pos, result.barcode, result.cid);
}
else
{
if (result != null && result.msg != null)
msg = result.msg;
reelParam.cid = traytype == "MTP1" ? "AMH-ML5-2" : "AMH-ML5-1"; ;
reelParam.IsNg = true;
reelParam.NgMsg = msg;
return reelParam;
}
}
catch (Exception ex) {
msg += ex.ToString();
reelParam.cid = traytype == "MTP1" ? "AMH-ML5-2" : "AMH-ML5-1"; ;
reelParam.IsNg = true;
reelParam.NgMsg = msg;
return reelParam;
}
}
public class emptyPosForPutin
{
public string result;
public string msg;
public string pos;
public string barcode;
public string cid;
}
[Serializable]
public class CarrierInformationData
{
public string carrier;
public string partnumber;
public string depot;
public int diameter;
public int height;
}
}
}