Commit 5e93ab72 LN

与流水线通信格式修改。

1 个父辈 a8c49f96
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<add key="HumitureControllerType" value="0"/> <add key="HumitureControllerType" value="0"/>
<add key="UseAIOBOX" value="1"/> <add key="UseAIOBOX" value="1"/>
<!--流水线地址和端口配置--> <!--流水线地址和端口配置-->
<add key ="LineServerIp" value ="192.168.1.113"/> <add key ="LineServerIp" value ="192.168.1.110"/>
<add key ="LineServerPort" value ="5246"/> <add key ="LineServerPort" value ="5246"/>
<!--是否调试状态--> <!--是否调试状态-->
<add key ="IsInDebug" value ="1"/> <add key ="IsInDebug" value ="1"/>
......
...@@ -1363,7 +1363,8 @@ namespace OnlineStore.ACSingleStore ...@@ -1363,7 +1363,8 @@ namespace OnlineStore.ACSingleStore
{ {
ss = StoreStatus.Debugging; ss = StoreStatus.Debugging;
} }
LineConnect.SendHeart(StoreManager.Config.Id, StoreManager.Config.CID, (int)ss, (int)StoreRunStatus.Runing, hasTray,(int)StoreAlarmType.None); StoreSendBean bean = new StoreSendBean(StoreManager.Config.Id, StoreManager.Config.CID, (int)ss, (int)StoreRunStatus.Runing, hasTray, (int)StoreAlarmType.None);
LineConnect.SendHeart(bean);
} }
private void chbDebug_CheckedChanged(object sender, EventArgs e) private void chbDebug_CheckedChanged(object sender, EventArgs e)
......
...@@ -77,12 +77,12 @@ namespace OnlineStore.Common ...@@ -77,12 +77,12 @@ namespace OnlineStore.Common
private static List<string> lasErrorLogList = new List<string>(); private static List<string> lasErrorLogList = new List<string>();
private static int errCount = 5; private static int errCount = 5;
public static void error(ILog log, string errorMsg,int type) public static void error(ILog log, string errorMsg,int type,int spanSeconds=10)
{ {
if (lastErrorLogTime.ContainsKey(type)) if (lastErrorLogTime.ContainsKey(type))
{ {
TimeSpan span = DateTime.Now - lastErrorLogTime[type]; TimeSpan span = DateTime.Now - lastErrorLogTime[type];
if (span.TotalSeconds < 10) if (span.TotalSeconds < spanSeconds)
{ {
return; return;
} }
......
...@@ -154,7 +154,7 @@ namespace OnlineStore.Common ...@@ -154,7 +154,7 @@ namespace OnlineStore.Common
if (m_clientSocket != null) if (m_clientSocket != null)
{ {
m_clientSocket.Close(); m_clientSocket.Close();
LogUtil.info(LOGGER, "Socket closed!"); LogUtil.debug(LOGGER, "Socket closed!");
} }
}catch(Exception ex) }catch(Exception ex)
{ {
...@@ -176,9 +176,9 @@ namespace OnlineStore.Common ...@@ -176,9 +176,9 @@ namespace OnlineStore.Common
catch (Exception ex) catch (Exception ex)
{ {
isInProcess = false; isInProcess = false;
LogUtil.error("重连处理出错:" + ex.ToString()); LogUtil.error(LOGGER, "重连处理出错:" + ex.ToString(),9,180);
} }
} }
/// <summary> /// <summary>
/// 断开连接 /// 断开连接
......
...@@ -654,7 +654,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -654,7 +654,11 @@ namespace OnlineStore.DeviceLibrary
{ {
ss = (int)StoreStatus.Debugging; ss = (int)StoreStatus.Debugging;
} }
LineConnect.OutStoreEnd(Config.Id, Config.CID, (int)storeStatus, (int)storeRunStatus, hasTray,(int)alarmType, StoreMove.MoveParam.PositionNum, StoreMove.MoveParam.PlateH,StoreMove.MoveParam.PlateW); StoreSendBean store = new StoreSendBean(Config.Id, Config.CID, (int)storeStatus, (int)storeRunStatus, hasTray, (int)alarmType);
store.PosId = StoreMove.MoveParam.PositionNum;
store.PlateH = StoreMove.MoveParam.PlateH;
store.PlateW = StoreMove.MoveParam.PlateW;
LineConnect.OutStoreEnd(store);
} }
else if (StoreMove.MoveStep == StoreMoveStep.SO_13_GoBack) else if (StoreMove.MoveStep == StoreMoveStep.SO_13_GoBack)
{ {
......
...@@ -9,8 +9,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -9,8 +9,9 @@ namespace OnlineStore.DeviceLibrary
{ {
public class LineConnect public class LineConnect
{ {
private static int ClientKeepSecond = 10;
private static TcpClient client = null; private static TcpClient client = null;
public static List<string> WaitInStoreList = new List<string>();
public static void StartConnect() public static void StartConnect()
{ {
string lineServer = ConfigAppSettings.GetValue(Setting_Init.LineServerIp); string lineServer = ConfigAppSettings.GetValue(Setting_Init.LineServerIp);
...@@ -21,6 +22,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -21,6 +22,7 @@ namespace OnlineStore.DeviceLibrary
return; return;
} }
client = new TcpClient(); client = new TcpClient();
bool result = client.StartConnect(lineServer, linePort, HandlerMsg,2000); bool result = client.StartConnect(lineServer, linePort, HandlerMsg,2000);
} }
...@@ -45,7 +47,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -45,7 +47,7 @@ namespace OnlineStore.DeviceLibrary
return seq; return seq;
} }
public static void SendHeart(int id,string cid,int ss,int runs,int doorHasTray,int alarmType) public static void SendHeart(StoreSendBean store)
{ {
if (client == null) if (client == null)
{ {
...@@ -53,24 +55,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -53,24 +55,16 @@ namespace OnlineStore.DeviceLibrary
} }
try try
{ {
List<object> paramList = new List<object>(); store.Cmd = cmd_heart;
paramList.Add(cmd_heart); string heartMsg = ToParamStr(store);
paramList.Add(id);
paramList.Add(cid);
paramList.Add(nextSeq());
paramList.Add(ss);
paramList.Add(runs);
paramList.Add(doorHasTray);
paramList.Add(alarmType);
string heartMsg = ToParamStr(paramList);
client.send(heartMsg); client.send(heartMsg);
}catch(Exception ex) } catch (Exception ex)
{ {
LogUtil.error("SendHeart 出错:"+ex.ToString()); LogUtil.error("SendHeart 出错:" + ex.ToString());
} }
} }
public static void OutStoreEnd(int id, string cid, int ss, int runs, int doorHasTray, int alarmType,string posid, string plateH, string plateW)
public static void OutStoreEnd(StoreSendBean store)
{ {
if (client == null) if (client == null)
{ {
...@@ -78,71 +72,74 @@ namespace OnlineStore.DeviceLibrary ...@@ -78,71 +72,74 @@ namespace OnlineStore.DeviceLibrary
} }
try try
{ {
List<object> paramList = new List<object>(); store.Cmd = cmd_outend;
paramList.Add(cmd_outend); string msg = ToParamStr(store);
paramList.Add(id); client.send(msg);
paramList.Add(cid);
paramList.Add(nextSeq());
paramList.Add(ss);
paramList.Add(runs);
paramList.Add(doorHasTray);
paramList.Add(alarmType);
paramList.Add(posid);
paramList.Add(plateH);
paramList.Add(plateW);
//string heartMsg = cmd_outend + cmd_spilt + id + cmd_spilt + cid + cmd_spilt + nextSeq() + cmd_spilt + ss + cmd_spilt + runs + cmd_spilt + doorHasTray+ cmd_spilt + posid + cmd_spilt;
//string msg = heartMsg + posid + cmd_spilt + plateH + cmd_spilt + plateW + cmd_spilt + "\r";
string msg = ToParamStr(paramList);
client.send(msg );
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("OutStoreEnd 出错:" + ex.ToString()); LogUtil.error("OutStoreEnd 出错:" + ex.ToString());
} }
} }
private static string ToParamStr(StoreSendBean store)
{
return JsonHelper.SerializeObject(store)+"\r";
}
private static string ToParamStr(List<object> paramList) private static string ToParamStr(List<object> paramList)
{ {
string result = ""; string result = "";
foreach(object str in paramList) foreach (object str in paramList)
{ {
result += str + cmd_spilt.ToString(); result += str + cmd_spilt.ToString();
} }
return result+"\r"; return result + "\r";
} }
private static void HandlerMsg(string message) private static void HandlerMsg(string message)
{ {
try try
{ {
string[] msgArray = message.Split(cmd_spilt); message = message.Replace("\r", "");
if (msgArray.Length > 2) StoreReviceBean reviceInfo = JsonHelper.DeserializeJsonToObject<StoreReviceBean>(message);
//string[] msgArray = message.Split(cmd_spilt);
if (reviceInfo == null)
{
LogUtil.debug("收到消息:" + message + ",解析失败");
}
else
{ {
string cmd = msgArray[0]; string cmd = reviceInfo.Cmd;
int canStartOut = Convert.ToInt32(msgArray[1]); CanOutStore = reviceInfo.CanOutStore.Equals(1);
CanOutStore = canStartOut.Equals(1);
LastUpdateTime = DateTime.Now; LastUpdateTime = DateTime.Now;
if (cmd.Equals(cmd_startIn)) if (cmd.Equals(cmd_startIn))
{ {
LogUtil.info("收到流水线入库消息:" + message); LogUtil.info("收到流水线入库消息:" + message);
string posId = msgArray[2]; //string posId = reviceInfo.PosId;
string plateH = msgArray[3]; //string plateH = reviceInfo.PlateH
string plateW = msgArray[4]; //string plateW = msgArray[4];
string code = msgArray[5]; //string code = msgArray[5];
StoreManager.Store.ReviceLineInStoreCMD(posId, plateH, plateW, code); StoreManager.Store.ReviceLineInStoreCMD(reviceInfo.PosId,reviceInfo.PlateH,reviceInfo.PlateW,reviceInfo.WareCode);
} }
else if (cmd.Equals(cmd_updateDebug)) else if (cmd.Equals(cmd_updateDebug))
{ {
int isDebug = Convert.ToInt32(msgArray[2]); int isDebug = reviceInfo.IsDebug;
LogUtil.info("收到流水线更改调试状态=" + isDebug); LogUtil.info("收到流水线更改调试状态=" + isDebug);
StoreManager.Store.IsDebug = isDebug.Equals(1) ? true : false; StoreManager.Store.IsDebug = isDebug.Equals(1) ? true : false;
ConfigAppSettings.SaveValue(Setting_Init.IsInDebug, isDebug); ConfigAppSettings.SaveValue(Setting_Init.IsInDebug, isDebug);
LogUtil.info("切换调试状态= " + isDebug + ";"); LogUtil.info("切换调试状态= " + isDebug + ";");
} }
else else if (cmd.Equals(cmd_checStartIn))
{ {
LogUtil.debug("收到消息:" + message); LogUtil.info("收到流水线入库库位验证消息:" + message);
bool result = StoreManager.Store.ReviceLineCheckInStoreCMD(reviceInfo.PosId, reviceInfo.PlateH, reviceInfo.PlateW, reviceInfo.WareCode);
if (result)
{
LineConnect.WaitInStoreList.Add(reviceInfo.PosId);
}
} }
} }
} }
catch (Exception ex) catch (Exception ex)
...@@ -151,12 +148,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -151,12 +148,13 @@ namespace OnlineStore.DeviceLibrary
} }
} }
public static char cmd_spilt = ';'; public static char cmd_spilt = ';';
private static string cmd_heart = "heart"; public static string cmd_heart = "heart";
private static string cmd_outend = "outend"; private static string cmd_outend = "outend";
private static string cmd_startIn = "starIn"; private static string cmd_startIn = "starIn";
private static string cmd_updateDebug = "updateDebug"; private static string cmd_updateDebug = "updateDebug";
private static bool CanOutStore = false; private static bool CanOutStore = false;
public static DateTime LastUpdateTime = new DateTime(0); public static DateTime LastUpdateTime = new DateTime(0);
public static string cmd_checStartIn = "cmd_checStartIn";
public static bool IsConnect() public static bool IsConnect()
{ {
if (client == null) if (client == null)
...@@ -173,11 +171,45 @@ namespace OnlineStore.DeviceLibrary ...@@ -173,11 +171,45 @@ namespace OnlineStore.DeviceLibrary
public static bool CanStartOut() public static bool CanStartOut()
{ {
TimeSpan span = DateTime.Now - LastUpdateTime; TimeSpan span = DateTime.Now - LastUpdateTime;
if (span.TotalSeconds < 3 && CanOutStore) if (span.TotalSeconds < ClientKeepSecond && CanOutStore)
{ {
return true; return true;
} }
return false; return false;
} }
} }
public class StoreReviceBean
{
public string Cmd = "";
public int CanOutStore = 0;
public string PosId = "";
public string PlateH = "0";
public string PlateW = "0";
public string WareCode = "";
public int IsDebug = 0;
}
public class StoreSendBean
{
public StoreSendBean(int id, string cid, int ss, int runs, int doorHasTray, int alarmType)
{
this.StoreId = id;
this.Cid = cid;
this.SStatus = ss;
this.SRunStatus = runs;
this.DoorHasTray = doorHasTray;
this.AlarmType = alarmType;
this.Seq = LineConnect.nextSeq();
}
public string Cmd =LineConnect. cmd_heart;
public int StoreId = 0;
public string Cid = "";
public int Seq = 0;
public int SStatus = 0;
public int SRunStatus = 0;
public int DoorHasTray = 0;
public int AlarmType = 0;
public string PosId = "";
public string PlateH = "0";
public string PlateW = "0";
}
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!