Commit 5d9fc6fe LN

修改与服务器通信代码

1 个父辈 386b9dc2
......@@ -17,7 +17,7 @@ using System.Net.NetworkInformation;
namespace OnlineStore.Common
{
public class HttpHelper
{
{
public static string PostAndWait(string url, string paramData)
{
string postRes = "";
......@@ -95,7 +95,17 @@ namespace OnlineStore.Common
{
try
{
return JsonHelper.DeserializeJsonToObject<Operation>(result);
Operation resultOP = JsonHelper.DeserializeJsonToObject<Operation>(result);
if (resultOP != null && (!operation.seq.Equals(resultOP.seq)))
{
LogUtil.error(" seq error : send 【" + json + "】 " + ",receive 【 " + result + "】");
}
if (resultOP != null && (!operation.cid.Equals(resultOP.cid)))
{
LogUtil.error(" cid error : send 【" + json + "】 " + ",receive 【 " + result + "】,return null");
return null;
}
return resultOP;
}
catch (Exception ex)
{
......
......@@ -499,14 +499,12 @@ namespace OnlineStore.DeviceLibrary
lastConTime = DateTime.Now;
try
{
//HumitureController.QueryData();
humBean.HumidityProcess(this);
if (StoreManager.IsConnectServer)
{
SendLineStatus();
}
////HumitureController.QueryData();
//humBean.HumidityProcess(this);
//if (StoreManager.IsConnectServer)
//{
// SendLineStatus();
//}
}
catch (Exception ex)
{
......
......@@ -22,8 +22,9 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 灯闪烁定时器
/// </summary>
private System.Timers.Timer ledProcessTimer = null;
private System.Timers.Timer ledProcessTimer = null;
private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
public Dictionary<int, AC_BOX_Config> BoxConfigMap { get; set; }
public Dictionary<int, AC_BOX_Bean> BoxMap = new Dictionary<int, AC_BOX_Bean>();
......@@ -86,6 +87,7 @@ namespace OnlineStore.DeviceLibrary
mainTimer.Enabled = true;
canStart = true;
serverConnectTimer.Enabled = true;
//连接AGV调度
AgvClient.Init();
});
......@@ -107,7 +109,13 @@ namespace OnlineStore.DeviceLibrary
ledProcessTimer.Interval = 1000;
ledProcessTimer.Elapsed += LedProcess;
ledProcessTimer.AutoReset = true;
ledProcessTimer.Enabled = false;
ledProcessTimer.Enabled = false;
serverConnectTimer = new System.Timers.Timer();
serverConnectTimer.Interval = 1000;
serverConnectTimer.AutoReset = true;
serverConnectTimer.Enabled = false;
serverConnectTimer.Elapsed += server_connect_timer_Tick;
}
private void IoCheckTimerProcess(object sender, ElapsedEventArgs e)
......@@ -155,6 +163,7 @@ namespace OnlineStore.DeviceLibrary
box.StartRun();
}
serverConnectTimer.Enabled = true;
ledProcessTimer.Enabled = true;
mainTimer.Enabled = true;
return true;
......@@ -449,5 +458,65 @@ namespace OnlineStore.DeviceLibrary
}
#endregion
#region 与服务器通信
private bool isInProcess = false;
private DateTime lastConTime = DateTime.Now;
public void server_connect_timer_Tick(object sender, EventArgs e)
{
if (isInProcess)
{
TimeSpan span = DateTime.Now - lastConTime;
if (span.TotalSeconds < 10)
{
return;
}
else
{
LogUtil.error($"{Name}server_connect_timer_Tick 已耗时{span.TotalSeconds}秒,重新处理");
}
}
isInProcess = true;
lastConTime = DateTime.Now;
try
{
foreach (AC_BOX_Bean box in BoxMap.Values)
{
if (box.storeRunStatus.Equals(StoreRunStatus.Wait))
{
continue;
}
if ((!box.IsDebug) && StoreManager.IsConnectServer)
{
try
{
box.SendLineStatus();
}
catch (Exception ex)
{
LogUtil.error(Name + "定时给服务器发送消息出错:" + ex.ToString());
}
}
box.humBean.HumidityProcess(box);
}
}
catch (Exception ex)
{
LogUtil.error(Name + "server_connect_timer_Tick出错:" + ex.ToString());
}
finally
{
isInProcess = false;
}
}
#endregion
}
}
\ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!