ScanRequestLabel.cs
11.6 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
using ExcelDataReader;
using HalconDotNet;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using TSA_V.Common;
using TSA_V.LoadCSVLibrary;
namespace TSA_V.DeviceLibrary.manager
{
public class ScanRequestLabel
{
//static Dictionary<string,string> pairs = new Dictionary<string,string>();
/// <summary>
/// 开灯、记录地址信息
/// </summary>
/// <param name="position"></param>
/// <param name="count"></param>
/// <param name="name"></param>
/// <param name="ComponentDes"></param>
/// <param name="dic"></param>
public static void RequestPost(TSAVPosition position,string count,string name,string ComponentDes,out Dictionary<string, string> dic)
{
Dictionary<string, string> pairs = new Dictionary<string, string>();
try
{
#region
////不为空时,关闭上一个指示灯
//if (pairs.Count>=3)
//{
// DataModel data = new DataModel()
// {
// ip = pairs["Ip"],
// mac = pairs["Mac"],
// PNum = pairs["PNum"],
// count=count,
// name= pairs["Name"],
// ComponentDes = pairs["ComponentDes"]
// };
// //关灯操作
// LogUtil.info($"电子屏关灯:{data.ip},{data.mac},{false},上一个电子屏信息:{data.mac}");
// lightTagsLed(data.ip, data.mac, false);
// UpdateQty(data);
// pairs.Clear();
//}
#endregion
if (!string.IsNullOrWhiteSpace(position.DeviceIP))
{
//开灯
LogUtil.info($"电子屏开灯:{position.DeviceIP},{position.Leds},{true}");
lightTagsLed(position.DeviceIP, position.Leds, true);
pairs.Add("Ip", position.DeviceIP);
pairs.Add("Mac", position.Leds);
pairs.Add("PNum", position.PositionNum);//库位编号
pairs.Add("Count",count);
pairs.Add("ComponentDes", ComponentDes);
pairs.Add("Name", name);
LogUtil.info($"{ComponentDes};{name};");
}
else
{
pairs.Clear();
}
}
catch (Exception)
{
}
dic = pairs;
}
/// <summary>
/// 关灯
/// </summary>
/// <param name="pairs"></param>
public static void Turnoffthelights(Dictionary<string,string> pairs)
{
DataModel data = new DataModel()
{
ip = pairs["Ip"],
mac = pairs["Mac"],
PNum = pairs["PNum"],
count = pairs["Count"],
name = pairs["Name"],
ComponentDes = pairs["ComponentDes"]
};
//关灯操作
LogUtil.info($"电子屏关灯:{data.ip},{data.mac},{false},上一个电子屏信息:{data.mac}");
lightTagsLed(data.ip, data.mac, false);
UpdateQty(data);
pairs.Clear();
}
/// <summary>
/// 请求标签,关灯、开灯
/// </summary>
/// <param name="ip"></param>
/// <param name="mac">标签地址</param>
/// <param name="isled">true=亮灯</param>
public static void lightTagsLed(string ip,string mac,bool isled)
{
string ledrgb=isled?"ff00":"0";
var client = new HttpClient();
var requests = new HttpRequestMessage(HttpMethod.Post, $"http://{ip}/wms/associate/lightTagsLed");
Dictionary<string, object> keyValuePairss = new Dictionary<string, object>{
{ "mac", mac },//标签地址
{ "lednum", 255 },
{ "timeout", 0 },
{ "ledrgb", ledrgb },
{ "ledmode", 0 },
{ "reserve", "reserve" },
{ "cmdtoken", "Inve123ntec" }};
string json= JsonHelper.SerializeObject(keyValuePairss);
var contents = new StringContent($"[{json}]", null, "application/json");
requests.Content = contents;
client.SendAsync(requests);
}
public static void Switchlanguage(int idenx)
{
if (idenx>1)
{
return;
}
//查询出所有的mac数据
var list=CSVPositionReader<TSAVPosition>.getPositionList();
var entity= list.Where(a => a.PositionType == 2).ToList();
if (entity == null)
return;
List<string> strings=new List<string>();
foreach (var item in entity)
{
var dic = dictionry(idenx);
dic["mac"] = item.Leds.ToString();
dic["lot"] = item.PositionNum.ToString();
dic["desc"] = null;
dic["PN"] = null;
dic["QTY"] = null;
string str=JsonHelper.SerializeObject(dic);
dic.Clear();
strings.Add(str);
}
string jsons = "";
foreach (var item in strings)
{
jsons += item + ",";
}
var client = new HttpClient();
var requests = new HttpRequestMessage(HttpMethod.Post, $"http://{entity[0].DeviceIP}/wms/associate/updateScreen");
string json = JsonHelper.SerializeObject(strings);
string aaa = $"[{jsons.Substring(0,jsons.Length - 1)}]";
var contents = new StringContent($"[{jsons.Substring(0,jsons.Length-1)}]", null, "application/json");
requests.Content = contents;
client.SendAsync(requests);
}
/// <summary>
/// 修改样式模板
/// </summary>
/// <param name="ip">ip地址</param>
/// <param name="mac">mac地址</param>
/// <param name="count">物料数量</param>
/// <param name="pnname">物料名称</param>
/// <param name="PN">库位编号位置名称</param>
public static void UpdateQty(DataModel data)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"http://{data.ip}/wms/associate/updateScreen");
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("Count", "Qty:");
dic.Add("Describe", "Desc:");
dic.Add("PN", data.name);
dic.Add("PartNumber", "Name:");
dic.Add("QRcode", "123456");
dic.Add("QTY", $"{int.Parse(data.count)-1}");
dic.Add("Striptype", "----------------------------------------");
dic.Add("desc", data.ComponentDes);
dic.Add("ledrgb", "0");
dic.Add("ledstate", "0");
dic.Add("location", "Lot.:");
dic.Add("logo", "neotel12");
dic.Add("logoname", "NEO LABEL");
dic.Add("lot", data.PNum);
dic.Add("mac", data.mac);
dic.Add("mappingtype",538);
dic.Add("outtime", "0");
dic.Add("styleid", 53);
string json = JsonHelper.SerializeObject(dic);
var contents = new StringContent($"[{json}]", null, "application/json");
request.Content = contents;
client.SendAsync(request);
}
public static Dictionary<string, object> dictionry(int idenx)
{
Dictionary<string, object> dic = new Dictionary<string, object>();
//中文请求
if (idenx == 0)
{
dic.Add("Count", "数量:");
dic.Add("Describe", "物料描述:");
dic.Add("PartNumber", "名称:");
dic.Add("QRcode", "123456");
dic.Add("Striptype", "----------------------------------------");
dic.Add("ledrgb", "0");
dic.Add("ledstate", "0");
dic.Add("location", "库位编号:");
dic.Add("logo", "neotel12");
dic.Add("logoname", "NEO LABEL");
dic.Add("mappingtype", 538);
dic.Add("outtime", "0");
dic.Add("styleid", 53);
dic.Add("mac", null);
dic.Add("PN", null);
dic.Add("QTY", $"{null}");
dic.Add("lot", null);
dic.Add("desc", null);
}
else if (idenx == 1)//英文请求
{
dic.Add("Count", "Qty:");
dic.Add("Describe", "Desc:");
dic.Add("PartNumber", "Name:");
dic.Add("QRcode", "123456");
dic.Add("Striptype", "----------------------------------------");
dic.Add("ledrgb", "0");
dic.Add("ledstate", "0");
dic.Add("location", "Lot.:");
dic.Add("logo", "neotel12");
dic.Add("logoname", "NEO LABEL");
dic.Add("mappingtype", 538);
dic.Add("outtime", "0");
dic.Add("styleid", 53);
dic.Add("mac", null);
dic.Add("PN", null);
dic.Add("QTY", $"{null}");
dic.Add("lot", null);
dic.Add("desc", null);
}
return dic;
}
//public static DataTable GetData(string filePath)
//{
// // 设置文件路径和工作表名称
// //string filePath = "path/to/your/excel/file.xlsx";
// string worksheetName = "Sheet1";
// // 创建ExcelDataReader对象并打开工作簿
// using (var reader = ExcelReaderFactory.CreateReader(filePath))
// {
// reader.IsFirstRowAsColumnNames = true; // 将第一行作为列名
// var result = reader.AsDataSet(new ExcelDataSetConfiguration()
// {
// ConfigureDataTable = (_) => new ExcelDataTableConfiguration()
// {
// UseHeaderRow = true // 使用标题行作为列名
// }
// });
// // 获取指定工作表的数据表
// DataTable dt = result.Tables[worksheetName];
// // 在此处使用数据表进行处理
// }
//}
public class DataModel
{
/// <summary>
/// ip地址
/// </summary>
public string ip { get; set; }
/// <summary>
/// mac地址
/// </summary>
public string mac { get; set; }
/// <summary>
/// 记录上一个库位编号
/// </summary>
public string PNum { get; set; }
/// <summary>
/// 元器件数量
/// </summary>
public string count { get; set; }
/// <summary>
/// 元器件名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 元器件描述
/// </summary>
public string ComponentDes { get; set; }
}
}
}