Commit 0aff9dd7 张东亮

timer改为线程

1 个父辈 7290c4f8
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
<Reference Include="CodeLibrary"> <Reference Include="CodeLibrary">
<HintPath>..\..\dll\CodeLibrary.dll</HintPath> <HintPath>..\..\dll\CodeLibrary.dll</HintPath>
</Reference> </Reference>
<Reference Include="ConfigHelper">
<HintPath>..\..\..\..\..\..\SharedRefDll\Neotel\ConfigHelper\Debug\net461\ConfigHelper.dll</HintPath>
</Reference>
<Reference Include="halcondotnet"> <Reference Include="halcondotnet">
<HintPath>..\..\dll\halcondotnet.dll</HintPath> <HintPath>..\..\dll\halcondotnet.dll</HintPath>
</Reference> </Reference>
......
...@@ -45,7 +45,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -45,7 +45,8 @@ namespace OnlineStore.DeviceLibrary
RFIDIP = RFIDManager.GetRFIP(DeviceID); RFIDIP = RFIDManager.GetRFIP(DeviceID);
HasOutLine = config.DOList.ContainsKey(IO_Type.SL_OutLine_Run); HasOutLine = config.DOList.ContainsKey(IO_Type.SL_OutLine_Run);
addLastDI(IO_Type.SL_Reset_BTN, IO_VALUE.LOW); addLastDI(IO_Type.SL_Reset_BTN, IO_VALUE.LOW);
mainTimer.Enabled = true; //mainTimer.Enabled = true;
mainStart();
} }
public override bool StartRun(bool isDebug = false) public override bool StartRun(bool isDebug = false)
...@@ -68,7 +69,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -68,7 +69,8 @@ namespace OnlineStore.DeviceLibrary
} }
if (RunAxis(true, BatchAxis) && RunAxis(true, UpdownAxis)) if (RunAxis(true, BatchAxis) && RunAxis(true, UpdownAxis))
{ {
mainTimer.Enabled = false; //mainTimer.Enabled = false;
mainStop();
MoveInfo.EndMove(); MoveInfo.EndMove();
SecondMoveInfo.EndMove(); SecondMoveInfo.EndMove();
runStatus = LineRunStatus.HomeMoving; runStatus = LineRunStatus.HomeMoving;
...@@ -81,7 +83,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -81,7 +83,8 @@ namespace OnlineStore.DeviceLibrary
if (isDebug) if (isDebug)
{ {
LogInfo("开始调试,启动定时器 "); LogInfo("开始调试,启动定时器 ");
mainTimer.Start(); //mainTimer.Start();
mainStart();
} }
return true; return true;
} }
...@@ -335,10 +338,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -335,10 +338,11 @@ namespace OnlineStore.DeviceLibrary
public override void StopRun() public override void StopRun()
{ {
runStatus = LineRunStatus.Wait; runStatus = LineRunStatus.Wait;
if (mainTimer != null) //if (mainTimer != null)
{ //{
mainTimer.Enabled = false; // mainTimer.Enabled = false;
} //}
mainStop();
StopMove(); StopMove();
CloseLed(); CloseLed();
AgvClient.SetStatus(Config.AgvInName, "", ClientAction.None, ClientLevel.Low, true); AgvClient.SetStatus(Config.AgvInName, "", ClientAction.None, ClientLevel.Low, true);
...@@ -364,7 +368,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -364,7 +368,8 @@ namespace OnlineStore.DeviceLibrary
if (!isOk) if (!isOk)
{ {
LogUtil.error("启动失败,等待下次启动"); LogUtil.error("启动失败,等待下次启动");
mainTimer.Enabled = true; // mainTimer.Enabled = true;
mainStart();
} }
} }
return; return;
......
...@@ -28,14 +28,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -28,14 +28,16 @@ namespace OnlineStore.DeviceLibrary
{ {
return false; return false;
} }
mainTimer.Enabled = false; //mainTimer.Enabled = false;
mainStop();
MoveInfo.EndMove(); MoveInfo.EndMove();
runStatus = LineRunStatus.HomeMoving; runStatus = LineRunStatus.HomeMoving;
MoveInfo.NewMove(LineMoveType.RHome); MoveInfo.NewMove(LineMoveType.RHome);
StartReset(); StartReset();
if (isDebug) if (isDebug)
{ {
mainTimer.Enabled = true; //mainTimer.Enabled = true;
mainStart();
} }
return true; return true;
} }
...@@ -132,10 +134,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -132,10 +134,11 @@ namespace OnlineStore.DeviceLibrary
public override void StopRun() public override void StopRun()
{ {
if (mainTimer != null) //if (mainTimer != null)
{ //{
mainTimer.Enabled = false; // mainTimer.Enabled = false;
} //}
mainStop();
StopMove(); StopMove();
runStatus = LineRunStatus.Wait; runStatus = LineRunStatus.Wait;
......
...@@ -27,16 +27,18 @@ namespace OnlineStore.DeviceLibrary ...@@ -27,16 +27,18 @@ namespace OnlineStore.DeviceLibrary
if (CanStartRun().Equals(false)) if (CanStartRun().Equals(false))
{ {
return false; return false;
} }
mainTimer.Enabled = false; //mainTimer.Enabled = false;
mainStop();
MoveInfo.EndMove(); MoveInfo.EndMove();
runStatus = LineRunStatus.HomeMoving; runStatus = LineRunStatus.HomeMoving;
MoveInfo.NewMove(LineMoveType.RHome); MoveInfo.NewMove(LineMoveType.RHome);
StartReset(); StartReset();
if (isDebug) if (isDebug)
{ {
mainTimer.Enabled = true; //mainTimer.Enabled = true;
mainStart();
} }
return true; return true;
} }
...@@ -126,10 +128,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -126,10 +128,11 @@ namespace OnlineStore.DeviceLibrary
public override void StopRun() public override void StopRun()
{ {
if (mainTimer != null) //if (mainTimer != null)
{ //{
mainTimer.Enabled = false; // mainTimer.Enabled = false;
} //}
mainStop();
StopMove(); StopMove();
runStatus = LineRunStatus.Wait; runStatus = LineRunStatus.Wait;
......
...@@ -43,16 +43,18 @@ namespace OnlineStore.DeviceLibrary ...@@ -43,16 +43,18 @@ namespace OnlineStore.DeviceLibrary
{ {
return false; return false;
} }
mainTimer.Enabled = false; // mainTimer.Enabled = false;
mainStop();
MoveInfo.EndMove(); MoveInfo.EndMove();
runStatus = LineRunStatus.HomeMoving; runStatus = LineRunStatus.HomeMoving;
MoveInfo.NewMove(LineMoveType.RHome); MoveInfo.NewMove(LineMoveType.RHome);
StartReset(); StartReset();
if (isDebug) if (isDebug)
{ {
mainTimer.Interval = 300; //mainTimer.Interval = 300;
mainTimer.Enabled = true; //mainTimer.Enabled = true;
LogInfo("StartRun 设置 Interval=180 ,启动定时器"); mainStart();
LogInfo("StartRun 设置 Interval=300,启动定时器");
} }
return true; return true;
} }
...@@ -120,12 +122,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -120,12 +122,15 @@ namespace OnlineStore.DeviceLibrary
} }
else if (MoveInfo.IsStep(LineMoveStep.JHY_R05_ClampCheck)) else if (MoveInfo.IsStep(LineMoveStep.JHY_R05_ClampCheck))
{ {
if (!mainTimer.Enabled) if (!IsMainStarted)
{ {
mainTimer.Enabled = true; //mainTimer.Enabled = true;
mainStart();
SetInterval(180);
LogInfo("复位完成 设置 mainTimer.Enabled = true "); LogInfo("复位完成 设置 mainTimer.Enabled = true ");
} }
mainTimer.Interval = 180; //mainTimer.Interval = 180;
SetInterval(180);
LogInfo("复位完成 设置 Interval=180 "); LogInfo("复位完成 设置 Interval=180 ");
LogInfo(MoveInfo.MoveType + " 完成!"); LogInfo(MoveInfo.MoveType + " 完成!");
MoveEndS(); MoveEndS();
...@@ -154,10 +159,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -154,10 +159,11 @@ namespace OnlineStore.DeviceLibrary
} }
public override void StopRun() public override void StopRun()
{ {
if (mainTimer != null) //if (mainTimer != null)
{ //{
mainTimer.Enabled = false; // mainTimer.Enabled = false;
} //}
mainStop();
StopMove(); StopMove();
//CheckAndMove(IO_Type.HY_ClampCylinder_Work, IO_VALUE.LOW); //CheckAndMove(IO_Type.HY_ClampCylinder_Work, IO_VALUE.LOW);
//CheckAndMove(IO_Type.HY_ClampCylinder_Relax, IO_VALUE.LOW); //CheckAndMove(IO_Type.HY_ClampCylinder_Relax, IO_VALUE.LOW);
......
...@@ -93,8 +93,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -93,8 +93,8 @@ namespace OnlineStore.DeviceLibrary
//CheckStopWatch(trayCheckWait, TrayWaitTime, false) && //CheckStopWatch(trayCheckWait, TrayWaitTime, false) &&
if (check2IsOk && canpro) if (check2IsOk && canpro)
{ {
StartTrayCheck(); //StartTrayCheck();
Start_JHY_05_TrayCheck();
} }
} }
// else // else
...@@ -191,9 +191,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -191,9 +191,8 @@ namespace OnlineStore.DeviceLibrary
SecondMoveInfo.NewMove(LineMoveType.Fixture); SecondMoveInfo.NewMove(LineMoveType.Fixture);
SecondMoveInfo.NextMoveStep(LineMoveStep.JHY_05_TrayCheck); SecondMoveInfo.NextMoveStep(LineMoveStep.JHY_05_TrayCheck);
CheckLog("接驳台托盘" + SecondMoveInfo.SLog + "前阻挡下降1.2s,等待托盘到位 "); CheckLog("接驳台托盘" + SecondMoveInfo.SLog + "前阻挡上升,等待托盘到位 ");
//IOMove(IO_Type.HY_FrontStopDown, IO_VALUE.LOW); IOMove(IO_Type.HY_FrontStopDown, IO_VALUE.LOW);
IOMove(IO_Type.HY_FrontStopDown, IO_VALUE.HIGH, 1200);
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.HY_FrontStopDown, IO_VALUE.LOW)); SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.HY_FrontStopDown, IO_VALUE.LOW));
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.HY_TrayCheck, IO_VALUE.HIGH)); SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.HY_TrayCheck, IO_VALUE.HIGH));
......
...@@ -24,14 +24,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -24,14 +24,16 @@ namespace OnlineStore.DeviceLibrary
{ {
return false; return false;
} }
mainTimer.Enabled = false; //mainTimer.Enabled = false;
mainStop();
MoveInfo.EndMove(); MoveInfo.EndMove();
runStatus = LineRunStatus.HomeMoving; runStatus = LineRunStatus.HomeMoving;
MoveInfo.NewMove(LineMoveType.RHome); MoveInfo.NewMove(LineMoveType.RHome);
StartReset(); StartReset();
if (isDebug) if (isDebug)
{ {
mainTimer.Enabled = true; //mainTimer.Enabled = true;
mainStart();
} }
return true; return true;
} }
...@@ -95,10 +97,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -95,10 +97,11 @@ namespace OnlineStore.DeviceLibrary
public override void StopRun() public override void StopRun()
{ {
if (mainTimer != null) //if (mainTimer != null)
{ //{
mainTimer.Enabled = false; // mainTimer.Enabled = false;
} //}
mainStop();
StopMove(); StopMove();
runStatus = LineRunStatus.Wait; runStatus = LineRunStatus.Wait;
......
...@@ -70,7 +70,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -70,7 +70,8 @@ namespace OnlineStore.DeviceLibrary
return false; return false;
} }
mainTimer.Enabled = false; //mainTimer.Enabled = false;
mainStop();
MoveInfo.EndMove(); MoveInfo.EndMove();
SecondMoveInfo.EndMove(); SecondMoveInfo.EndMove();
runStatus = LineRunStatus.HomeMoving; runStatus = LineRunStatus.HomeMoving;
...@@ -79,7 +80,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -79,7 +80,8 @@ namespace OnlineStore.DeviceLibrary
StartReset(); StartReset();
if (isDebug) if (isDebug)
{ {
mainTimer.Enabled = true; // mainTimer.Enabled = true;
mainStart();
} }
return true; return true;
} }
...@@ -205,10 +207,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -205,10 +207,11 @@ namespace OnlineStore.DeviceLibrary
public override void StopRun() public override void StopRun()
{ {
if (mainTimer != null) //if (mainTimer != null)
{ //{
mainTimer.Enabled = false; // mainTimer.Enabled = false;
} //}
mainStop();
StopMove(); StopMove();
//停止运行时,把所有IO 置零 //停止运行时,把所有IO 置零
//CheckAndMove(IO_Type.StopDown1, IO_VALUE.LOW); //CheckAndMove(IO_Type.StopDown1, IO_VALUE.LOW);
......
using log4net; using log4net;
using OnlineStore.Common; using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
using System; using System;
...@@ -24,11 +24,30 @@ namespace OnlineStore.DeviceLibrary ...@@ -24,11 +24,30 @@ namespace OnlineStore.DeviceLibrary
public int DeviceID { get; set; } public int DeviceID { get; set; }
protected System.Timers.Timer mainTimer; protected System.Timers.Timer mainTimer;
protected Thread mainThread;
protected bool loop;
protected bool pause = false;
protected int threadInterval = 300;
private bool isInit = false; private bool isInit = false;
/// <summary>
public bool mainTimerStart { get => mainTimer.Enabled; } /// 使用timer定时器
/// </summary>
protected bool useTimer = ConfigHelper.Config.Get("Device_MainThreadUseTimer", true);
public bool IsMainStarted
{
get
{
if (useTimer)
{
return mainTimer.Enabled;
}
else
{
return !pause;
}
}
}
//public bool mainTimerStart { get => mainTimer.Enabled; }
/// <summary> /// <summary>
/// 托盘检测信号需要持续时间 /// 托盘检测信号需要持续时间
...@@ -37,6 +56,62 @@ namespace OnlineStore.DeviceLibrary ...@@ -37,6 +56,62 @@ namespace OnlineStore.DeviceLibrary
public KTK_Store() public KTK_Store()
{ {
} }
~KTK_Store()
{
if (useTimer)
{
}
else
{
loop = false;
}
}
/// <summary>
/// 主进程启动
/// </summary>
public void mainStart()
{
if (useTimer)
{
if (mainTimer != null)
{
mainTimer.Start();
}
}
else
{
// pause = false;
}
}
public void SetInterval(int interval = 300)
{
if (useTimer)
{
if (mainTimer != null)
{
mainTimer.Interval = interval;
}
}
else
{
threadInterval = interval;
}
}
/// <summary>
/// 主进程停止
/// </summary>
public void mainStop()
{
if (useTimer)
{
mainTimer?.Stop();
}
else
{
//pause = true;
}
}
/// <summary> /// <summary>
/// 开始运行的时间 /// 开始运行的时间
/// </summary> /// </summary>
...@@ -203,18 +278,60 @@ namespace OnlineStore.DeviceLibrary ...@@ -203,18 +278,60 @@ namespace OnlineStore.DeviceLibrary
{ {
if (!isInit) if (!isInit)
{ {
mainTimer = new System.Timers.Timer(); if (useTimer)
mainTimer.Enabled = false; {
mainTimer.Interval = 300; mainTimer = new System.Timers.Timer();
mainTimer.Elapsed += mainTimer_Elapsed; mainTimer.Enabled = false;
mainTimer.AutoReset = true; mainTimer.Interval = 300;
mainTimer.Elapsed += mainTimer_Elapsed;
mainTimer.AutoReset = true;
}
else
{
mainThread = new Thread(mainThread_Handle);
mainThread.IsBackground = true;
threadInterval = 300;
loop = true;
GC.KeepAlive(mainThread);
mainThread.Start();
}
isInit = true; isInit = true;
} }
} }
public LineMoveInfo MoveInfo = null; public LineMoveInfo MoveInfo = null;
string threadInfo = "";
void mainThread_Handle()
{
while (loop)
{
if (pause)
{
Thread.Sleep(1000);
}
else
{
mainThread_Process();
Thread.Sleep(threadInterval);
try
{
string curStr = $"{Name}-{DeviceID}:Thread ID: {Thread.CurrentThread.ManagedThreadId}";
if (!curStr.Equals(threadInfo))
{
threadInfo = curStr;
LogUtil.LOGGER.Info(curStr);
}
}
finally { }
protected abstract void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e); }
}
}
protected abstract void mainThread_Process();
void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
mainThread_Process();
}
#region 出库 #region 出库
/// <summary> /// <summary>
...@@ -642,7 +759,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -642,7 +759,8 @@ namespace OnlineStore.DeviceLibrary
warnParam.OperteType = ""; warnParam.OperteType = "";
} }
} }
}catch(Exception ex) }
catch (Exception ex)
{ {
LogUtil.error("SetWarnMsg Error: " + ex.ToString()); LogUtil.error("SetWarnMsg Error: " + ex.ToString());
} }
...@@ -654,9 +772,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -654,9 +772,9 @@ namespace OnlineStore.DeviceLibrary
try try
{ {
SetWarnMsg(move.Name + "[" + move.GetMoveType() + "][" + move.SLog + "] " + alarmType + " [" + FormUtil.GetSpanStr(move.StepSpan()) + "]", alarmType, move); SetWarnMsg(move.Name + "[" + move.GetMoveType() + "][" + move.SLog + "] " + alarmType + " [" + FormUtil.GetSpanStr(move.StepSpan()) + "]", alarmType, move);
Alarm(LineAlarmType.IoSingleTimeOut); Alarm(LineAlarmType.IoSingleTimeOut);
} }
catch(Exception ex) catch (Exception ex)
{ {
} }
...@@ -689,7 +807,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -689,7 +807,7 @@ namespace OnlineStore.DeviceLibrary
string alarmTypeStr = stepDes + "_超时报警"; string alarmTypeStr = stepDes + "_超时报警";
if (warnParam.AlarmType.Equals(alarmTypeStr)) if (warnParam.AlarmType.Equals(alarmTypeStr))
{ {
LogUtil.info(Name + $"步骤{stepDes}结束,清理【{ WarnMsg }】 "); LogUtil.info(Name + $"步骤{stepDes}结束,清理【{WarnMsg}】 ");
alarmType = LineAlarmType.None; alarmType = LineAlarmType.None;
SetWarnMsg(""); SetWarnMsg("");
} }
...@@ -699,7 +817,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -699,7 +817,7 @@ namespace OnlineStore.DeviceLibrary
string alarmTypeStr = stepDes + "_轴运动报警"; string alarmTypeStr = stepDes + "_轴运动报警";
if (warnParam.AlarmType.Equals(alarmTypeStr)) if (warnParam.AlarmType.Equals(alarmTypeStr))
{ {
LogUtil.info(Name + $"步骤{stepDes}结束,清理【{ WarnMsg }】 "); LogUtil.info(Name + $"步骤{stepDes}结束,清理【{WarnMsg}】 ");
alarmType = LineAlarmType.None; alarmType = LineAlarmType.None;
SetWarnMsg(""); SetWarnMsg("");
} }
...@@ -732,4 +850,4 @@ namespace OnlineStore.DeviceLibrary ...@@ -732,4 +850,4 @@ namespace OnlineStore.DeviceLibrary
public string Barcode = ""; public string Barcode = "";
} }
} }
...@@ -116,7 +116,7 @@ namespace HuichuanLibrary ...@@ -116,7 +116,7 @@ namespace HuichuanLibrary
} }
else else
{ {
LOGGER.Debug("ShowLogPro【" + msg + "】失败,未得到锁"); //LOGGER.Debug("ShowLogPro【" + msg + "】失败,未得到锁");
} }
} }
private static List<string> logList = new List<string>(); private static List<string> logList = new List<string>();
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!