StoreServerManager.cs
7.8 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
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class StoreServerManager
{
private static string spiltStr = "%23%23";
public static string CodeReceived(string deviceName, int trayNum, List<string> codeList, int height, int width)
{
string msg = "";
try
{
string codeStr = "";
foreach(string str in codeList)
{
if (codeStr.Equals(""))
{
codeStr = str;
}
else
{
codeStr += spiltStr + str;
}
}
if (String.IsNullOrEmpty(codeStr))
{
return msg = deviceName + "托盘【" + trayNum + "】 没有扫码到条码";
}
if (LineManager.Line.runStatus.Equals(LineRunStatus.Wait))
{
return msg = deviceName + "托盘【" + trayNum + "】 收到条码<< " + codeStr + ",暂未开启,不需要发送服务器";
}
//http://localhost/myproject/service/store/emptyPosForPutin
// 参数:cids: 多个 cid
//code: 条码内容
string server = ConfigAppSettings.GetValue(Setting_Init.http_server) + "?cids=" + LineServer.GetAllCID() + "&code=%3D" + codeStr;
LogUtil.info(deviceName + "托盘【" + trayNum + "】 收到条码<< " + codeStr + ",获取入库PosID:" + server);
//发送扫码内容到服务器进行入库操作
// Operation operation =LineServer.GetInStoreOperation(codeStr);
// LineGetPosOp op = new LineGetPosOp(LineServer.GetAllCID(), codeStr);
string resultStr = HttpHelper.Post(server, "");
LineOperation serverResult = JsonHelper.DeserializeJsonToObject<LineOperation>(resultStr);
if (serverResult == null)
{
return msg = deviceName + "托盘【" + trayNum + "】 条码【" + codeStr + "】没有收到服务器反馈";
}
else if ((!string.IsNullOrEmpty(serverResult.msg)) || serverResult.result.Equals(0).Equals(false))
{
return msg = deviceName + "托盘【" + trayNum + "】 条码【" + codeStr + "】 :" + serverResult.msg;
}
if (!serverResult.pos.Equals(""))
{
string posId = serverResult.pos;
int plateW = width;
int plateH = height;
string[] posArray = posId.Split('#');
if (!(posArray.Length == 2))
{
return msg = deviceName + "托盘【" + trayNum + "】 入库库位格式错误:条码【" + codeStr + "】库位【" + posId + "】";
}
//判断盘是否过高(7*8的盘需要判断,如果盘过高,不让盘通过,直接显示报警信息)
int storeId = int.Parse(posArray[0]);
//根据库位号查找移栽
MoveEquip moveEquip = LineManager.Line.MoveEquipMap[storeId];
//取盘号
string wareNum = serverResult.barcode;
int trayCode = TrayManager.GetTrayNum(0);
LogUtil.info("更新盘空满信息,托盘号【" + trayCode + "】,是否有料盘【" + true + "】,出库入库【" + 1 + "】");
TrayManager.UpdateTrayInfo(trayCode, true, ReelType.InStore, wareNum, posId, plateH, plateW);
//TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器;
if (LineServer.BoxCanInStore(moveEquip.DeviceID))
{
InOutParam param = new InOutParam(trayCode, wareNum, posId, plateH, plateW);
// 判断PosID是否已经在入库或者在排队列表中,如果已经存在,加入列表失败
if (LineManager.Line.IsReviceInPosId(moveEquip, posId))
{
LineManager.Line.WarnMsg = "入库库位重复: " + param.ToStr() + " ,入库失败!";
moveEquip.WarnMsg = "入库库位重复: " + param.ToStr() + " ,入库失败!";
return msg = ("收到服务器入库命令 " + "入库库位重复: " + param.ToStr() + " ,入库失败!");
}
LineServer.CheckInStorePos(storeId, param);
//StartInStoreMove(param);
TrayManager.UpdateTrayInfo(trayCode, true, 1, codeStr, posId, plateH, plateW);
}
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " " + ex.ToString());
}
return "";
}
///// <summary>
///// 是否已经扫码
///// </summary>
//private bool IsScanCode = false;
//private string CodeMsg = "";
//private static string ACCode = "";
//public void GetCameraCode()
//{
// if (IsInScan())
// {
// LogUtil.info("上次扫码还未执行完毕,请稍后!");
// return;
// }
// Task.Factory.StartNew(delegate
// {
// IsScanCode = true;
// LastScanTime = DateTime.Now;
// DateTime date = DateTime.Now;
// // IOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
// List<string> codeList = CodeManager.CameraScan();
// if (codeList.Count <= 0)
// {
// codeList = CodeManager.CameraScan();
// }
// List<string> list = new List<string>();
// string outMsg = "";
// string message = "";
// int height = GetHeight();
// int width = GetWidth();
// //= 1 + 123.4x100.5 - 7x12 = CODE
// foreach (string str in codeList)
// {
// if (list.Contains(str.Trim()))
// {
// continue;
// }
// list.Add(str.Trim());
// //string code = "=1+0x0-" + width + "x" + height + "=" + str.Trim();
// string code = width + "x" + height + "%3D" + str.Trim();
// message = message + code + spiltStr;
// }
// if (!outMsg.Equals(""))
// {
// CodeMsg = "盘尺寸错误,清理二维码【" + message + "】";
// LogUtil.error("盘尺寸错误,清理二维码【" + message + "】");
// message = "";
// }
// // KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
// onCodeReceived(message, height, width);
// IsScanCode = false;
// });
//}
//
//private DateTime LastScanTime = DateTime.Now;
//private bool IsInScan()
//{
// if (!IsScanCode)
// {
// return false;
// }
// TimeSpan span = DateTime.Now - LastScanTime;
// if (span.TotalSeconds > 60)
// {
// //大于60秒表示超时了,可以重新开始扫码
// return false;
// }
// return true;
//}
}
}