Commit 46aa9c56 张东亮

发送状态死锁造成离线

1 个父辈 e950f5cc
...@@ -105,13 +105,13 @@ namespace DeviceLibrary ...@@ -105,13 +105,13 @@ namespace DeviceLibrary
} }
bool isnglog = false; bool isnglog = false;
public void LogNgInfo(ServerCommunication server) //public void LogNgInfo(ServerCommunication server)
{ //{
if (!isnglog && IsNg) // if (!isnglog && IsNg)
{ // {
isnglog = server.SendNGInfo(NgMsg); // isnglog = server.SendNGInfo(NgMsg);
} // }
} //}
} }
} }
...@@ -44,7 +44,7 @@ namespace DeviceLibrary ...@@ -44,7 +44,7 @@ namespace DeviceLibrary
string WarnMsg = ""; string WarnMsg = "";
private System.Timers.Timer serverConnectTimer = new System.Timers.Timer(); private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
public object serverclock = new object(); public object serverclock = new object();
public ServerCommunication() public ServerCommunication()
{ {
serverConnectTimer.Interval = 1000; serverConnectTimer.Interval = 1000;
...@@ -73,7 +73,7 @@ namespace DeviceLibrary ...@@ -73,7 +73,7 @@ namespace DeviceLibrary
LogUtil.error("上传SendLineStatus超时"); LogUtil.error("上传SendLineStatus超时");
} }
} }
} }
public void ProcessMsg(List<Msg> msg) public void ProcessMsg(List<Msg> msg)
...@@ -158,7 +158,7 @@ namespace DeviceLibrary ...@@ -158,7 +158,7 @@ namespace DeviceLibrary
} }
else if (!RobotManage.isRunning) else if (!RobotManage.isRunning)
{ {
sendmsg = "I="+crc.GetString("Res0127.a5affabf","设备未启动"); sendmsg = "I=" + crc.GetString("Res0127.a5affabf", "设备未启动");
} }
lineOperation.msg = sendmsg; lineOperation.msg = sendmsg;
...@@ -168,9 +168,9 @@ namespace DeviceLibrary ...@@ -168,9 +168,9 @@ namespace DeviceLibrary
lineOperation.msgJp = lineOperation.msg; lineOperation.msgJp = lineOperation.msg;
//lineOperation.boxStatus.Add(StoreID, boxStatus); //lineOperation.boxStatus.Add(StoreID, boxStatus);
lineOperation.data= lineOperation.data.Union(UnifiedDataHandler.PrintNgMESData()).ToDictionary(x=>x.Key,x=>x.Value); lineOperation.data = lineOperation.data.Union(UnifiedDataHandler.PrintNgMESData()).ToDictionary(x => x.Key, x => x.Value);
lineOperation.showLogs = StepInformation(out Dictionary<string,string> dic); lineOperation.showLogs = StepInformation(out Dictionary<string, string> dic);
lineOperation.data =lineOperation.data.Union(dic).ToDictionary(x => x.Key, x => x.Value); lineOperation.data = lineOperation.data.Union(dic).ToDictionary(x => x.Key, x => x.Value);
return lineOperation; return lineOperation;
} }
private static string api_communication = "service/equipment/communication"; //流水线状态通信接口 private static string api_communication = "service/equipment/communication"; //流水线状态通信接口
...@@ -207,7 +207,7 @@ namespace DeviceLibrary ...@@ -207,7 +207,7 @@ namespace DeviceLibrary
{ {
try try
{ {
lock (serverclock) // lock (serverclock)
{ {
bool printlog = false; bool printlog = false;
DateTime time = DateTime.Now; DateTime time = DateTime.Now;
...@@ -232,38 +232,46 @@ namespace DeviceLibrary ...@@ -232,38 +232,46 @@ namespace DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("SendLineStatus",ex); LogUtil.error("SendLineStatus", ex);
}
finally
{
Monitor.Exit(serverclock);
} }
} }
public bool SendAgvLog(string msg) public bool SendAgvLog(string msg)
{ {
if (Monitor.TryEnter(serverclock, TimeSpan.FromSeconds(5))) if (Monitor.TryEnter(serverclock, TimeSpan.FromSeconds(5)))
{ {
if (!server.ToLower().StartsWith("http")) try
{
return false;
}
lock (serverclock)
{ {
Operation operation = getLineBoxStatus(); if (!server.ToLower().StartsWith("http"))
{
return false;
}
//lock (serverclock)
{
Operation operation = getLineBoxStatus();
//operation.logList = new List<AgvLogInfo> //operation.logList = new List<AgvLogInfo>
//{ //{
// new AgvLogInfo(msg) // new AgvLogInfo(msg)
//}; //};
//LogUtil.info(JsonHelper.SerializeObject(operation)); //LogUtil.info(JsonHelper.SerializeObject(operation));
Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 5000); Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 5000);
if (resultOperation == null) if (resultOperation == null)
{ {
LogUtil.info($"SendAgvLog error:{msg}"); LogUtil.info($"SendAgvLog error:{msg}");
return false; return false;
}
LogUtil.info($"SendAgvLog success:{msg}");
} }
LogUtil.info($"SendAgvLog success:{msg}"); return true;
} }
return true; finally { Monitor.Exit(serverclock); }
} }
else else
{ {
...@@ -276,34 +284,42 @@ namespace DeviceLibrary ...@@ -276,34 +284,42 @@ namespace DeviceLibrary
{ {
if (Monitor.TryEnter(serverclock, TimeSpan.FromSeconds(5))) if (Monitor.TryEnter(serverclock, TimeSpan.FromSeconds(5)))
{ {
if (!server.ToLower().StartsWith("http")) try
{
return false;
}
lock (serverclock)
{ {
Operation operation = getLineBoxStatus(); if (!server.ToLower().StartsWith("http"))
{
return false;
}
// lock (serverclock)
{
Operation operation = getLineBoxStatus();
//operation.mimoOpMap = new Dictionary<string, Dictionary<string, string>>(); //operation.mimoOpMap = new Dictionary<string, Dictionary<string, string>>();
//Dictionary<string, string> op = new Dictionary<string, string> //Dictionary<string, string> op = new Dictionary<string, string>
//{ //{
// { "Y10", "open" } // { "Y10", "open" }
//}; //};
//operation.mimoOpMap.Add("1", op); //operation.mimoOpMap.Add("1", op);
//operation.mimoOpMap.Add(mimoCid, operate); //operation.mimoOpMap.Add(mimoCid, operate);
LogUtil.info(JsonHelper.SerializeObject(operation)); LogUtil.info(JsonHelper.SerializeObject(operation));
Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 1000); Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 1000);
if (resultOperation == null) if (resultOperation == null)
{ {
LogUtil.info($"OpMIMO error:{msg}"); LogUtil.info($"OpMIMO error:{msg}");
return false; return false;
}
LogUtil.info($"OpMIMO success:{msg}");
} }
LogUtil.info($"OpMIMO success:{msg}"); return true;
} }
return true; finally
{
Monitor.Exit(serverclock);
}
} }
else else
{ {
...@@ -455,9 +471,9 @@ namespace DeviceLibrary ...@@ -455,9 +471,9 @@ namespace DeviceLibrary
/// 获取模板信息 /// 获取模板信息
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public List<EquipMsg> StepInformation(out Dictionary<string,string> dic) public List<EquipMsg> StepInformation(out Dictionary<string, string> dic)
{ {
dic = new Dictionary<string,string>(); dic = new Dictionary<string, string>();
List<EquipMsg> equipMsgs = new List<EquipMsg>(); List<EquipMsg> equipMsgs = new List<EquipMsg>();
try try
{ {
...@@ -477,12 +493,12 @@ namespace DeviceLibrary ...@@ -477,12 +493,12 @@ namespace DeviceLibrary
//msg.msgParams = new string[] { addressValue.GetStateStr() }; //msg.msgParams = new string[] { addressValue.GetStateStr() };
msg.msg = addressValue.GetStateStr(); msg.msg = addressValue.GetStateStr();
equipMsgs.Add(msg); equipMsgs.Add(msg);
if (addressValue.Name== crc.GetString("Res0039", "右侧取料")) if (addressValue.Name == crc.GetString("Res0039", "右侧取料"))
{ {
dic.Add("inShelfType", ShelfType.smallReel.ToString()); dic.Add("inShelfType", ShelfType.smallReel.ToString());
dic.Add("inShelfStatus", UnifiedDataHandler.ShelfStatus(true,Convert.ToInt32(addressValue.MoveStep))); dic.Add("inShelfStatus", UnifiedDataHandler.ShelfStatus(true, Convert.ToInt32(addressValue.MoveStep)));
} }
if (addressValue.Name== crc.GetString("Res0051", "左侧放料")) if (addressValue.Name == crc.GetString("Res0051", "左侧放料"))
{ {
dic.Add("outShelfType", ShelfType.smallReel.ToString()); dic.Add("outShelfType", ShelfType.smallReel.ToString());
dic.Add("outShelfStatus", UnifiedDataHandler.ShelfStatus(false, Convert.ToInt32(addressValue.MoveStep))); dic.Add("outShelfStatus", UnifiedDataHandler.ShelfStatus(false, Convert.ToInt32(addressValue.MoveStep)));
...@@ -497,7 +513,7 @@ namespace DeviceLibrary ...@@ -497,7 +513,7 @@ namespace DeviceLibrary
module = crc.GetString("Res0216", "打印机"), module = crc.GetString("Res0216", "打印机"),
msg = (printstatus == CustPrinterStatus.Unknown) ? "Wait" : printstatus.ToString(), msg = (printstatus == CustPrinterStatus.Unknown) ? "Wait" : printstatus.ToString(),
}; };
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -509,12 +525,10 @@ namespace DeviceLibrary ...@@ -509,12 +525,10 @@ namespace DeviceLibrary
public bool SendNGInfo(string ngmsg) public bool SendNGInfo(string ngmsg)
{ {
lock (serverclock) try
{ {
try Operation operation = getLineBoxStatus();
{ operation.msgList = new List<MsgInfo>
Operation operation = getLineBoxStatus();
operation.msgList = new List<MsgInfo>
{ {
new MsgInfo new MsgInfo
{ {
...@@ -523,30 +537,33 @@ namespace DeviceLibrary ...@@ -523,30 +537,33 @@ namespace DeviceLibrary
msg = ngmsg msg = ngmsg
} }
}; };
//operation.boxStatus[StoreID].status = (int)storeStatus; //operation.boxStatus[StoreID].status = (int)storeStatus;
//LogUtil.Log.Info(JsonHelper.SerializeObject(operation)); //LogUtil.Log.Info(JsonHelper.SerializeObject(operation));
Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 5000);
if (resultOperation == null) Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 5000);
{
LogUtil.error($"SendNGInfo error,ngmsg={ngmsg}");
return false;
}
if (operation.seq != resultOperation.seq)
{
LogUtil.error($"SendNGInfo seq error,ngmsg={ngmsg},cseq={operation.seq},rseq={resultOperation.seq}");
return false;
}
LogUtil.info($"SendNGInfo success,ngmsg={ngmsg}"); if (resultOperation == null)
ResultProcess(resultOperation); {
LogUtil.error($"SendNGInfo error,ngmsg={ngmsg}");
return false;
} }
catch (Exception ex) if (operation.seq != resultOperation.seq)
{ {
LogUtil.error($"SendNGInfo error:{ngmsg}", ex); LogUtil.error($"SendNGInfo seq error,ngmsg={ngmsg},cseq={operation.seq},rseq={resultOperation.seq}");
return false;
} }
LogUtil.info($"SendNGInfo success,ngmsg={ngmsg}");
ResultProcess(resultOperation);
}
catch (Exception ex)
{
LogUtil.error($"SendNGInfo error:{ngmsg}", ex);
}
finally
{
Monitor.Exit(serverclock);
} }
return true; return true;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!