Commit 9e1824ec 张东亮

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

1 个父辈 3190641f
...@@ -45,8 +45,19 @@ namespace OnlineStore.DeviceLibrary ...@@ -45,8 +45,19 @@ 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)
{ {
if(Monitor.TryEnter(lockMainTimer))
{
try
{
TimerProcess(); 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,6 +758,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -758,6 +758,8 @@ 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)
{ {
if(Monitor.TryEnter(lockMainTimer))
{
try try
{ {
DateTime time = DateTime.Now; DateTime time = DateTime.Now;
...@@ -773,7 +775,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -773,7 +775,7 @@ namespace OnlineStore.DeviceLibrary
if (isAutoStart && fuweiValue.Equals(IO_VALUE.HIGH) && lastFuwei.Equals(IO_VALUE.LOW)) if (isAutoStart && fuweiValue.Equals(IO_VALUE.HIGH) && lastFuwei.Equals(IO_VALUE.LOW))
{ {
//没有启动时收到启动按钮 //没有启动时收到启动按钮
LogUtil.info( Name + "没有启动时收到启动按钮,开始调用启动方法!"); LogUtil.info(Name + "没有启动时收到启动按钮,开始调用启动方法!");
bool isOk = StartRun(); bool isOk = StartRun();
if (!isOk) if (!isOk)
{ {
...@@ -805,10 +807,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -805,10 +807,16 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(Name + "主定时器出错:",ex); LogUtil.error(Name + "主定时器出错:", ex);
}
finally
{
Monitor.Exit(mainTimer);
} }
Thread.Sleep(1); Thread.Sleep(1);
} }
}
private bool busyPro = false ; private bool busyPro = false ;
private DateTime busyProTime = DateTime.Now; private DateTime busyProTime = DateTime.Now;
private int maxSeconds = 3; private int maxSeconds = 3;
......
...@@ -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,10 +412,13 @@ namespace Asa.IOModule ...@@ -410,10 +412,13 @@ namespace Asa.IOModule
{ {
try try
{ {
if(IsConn)
{
_client.Send(buff); _client.Send(buff);
log.Debug(LogName+ "Send: " + HexBuff(buff)); log.Debug(LogName + "Send: " + HexBuff(buff));
return true; return true;
} }
}
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LogName + "Send Error Socket Close", ex); LogUtil.error(LogName + "Send Error Socket Close", 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!