Commit 9e1824ec 张东亮

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

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