You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
261 lines
11 KiB
C#
261 lines
11 KiB
C#
using Rs.Framework;
|
|
using Rs.Motion;
|
|
using Rs.MotionPlat.Commom;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Rs.MotionPlat.Flow
|
|
{
|
|
public enum EMonitorButtonStep
|
|
{
|
|
Monitoring,//监控中
|
|
EStopButtonPressed,//急停按钮按下
|
|
EStopButtonUp,//急停按钮抬起
|
|
StartButtonPressed,//启动按钮按下
|
|
StartButtonUp,//启动按钮抬起
|
|
ResetButtonPressed,//复位按钮按下
|
|
ResetButtonUp,//复位按钮抬起
|
|
StopButtonPressed,//停止按钮按下
|
|
StopButtonUp,//停止按钮抬起,
|
|
DoorOpend,//门被打开,
|
|
LightButtonPressed,//照明被按下
|
|
LightButtonUp//照明被抬起
|
|
}
|
|
|
|
public enum ESystemButton
|
|
{
|
|
None,
|
|
EStopPressed=1,
|
|
StartPressed = 2,
|
|
StopPressed = 4,
|
|
ResetPressed = 8,
|
|
EStopUp = 16,
|
|
StartUp = 32,
|
|
StopUp= 64,
|
|
ResetUp = 128
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 系统按钮监控
|
|
/// </summary>
|
|
public class MonitorSystemButton:BaseFlow
|
|
{
|
|
private ESystemButton buttonValue = ESystemButton.None;
|
|
EMonitorButtonStep step = EMonitorButtonStep.Monitoring;
|
|
private static MonitorSystemButton instance;
|
|
private short signalValue = 0;
|
|
public static MonitorSystemButton Instance
|
|
{
|
|
get
|
|
{
|
|
if(instance==null)
|
|
{
|
|
instance = new MonitorSystemButton();
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
public void ButtonPressed(ESystemButton button)
|
|
{
|
|
buttonValue=button;
|
|
}
|
|
|
|
private MonitorSystemButton() {
|
|
sleepTime = 50;
|
|
stopWaitTime = 100;
|
|
FlowName = "系统按钮监控";
|
|
}
|
|
|
|
/*
|
|
|
|
0010
|
|
0001 & 0001
|
|
0010 &
|
|
*/
|
|
public override void Run()
|
|
{
|
|
switch (step)
|
|
{
|
|
case EMonitorButtonStep.Monitoring:
|
|
signalValue = IoManager.Instance.ReadIn("前急停");
|
|
if(signalValue==0 || (buttonValue == ESystemButton.EStopPressed))
|
|
{
|
|
step = EMonitorButtonStep.EStopButtonPressed;
|
|
break;
|
|
}
|
|
signalValue = IoManager.Instance.ReadIn("后急停");
|
|
if (signalValue == 0 || (buttonValue == ESystemButton.EStopPressed))
|
|
{
|
|
step = EMonitorButtonStep.EStopButtonPressed;
|
|
break;
|
|
}
|
|
signalValue = IoManager.Instance.ReadIn("启动");
|
|
if (signalValue == 1 || (buttonValue == ESystemButton.StartPressed))
|
|
{
|
|
step = EMonitorButtonStep.StartButtonPressed;
|
|
break;
|
|
}
|
|
signalValue = IoManager.Instance.ReadIn("停止");
|
|
if (signalValue == 1 || (buttonValue == ESystemButton.StopPressed))
|
|
{
|
|
step = EMonitorButtonStep.StopButtonPressed;
|
|
break;
|
|
}
|
|
signalValue = IoManager.Instance.ReadIn("复位");
|
|
//if (signalValue == 1 || (buttonValue == ESystemButton.ResetPressed))
|
|
if ((buttonValue == ESystemButton.ResetPressed))
|
|
{
|
|
step = EMonitorButtonStep.ResetButtonPressed;
|
|
break;
|
|
}
|
|
signalValue = IoManager.Instance.ReadIn("光栅门禁开关");
|
|
if(signalValue==0 && MachineManage.Instance.MachineStatus== EMachineStatus.Working)
|
|
{
|
|
step = EMonitorButtonStep.DoorOpend;
|
|
break;
|
|
}
|
|
|
|
signalValue = IoManager.Instance.ReadIn("照明");
|
|
if (signalValue == 1)
|
|
{
|
|
step = EMonitorButtonStep.LightButtonPressed;
|
|
break;
|
|
}
|
|
break;
|
|
case EMonitorButtonStep.EStopButtonPressed:
|
|
MessageQueue.Instance.Insert("急停按钮按下");
|
|
MachineManage.Instance.NeedRestoreMove = false;
|
|
AxisControl.AllDisable();
|
|
WorkFlow.Instance.Stop();
|
|
TurnoverFlow.Instance.Stop();
|
|
AxisControl.AllAbortHome();
|
|
HomeFlow.Instance.CancleHome();
|
|
MachineManage.Instance.MachineStatus = EMachineStatus.EStop;
|
|
step = EMonitorButtonStep.EStopButtonUp;
|
|
break;
|
|
case EMonitorButtonStep.EStopButtonUp:
|
|
signalValue = IoManager.Instance.ReadIn("前急停");
|
|
if (((IoManager.Instance.ReadIn("前急停") == 1)&& ((IoManager.Instance.ReadIn("后急停") == 1))) || (buttonValue == ESystemButton.ResetPressed))
|
|
{
|
|
buttonValue = ESystemButton.None;
|
|
//AxisManager.AllEnable();
|
|
MachineManage.Instance.MachineStatus = EMachineStatus.NotHomed;
|
|
MessageQueue.Instance.Insert("急停按钮抬起");
|
|
step = EMonitorButtonStep.Monitoring;
|
|
}
|
|
break;
|
|
case EMonitorButtonStep.StartButtonPressed:
|
|
MessageQueue.Instance.Insert("启动按钮被按下");
|
|
if (MachineManage.Instance.MachineStatus== EMachineStatus.Stop
|
|
|| MachineManage.Instance.MachineStatus== EMachineStatus.Homed)
|
|
{
|
|
if(MachineManage.Instance.NeedRestoreMove)
|
|
{
|
|
MachineManage.Instance.NeedRestoreMove = false;
|
|
//WorkFlow.Instance.Restore();
|
|
Thread.Sleep(100);
|
|
}
|
|
WorkFlow.Instance.Start();
|
|
MachineManage.Instance.MachineStatus = EMachineStatus.Working;
|
|
LightManger.Instance.SetStatus(ELightStatus.Green);
|
|
}
|
|
else
|
|
{
|
|
MessageQueue.Instance.Insert($"设备在{MachineManage.Instance.MachineStatus}状态,无法启动!");
|
|
}
|
|
step = EMonitorButtonStep.StartButtonUp;
|
|
break;
|
|
case EMonitorButtonStep.StartButtonUp:
|
|
signalValue = IoManager.Instance.ReadIn("启动");
|
|
if (signalValue == 0 || (buttonValue == ESystemButton.StartUp))
|
|
{
|
|
buttonValue = ESystemButton.None;
|
|
MessageQueue.Instance.Insert("启动按钮被抬起");
|
|
step = EMonitorButtonStep.Monitoring;
|
|
}
|
|
break;
|
|
case EMonitorButtonStep.ResetButtonPressed:
|
|
//MessageQueue.Instance.Insert("复位按钮被按下");
|
|
if (MachineManage.Instance.MachineStatus == EMachineStatus.NotInit
|
|
|| MachineManage.Instance.MachineStatus == EMachineStatus.NotHomed)
|
|
{
|
|
HomeFlow.Instance.StartGoHome();
|
|
}
|
|
step = EMonitorButtonStep.ResetButtonUp;
|
|
break;
|
|
case EMonitorButtonStep.ResetButtonUp:
|
|
//signalValue = IoManager.Instance.ReadIn("复位");
|
|
if ((buttonValue == ESystemButton.ResetUp))
|
|
{
|
|
buttonValue = ESystemButton.None;
|
|
//MessageQueue.Instance.Insert("复位按钮抬起");
|
|
step = EMonitorButtonStep.Monitoring;
|
|
}
|
|
break;
|
|
case EMonitorButtonStep.StopButtonPressed:
|
|
MessageQueue.Instance.Insert("停止按钮被按下");
|
|
if (MachineManage.Instance.MachineStatus== EMachineStatus.Working
|
|
|| MachineManage.Instance.MachineStatus== EMachineStatus.Homing)
|
|
{
|
|
if (MachineManage.Instance.MachineStatus == EMachineStatus.Homing)
|
|
{
|
|
HomeFlow.Instance.CancleHome();
|
|
MachineManage.Instance.MachineStatus = EMachineStatus.NotHomed;
|
|
}
|
|
else
|
|
{
|
|
WorkFlow.Instance.Stop();
|
|
MachineManage.Instance.MachineStatus = EMachineStatus.Stop;
|
|
}
|
|
LightManger.Instance.SetStatus(ELightStatus.Yellow);
|
|
}
|
|
step = EMonitorButtonStep.StopButtonUp;
|
|
break;
|
|
case EMonitorButtonStep.StopButtonUp:
|
|
signalValue = IoManager.Instance.ReadIn("停止");
|
|
if (signalValue == 0 || (buttonValue == ESystemButton.StopUp))
|
|
{
|
|
buttonValue = ESystemButton.None;
|
|
MessageQueue.Instance.Insert("停止按钮抬起");
|
|
step = EMonitorButtonStep.Monitoring;
|
|
}
|
|
break;
|
|
case EMonitorButtonStep.DoorOpend:
|
|
//AxisManager.AllStop();
|
|
WorkFlow.Instance.Stop();
|
|
MachineManage.Instance.NeedRestoreMove = true;
|
|
MachineManage.Instance.MachineStatus= EMachineStatus.Stop;
|
|
MessageQueue.Instance.Insert("光栅门禁被触发");
|
|
step = EMonitorButtonStep.Monitoring;
|
|
break;
|
|
case EMonitorButtonStep.LightButtonPressed:
|
|
if(Ops.IsOutOn("照明灯"))
|
|
{
|
|
Ops.Off("照明灯");
|
|
}
|
|
else
|
|
{
|
|
Ops.On("照明灯");
|
|
}
|
|
step = EMonitorButtonStep.LightButtonUp;
|
|
break;
|
|
case EMonitorButtonStep.LightButtonUp:
|
|
if(Ops.IsOff("照明"))
|
|
{
|
|
step = EMonitorButtonStep.Monitoring;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
Thread.Sleep(50);
|
|
}
|
|
}
|
|
}
|