AC_BOX_Bean_ScanCode.cs
12.4 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
using Asa;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public partial class AC_BOX_Bean
{
#region 扫码获取库位
/// <summary>
/// 数据接收
/// </summary>
/// <param name="message"></param>
private bool GetPosIdByCode()
{
try
{
if (LastWidth <= 0)
{
LastWidth = 7;
}
//string message = StoreManager.ProcessCode(LastWidth, LastHeight, LastScanCodes);
string message = MoveInfo.shelfLockDatas[MoveInfo.currShelfIndex].barcode;
if (message.Equals("") || string.IsNullOrEmpty(message))
{
CodeMsg = "未扫到二维码";
LogInfo("未扫到二维码");
return false;
}
if (storeRunStatus.Equals(StoreRunStatus.Wait))
{
LogInfo("二维码【 " + message + "】,设备未启动,不需要发送服务器");
return false;
}
// CodeMsg = "收到二维码【 " + message + "】,发送给服务器获取入库PosID";
LogUtil.info(Name + "二维码【 " + message + "】,发送给服务器获取入库PosID");
//发送扫码内容到服务器进行入库操作
Operation operation = getLineBoxStatus();
operation.op = 1;
operation.data = new Dictionary<string, string>() { { "code", message }, { "boxId", 1.ToString() }, { ParamDefine.rfid, CurrShelfID } };
string server = Setting_Init.http_server;
Operation resultOperation = HttpHelper.PostJson(StoreManager.GetPostApi(server), operation, false);
if (resultOperation == null)
{
CodeMsg = "二维码【" + message + "】没有收到服务器反馈";
LogInfo("二维码【 " + message + "】没有收到服务器反馈!");
return false;
}
else if (!string.IsNullOrEmpty(resultOperation.msg))
{
//如果有提示消息,直接显示提示
LogInfo("二维码【 " + message + "】 :" + resultOperation.msg);
return false;
}
if (resultOperation.op.Equals(1))
{
Dictionary<string, string> data = resultOperation.data;
if (data != null && data.ContainsKey(ParamDefine.posId) && data.ContainsKey(ParamDefine.plateH) && data.ContainsKey(ParamDefine.plateW))
{
//服务器返回时有:posId库位编号,plateW:料盘宽度,plateH:料盘高度,
//postId格式BoxId#位置
string posId = data[ParamDefine.posId];
int plateW = FormUtil.GetIntData(data, ParamDefine.plateW);
int plateH = FormUtil.GetIntData(data, ParamDefine.plateH);
int storeId = InOutParam.GetPosStoreId(posId);
//根据发送的posId获取位置列表
ACBoxPosition position = CSVPositionReader<ACBoxPosition>.GetPositon(posId);
if (position == null)
{ //出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = "入库未找到库位:二维码【" + message + "】库位【" + posId + "】 ";
LogUtil.error(Name + "收到服务器入库命令:入库未找到库位:二维码【" + message + "】库位【" + posId + "】");
return false;
}
int p2 = Config.GetComP2(plateH).TargetComP2(); ;
int p3 = p2 + Config.GetCom_P3_P2(plateW);
LogInfo(" 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】设置入库参数,压紧位置["+p2+"]["+p3+"] , 开始入库!");
MoveInfo.MoveParam.UpdatePosId(message, posId, plateW, plateH, p2, p3);
return true;
}
}
else if (resultOperation.op.Equals(2))
{
ReviceOutStoreProcess(resultOperation);
}
else if (resultOperation.op.Equals(5))
{
humBean.ProcessHumidityCMD(resultOperation);
}
else
{
LogUtil.error("收到服务器命令:op=" + resultOperation.op + ",未找到对应处理");
}
}
catch (Exception ex)
{
LogUtil.error(Name + "GetPosIdByCode" + ex.StackTrace);
}
return false;
}
/// <summary>
/// 扫码枪数据接收
/// </summary>
/// <param name="codeResultType">扫码结果</param>
/// <returns></returns>
public enum CodeResultType
{
/// <summary>
/// 未扫到二维码
/// </summary>
NoCode,
/// <summary>
/// 设备未启动
/// </summary>
DeviceNotOpen,
/// <summary>
///未收到服务器反馈
/// </summary>
NotResponseFromServer,
WarnMsg,
/// <summary>
/// 未找到库位
/// </summary>
NotFoundPos,
/// <summary>
/// 不属于该仓位
/// </summary>
NotPosForPutIn,
Error,
Success
}
private bool GetPosIdByCode(int rfidLoc, out CodeResultType codeResultType)
{
try
{
if (LastWidth <= 0)
{
LastWidth = 7;
}
string message = StoreManager.ProcessCode(LastWidth, LastHeight, LastScanCodes);
if (message.Equals("") || string.IsNullOrEmpty(message))
{
CodeMsg = "未扫到二维码";
LogInfo("未扫到二维码");
codeResultType = CodeResultType.NoCode;
return false;
}
if (storeRunStatus.Equals(StoreRunStatus.Wait))
{
LogInfo("二维码【 " + message + "】,设备未启动,不需要发送服务器");
codeResultType = CodeResultType.DeviceNotOpen;
return false;
}
// CodeMsg = "收到二维码【 " + message + "】,发送给服务器获取入库PosID";
LogUtil.debug (Name + "二维码【 " + message + "】,发送给服务器获取入库PosID");
//查询该料盘所在料仓以及仓位
StoreManager.ResultType resultType = StoreManager.GetPosForPutIn(Name, Config, message, CurrShelfID, rfidLoc, out bool isLockInfoMatch);
if(resultType.Equals(CodeResultType.Error))
{
resultType = StoreManager.GetPosForPutIn(Name, Config, message, CurrShelfID, rfidLoc, out isLockInfoMatch);
}
if (resultType == StoreManager.ResultType.Error)
{
codeResultType = CodeResultType.Error;
return false;
}
else if(resultType == StoreManager.ResultType.NotInThisBox)
{
codeResultType = CodeResultType.NotPosForPutIn;
return false;
}
if (!isLockInfoMatch && MoveInfo.IsShelfLocked)//锁定信息不匹配则从第一层开始重新取料,一个料架只重新开始一次
{
MoveInfo.IsShelfLocked = false;
MoveInfo.currShelfIndex = -1;
LogUtil.info(Name + "该锁定料架" + CurrShelfID + "上的料盘信息不匹配,即将从开始位置循环取料");
}
//发送扫码内容到服务器进行入库操作
Operation operation = getLineBoxStatus();
operation.op = 1;
operation.data = new Dictionary<string, string>() { { "code", message }, { "boxId", 1.ToString() }, { ParamDefine.rfid, CurrShelfID } };
string server = Setting_Init.http_server;
Operation resultOperation = HttpHelper.PostJson(StoreManager.GetPostApi(server), operation, false);
if (resultOperation == null)
{
CodeMsg = "二维码【" + message + "】没有收到服务器反馈";
LogInfo("二维码【 " + message + "】没有收到服务器反馈!");
codeResultType = CodeResultType.NotResponseFromServer;
return false;
}
else if (!string.IsNullOrEmpty(resultOperation.msg))
{
//如果有提示消息,直接显示提示
LogInfo("二维码【 " + message + "】 :" + resultOperation.msg);
codeResultType = CodeResultType.WarnMsg;
return false;
}
if (resultOperation.op.Equals(1))
{
Dictionary<string, string> data = resultOperation.data;
if (data != null && data.ContainsKey(ParamDefine.posId) && data.ContainsKey(ParamDefine.plateH) && data.ContainsKey(ParamDefine.plateW))
{
//服务器返回时有:posId库位编号,plateW:料盘宽度,plateH:料盘高度,
//postId格式BoxId#位置
string posId = data[ParamDefine.posId];
int plateW = FormUtil.GetIntData(data, ParamDefine.plateW);
int plateH = FormUtil.GetIntData(data, ParamDefine.plateH);
int storeId = InOutParam.GetPosStoreId(posId);
//根据发送的posId获取位置列表
ACBoxPosition position = CSVPositionReader<ACBoxPosition>.GetPositon(posId);
if (position == null)
{ //出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = "入库未找到库位:二维码【" + message + "】库位【" + posId + "】 ";
LogUtil.error(Name + "收到服务器入库命令:入库未找到库位:二维码【" + message + "】库位【" + posId + "】");
codeResultType = CodeResultType.NotFoundPos;
return false;
}
int p2 = Config.GetComP2(plateH).TargetComP2(); ;
int p3 = p2 + Config.GetCom_P3_P2(plateW);
LogInfo(" 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】设置入库参数,压紧位置[" + p2 + "][" + p3 + "] , 开始入库!");
MoveInfo.MoveParam.UpdatePosId(message, posId, plateW, plateH, p2, p3);
codeResultType = CodeResultType.Success;
return true;
}
}
else if (resultOperation.op.Equals(2))
{
ReviceOutStoreProcess(resultOperation);
}
else if (resultOperation.op.Equals(5))
{
humBean.ProcessHumidityCMD(resultOperation);
}
else
{
LogUtil.error("收到服务器命令:op=" + resultOperation.op + ",未找到对应处理");
}
}
catch (Exception ex)
{
LogUtil.error(Name + "GetPosIdByCode" + ex.StackTrace);
}
codeResultType = CodeResultType.Error;
return false;
}
#endregion
}
}