SServerManager.cs
8.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
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class SServerManager
{
//是否测值:
//http://10.85.17.233/ESMTCommonInterface/CommonService.asmx?op=VMICheckRLC
//结果上传:
//http://10.85.17.233/ReturnOne/WebServiceF.asmx?op=Return_Material
// http://10.85.17.233/ESMTCommonInterface/CommonService.asmx/VMICheckRLC?reelID=R014212020051100876&partNum=6C.R0034.1D1
private static string Addr_VMICheckRLC = "/ESMTCommonInterface/CommonService.asmx/VMICheckRLC";
private static string Addr_Return_Material = "/ReturnOne/WebServiceF.asmx/Return_Material";
public static string Get_VMICheckRLC(string deviceName, string codeStr, out int targetP)
{
//reelID:
//partNum:
//{"data":{"IFneed":"不需要","iftest":"","component":"","msg":"不需要测量RLC","status":1}}
targetP = 0;
string msg = "";
try
{
string[] codeArray = codeStr.Split(';');
if (codeArray.Length != 2)
{
return msg = deviceName + "【" + codeStr + "】未找到有效条码";
}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("reelID", codeArray[1]);
paramMap.Add("partNum", codeArray[0]);
string server = GetAddr(Addr_VMICheckRLC, paramMap);
if (server.Equals(""))
{
return "获取是否测值失败";
}
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Get(server);
LogUtil.info(deviceName + "Get_VMICheckRLC " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
//{"data":{"IFneed":"不需要","iftest":"","component":"","msg":"不需要测量RLC","status":1}}
ResultData strData = JsonHelper.DeserializeJsonToObject<ResultData>(resultStr);
if (strData != null && strData.data != null)
{
if (strData.data.status.Equals(0) && strData.data.IFneed.Equals("不需要"))
{
targetP = 1;
return "";
}
else if (strData.data.status.Equals(1) && strData.data.IFneed.Equals("需要"))
{
//需要时,component是电容 或者电阻
if (strData.data.component.Equals("电容"))
{
targetP = 2;
}
else
{
targetP = 3;
}
return "";
}
else
{
msg = strData.data.msg;
return msg;
}
}
else
{
return "获取是否测值失败";
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " ", ex);
return ex.ToString();
}
return msg;
}
public static string Return_Material(string deviceName, string codeStr, int count, out string FactoryCode)
{
// Parameter Value
//txtQty:
// txtReelId:
string msg = "";
FactoryCode = "";
try
{
string[] codeArray = codeStr.Split(';');
if (codeArray.Length != 2)
{
return msg = deviceName + "【" + codeStr + "】未找到有效条码";
}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("txtQty", count.ToString());
paramMap.Add("txtReelId", codeArray[1]);
string server = GetAddr(Addr_Return_Material, paramMap);
if (server.Equals(""))
{
return "";
}
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Get(server).Replace("\r\n", " ");
//【<?xml version="1.0" encoding="utf-8"?>< string xmlns = "http://tempuri.org/" > NG 不可退料 厂别:ST </ string >】
LogUtil.info(deviceName + "Return_Material " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
//resultStr = "<?xml version=\"1.0\" encoding=\"utf - 8\"?>< string xmlns = \"http://tempuri.org/\" > NG 不可退料 厂别:ST </ string >";
if (resultStr.Contains("NG"))
{
int index = resultStr.IndexOf("NG");
msg = resultStr.Substring(index, resultStr.Length - index).Replace("</ string >", "");
}
var m = Regex.Match(resultStr, "厂别[::\\s]*(.*?)<");
if (m.Success)
{
FactoryCode = m.Groups[1].Value.Trim();
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " ", ex);
}
return msg;
}
private static string GetAddr(string addr, Dictionary<string, string> paramsMap)
{
string server = ConfigAppSettings.GetValue(Setting_Init.ServerAddr).Trim();
if (server.Equals(""))
{
return "";
}
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;
}
private static string server = ConfigAppSettings.GetValue(Setting_Init.ServerAddr).Trim();
public static bool CanConnect()
{
return !String.IsNullOrEmpty(server);
}
public static bool GetReekinfo(string codeStr, out ReelResult reelResult) {
string[] codeArray = codeStr.Split(';');
if (codeArray.Length != 2)
{
reelResult = null;
return false;
}
string resultStr = HttpHelper.Get("http://10.85.199.25/myproject/rest/api/qisda/device/resolveCode?code=" + codeArray[1], Encoding.UTF8,1000);
ServerResult serverResult = JsonHelper.DeserializeJsonToObject<ServerResult>(resultStr);
if (serverResult.code == 0) {
reelResult = serverResult.data;
return true;
} else {
reelResult = null;
return false;
}
}
}
// http://10.85.17.233/ESMTCommonInterface/CommonService.asmx/VMICheckRLC?reelID=R014212020051100876&partNum=6C.R0034.1D1
// {"data":{"IFneed":"需要","iftest":"未测值","component":"","msg":"未获取到测量RLC时间","status":1}}
public class ResultData
{
public CheckData data { get; set; }
}
public class CheckData
{
//{"data":{"IFneed":"不需要","iftest":"","component":"","msg":"不需要测量RLC","status":1}}
public string IFneed { get; set; }
public string iftest { get; set; }
public string component { get; set; }
public string msg { get; set; }
public int status { get; set; }
}
public class ServerResult {
public int code;
public string msg;
public ReelResult data;
}
public class ReelResult
{
public int qty;
public int w;
public int h;
public string pn;
}
}