Commit 9e1824ec 张东亮

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

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