Commit 9e1824ec 张东亮

在主线程加锁,io断开连接时心跳包不发送

1 个父辈 3190641f
...@@ -45,7 +45,18 @@ namespace OnlineStore.DeviceLibrary ...@@ -45,7 +45,18 @@ namespace OnlineStore.DeviceLibrary
protected abstract void CheckFixtureProcess(); protected abstract void CheckFixtureProcess();
protected override void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) protected override void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
TimerProcess(); if(Monitor.TryEnter(lockMainTimer))
{
try
{
TimerProcess();
}
finally
{
Monitor.Exit(lockMainTimer);
}
}
} }
public DateTime LastAlarmTime = DateTime.Now; public DateTime LastAlarmTime = DateTime.Now;
public override void Alarm(LineAlarmType alarmType) public override void Alarm(LineAlarmType alarmType)
......
...@@ -758,56 +758,64 @@ namespace OnlineStore.DeviceLibrary ...@@ -758,56 +758,64 @@ namespace OnlineStore.DeviceLibrary
/// </summary> /// </summary>
protected override void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) protected override void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
try if(Monitor.TryEnter(lockMainTimer))
{ {
DateTime time = DateTime.Now; try
if (runStatus.Equals(LineRunStatus.Wait))
{ {
//取新的Io状态 DateTime time = DateTime.Now;
IO_VALUE fuweiValue = IOValue(IO_Type.Reset_BTN); if (runStatus.Equals(LineRunStatus.Wait))
IO_VALUE lastFuwei = DILastValueMap[IO_Type.Reset_BTN];
addLastDI(IO_Type.Reset_BTN, fuweiValue);
bool isAutoStart = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun) == 1;
//收到复位信号后启动
if (isAutoStart && fuweiValue.Equals(IO_VALUE.HIGH) && lastFuwei.Equals(IO_VALUE.LOW))
{ {
//没有启动时收到启动按钮 //取新的Io状态
LogUtil.info( Name + "没有启动时收到启动按钮,开始调用启动方法!"); IO_VALUE fuweiValue = IOValue(IO_Type.Reset_BTN);
bool isOk = StartRun(); IO_VALUE lastFuwei = DILastValueMap[IO_Type.Reset_BTN];
if (!isOk) addLastDI(IO_Type.Reset_BTN, fuweiValue);
bool isAutoStart = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun) == 1;
//收到复位信号后启动
if (isAutoStart && fuweiValue.Equals(IO_VALUE.HIGH) && lastFuwei.Equals(IO_VALUE.LOW))
{ {
LogUtil.error("启动失败,等待下次启动"); //没有启动时收到启动按钮
mainTimer.Enabled = true; LogUtil.info(Name + "没有启动时收到启动按钮,开始调用启动方法!");
bool isOk = StartRun();
if (!isOk)
{
LogUtil.error("启动失败,等待下次启动");
mainTimer.Enabled = true;
}
} }
return;
} }
return; //判断急停
} else if (this.runStatus >= LineRunStatus.HomeMoving)
//判断急停
else if (this.runStatus >= LineRunStatus.HomeMoving)
{
foreach (EquipBase moveEquip in this.AllEquipMap.Values)
{ {
if (!moveEquip.IsDebug) foreach (EquipBase moveEquip in this.AllEquipMap.Values)
{ {
moveEquip.TimerProcess(); if (!moveEquip.IsDebug)
{
moveEquip.TimerProcess();
}
} }
LineTimerPro();
} }
LineTimerPro(); TimeSpan span = DateTime.Now - time;
if (span.TotalMilliseconds > 1000)
{
LogUtil.error(Name + "主定时器处理耗时:" + FormUtil.GetSpanStr(span));
}
} }
catch (Exception ex)
TimeSpan span = DateTime.Now - time;
if (span.TotalMilliseconds > 1000)
{ {
LogUtil.error(Name + "主定时器处理耗时:" + FormUtil.GetSpanStr(span)); LogUtil.error(Name + "主定时器出错:", ex);
} }
finally
{
Monitor.Exit(mainTimer);
}
Thread.Sleep(1);
} }
catch (Exception ex)
{
LogUtil.error(Name + "主定时器出错:",ex);
}
Thread.Sleep(1);
} }
private bool busyPro = false ; private bool busyPro = false ;
private DateTime busyProTime = DateTime.Now; private DateTime busyProTime = DateTime.Now;
......
...@@ -133,10 +133,12 @@ namespace Asa.IOModule ...@@ -133,10 +133,12 @@ namespace Asa.IOModule
tRecon = new Thread(new ThreadStart(Reconn)); tRecon = new Thread(new ThreadStart(Reconn));
tSend = new Thread(new ThreadStart(Send)); tSend = new Thread(new ThreadStart(Send));
tListen = new Thread(new ThreadStart(Listen)); tListen = new Thread(new ThreadStart(Listen));
tRecon.IsBackground=true;
tSend.IsBackground=true;
tListen.IsBackground=true;
tRecon.Start(); tRecon.Start();
tSend.Start(); tSend.Start();
tListen.Start(); tListen.Start();
log.Info(LogName+ "Connect");
} }
/// <summary> /// <summary>
...@@ -297,7 +299,7 @@ namespace Asa.IOModule ...@@ -297,7 +299,7 @@ namespace Asa.IOModule
log.Error(LogName + "WriteDO Fail : IsConn= " + IsConn); log.Error(LogName + "WriteDO Fail : IsConn= " + IsConn);
return false; return false;
} }
log.Info(LogName+ "call WriteDO"); log.Debug(LogName+ "WriteDO【"+$"{add}={sta}"+"】");
byte[] data = Command(); byte[] data = Command();
byte[] buff = new byte[12]; byte[] buff = new byte[12];
...@@ -311,8 +313,8 @@ namespace Asa.IOModule ...@@ -311,8 +313,8 @@ namespace Asa.IOModule
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LogName + "WriteDO ", ex); LogUtil.error(LogName + "WriteDO【" + $"{add}={sta}" + "】", ex);
log.Error(LogName+ "WriteDO ", ex); log.Error(LogName + "WriteDO【" + $"{add}={sta}" + "】",ex);
return false; return false;
} }
} }
...@@ -410,9 +412,12 @@ namespace Asa.IOModule ...@@ -410,9 +412,12 @@ namespace Asa.IOModule
{ {
try try
{ {
_client.Send(buff); if(IsConn)
log.Debug(LogName+ "Send: " + HexBuff(buff)); {
return true; _client.Send(buff);
log.Debug(LogName + "Send: " + HexBuff(buff));
return true;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -662,7 +667,7 @@ namespace Asa.IOModule ...@@ -662,7 +667,7 @@ namespace Asa.IOModule
buff = GetReadDO_Command(); buff = GetReadDO_Command();
SendToDevice(buff); SendToDevice(buff);
LogUtil.error(LogName+ "Socket Connect OK"); LogUtil.info(LogName+ "Socket Connect OK");
log.Info(LogName + "Socket Connect OK"); log.Info(LogName + "Socket Connect OK");
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -330,7 +330,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -330,7 +330,7 @@ namespace OnlineStore.DeviceLibrary
bool result = aioBox.WriteDO(StartAddress, GetBox_Sta(onOff)); bool result = aioBox.WriteDO(StartAddress, GetBox_Sta(onOff));
if (!result) if (!result)
{ {
LogUtil.error("AIO WriteSingleDO [" + ioIp + "] [" + StartAddress + "] 失败" ); LogUtil.error("AIO WriteSingleDO [" + ioIp + "] [" + StartAddress + "] 失败" );
} }
} }
else else
......
...@@ -250,7 +250,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -250,7 +250,7 @@ namespace OnlineStore.DeviceLibrary
/// 移动信息 /// 移动信息
/// </summary> /// </summary>
public LineMoveInfo MoveInfo = null; public LineMoveInfo MoveInfo = null;
protected object lockMainTimer = new object();
/// <summary> /// <summary>
/// 定时处理,监听信号,监听IO /// 定时处理,监听信号,监听IO
/// </summary> /// </summary>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!