Commit 40e0cf04 LN

修改服务器通信代码

1 个父辈 cc75828e
...@@ -19,6 +19,17 @@ namespace OnlineStore.Common ...@@ -19,6 +19,17 @@ namespace OnlineStore.Common
{ {
public class HttpHelper public class HttpHelper
{ {
private static int seq = 1;
public static int nextSeq()
{
if (seq.Equals(Int32.MaxValue))
{
LogUtil.info("seq当前值:" + seq + ",重置seq=0");
seq = 0;
}
Interlocked.Increment(ref seq);
return seq;
}
public static string LastSend = ""; public static string LastSend = "";
public static string LastRevice = ""; public static string LastRevice = "";
...@@ -36,7 +47,17 @@ namespace OnlineStore.Common ...@@ -36,7 +47,17 @@ namespace OnlineStore.Common
string result = PostJson(url, json, Encoding.UTF8, out isTimeOut); string result = PostJson(url, json, Encoding.UTF8, out isTimeOut);
if (!string.IsNullOrEmpty(result)) if (!string.IsNullOrEmpty(result))
{ {
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) catch (Exception ex)
......
...@@ -36,6 +36,6 @@ PRO,0,是否调试状态,ISDebug,0,,,,,,,,,,,, ...@@ -36,6 +36,6 @@ PRO,0,是否调试状态,ISDebug,0,,,,,,,,,,,,
PRO,,每次吹气的时间(分钟),BlowAir_Time,10,,,,,,,,,,,, PRO,,每次吹气的时间(分钟),BlowAir_Time,10,,,,,,,,,,,,
PRO,,两次吹气间隔(分钟),BlowAir_Interval,10,,, ,,,,,,,,, PRO,,两次吹气间隔(分钟),BlowAir_Interval,10,,, ,,,,,,,,,
PRO,,温湿度端口号,Humiture_Port,COM5,,,,,,,,,,,, PRO,,温湿度端口号,Humiture_Port,COM5,,,,,,,,,,,,
PRO,,仓门口相机名称,Camera_Name,monitor,,,,,,,,,,,, PRO,,仓门口相机名称,Camera_Name,,,,,,,,,,,,,
PRO,,拍照相机名称,PhotoCamera_Name,monitor,,,,,,,,,,,, PRO,,拍照相机名称,PhotoCamera_Name,,,,,,,,,,,,,
PRO,0,压紧轴(轴4)P2压紧点列表,CompAxis_P2_List,8=385001;,,,,,,,,,,,, PRO,0,压紧轴(轴4)P2压紧点列表,CompAxis_P2_List,8=385001;,,,,,,,,,,,,
...@@ -1229,22 +1229,22 @@ namespace OnlineStore.DeviceLibrary ...@@ -1229,22 +1229,22 @@ namespace OnlineStore.DeviceLibrary
StoreSendBean store = lineConnect.GetBean((int)ss, (int)storeRunStatus, hasTray, (int)alarmType); StoreSendBean store = lineConnect.GetBean((int)ss, (int)storeRunStatus, hasTray, (int)alarmType);
lineConnect.SendHeart(store); lineConnect.SendHeart(store);
} }
if (StoreManager.IsConnectServer) //if (StoreManager.IsConnectServer)
{ //{
try // try
{ // {
SendLineStatus(); // SendLineStatus();
} // }
catch (Exception ex) // catch (Exception ex)
{ // {
LogUtil.error(Name + "定时给服务器发送消息出错:" + ex.ToString()); // LogUtil.error(Name + "定时给服务器发送消息出错:" + ex.ToString());
} // }
} //}
}
if (StoreManager.Store.UseTemp)
{
humBean.HumidityProcess(this);
} }
//if (StoreManager.Store.UseTemp)
//{
// humBean.HumidityProcess(this);
//}
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -1255,17 +1255,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1255,17 +1255,7 @@ namespace OnlineStore.DeviceLibrary
isInProcess = false; isInProcess = false;
} }
} }
private int seq = 1;
public int nextSeq()
{
if (seq.Equals(Int32.MaxValue))
{
LogUtil.info("seq当前值:" + seq + ",重置seq=0");
seq = 0;
}
Interlocked.Increment(ref seq);
return seq;
}
public Operation getLineBoxStatus() public Operation getLineBoxStatus()
{ {
//构建发送给服务器的对象 //构建发送给服务器的对象
...@@ -1273,7 +1263,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1273,7 +1263,7 @@ namespace OnlineStore.DeviceLibrary
lineOperation.msg = ""; lineOperation.msg = "";
lineOperation.alarmList = new List<AlarmInfo>(); lineOperation.alarmList = new List<AlarmInfo>();
lineOperation.cid = CID; lineOperation.cid = CID;
lineOperation.seq = nextSeq(); lineOperation.seq = HttpHelper.nextSeq();
lineOperation.status = 1; lineOperation.status = 1;
if (WarnMsg != "") if (WarnMsg != "")
{ {
...@@ -1371,6 +1361,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -1371,6 +1361,11 @@ namespace OnlineStore.DeviceLibrary
//发送状态信息到服务器 //发送状态信息到服务器
if (resultOperation == null || (resultOperation.op <= 0)) if (resultOperation == null || (resultOperation.op <= 0))
{ {
TimeSpan span1 = DateTime.Now - time;
if (span1.TotalMilliseconds > 100)
{
LogInfo("执行 SendLineStatus PostOP 共【" + span1.TotalMilliseconds + "】毫秒");
}
//判断服务端是否返回出库操作 //判断服务端是否返回出库操作
return; return;
} }
......
...@@ -21,6 +21,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -21,6 +21,7 @@ namespace OnlineStore.DeviceLibrary
public Asa.Camera.VisionLib vision; public Asa.Camera.VisionLib vision;
private System.Timers.Timer ledProcessTimer = null; private System.Timers.Timer ledProcessTimer = null;
private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
public Dictionary<int, BoxConfig> BoxConfigMap { get; set; } public Dictionary<int, BoxConfig> BoxConfigMap { get; set; }
public Dictionary<int, BoxBean> BoxMap = new Dictionary<int, BoxBean>(); public Dictionary<int, BoxBean> BoxMap = new Dictionary<int, BoxBean>();
public bool UseBuzzer = true; public bool UseBuzzer = true;
...@@ -75,6 +76,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -75,6 +76,7 @@ namespace OnlineStore.DeviceLibrary
ledProcessTimer.Enabled = true; ledProcessTimer.Enabled = true;
InitVisionLib(); InitVisionLib();
canStart = true; canStart = true;
serverConnectTimer.Enabled = true;
}); });
} }
...@@ -85,10 +87,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -85,10 +87,12 @@ namespace OnlineStore.DeviceLibrary
ledProcessTimer.Elapsed += LedProcess; ledProcessTimer.Elapsed += LedProcess;
ledProcessTimer.AutoReset = true; ledProcessTimer.AutoReset = true;
ledProcessTimer.Enabled = false; ledProcessTimer.Enabled = false;
}
private void IoCheckTimerProcess(object sender, ElapsedEventArgs e) serverConnectTimer = new System.Timers.Timer();
{ serverConnectTimer.Interval = 1000;
serverConnectTimer.AutoReset = true;
serverConnectTimer.Enabled = false;
serverConnectTimer.Elapsed += server_connect_timer_Tick;
} }
#endregion #endregion
...@@ -128,7 +132,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -128,7 +132,7 @@ namespace OnlineStore.DeviceLibrary
{ {
box.StartRun(); box.StartRun();
} }
serverConnectTimer.Enabled = true;
ledProcessTimer.Enabled = true; ledProcessTimer.Enabled = true;
mainTimer.Enabled = true; mainTimer.Enabled = true;
return true; return true;
...@@ -387,8 +391,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -387,8 +391,6 @@ namespace OnlineStore.DeviceLibrary
} }
public override void StopMove() public override void StopMove()
{ {
foreach (BoxBean equip in this.BoxMap.Values) foreach (BoxBean equip in this.BoxMap.Values)
...@@ -431,9 +433,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -431,9 +433,6 @@ namespace OnlineStore.DeviceLibrary
} }
} }
public override void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType storeMoveType) public override void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType storeMoveType)
{ {
...@@ -460,5 +459,65 @@ namespace OnlineStore.DeviceLibrary ...@@ -460,5 +459,65 @@ namespace OnlineStore.DeviceLibrary
#endregion #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 (BoxBean 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());
}
}
if (StoreManager.Store.UseTemp)
{
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 \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!