|
|
using Rs.Controls;
|
|
|
using Rs.Framework;
|
|
|
using Rs.Motion;
|
|
|
using Rs.MotionPlat.Commom;
|
|
|
using Rs.MotionPlat.Entitys;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using static Rs.MotionPlat.Commom.SchedulingAlarms;
|
|
|
using static Rs.MotionPlat.Commom.SchedulingMessageBox;
|
|
|
|
|
|
namespace Rs.MotionPlat.Flow
|
|
|
{
|
|
|
public enum EMonitorButtonStep
|
|
|
{
|
|
|
Monitoring,//监控中
|
|
|
EStopButtonPressed,//急停按钮按下
|
|
|
EStopButtonUp,//急停按钮抬起
|
|
|
StartButtonPressed,//启动按钮按下
|
|
|
StartButtonUp,//启动按钮抬起
|
|
|
ResetButtonPressed,//复位按钮按下
|
|
|
ResetButtonUp,//复位按钮抬起
|
|
|
StopButtonPressed,//停止按钮按下
|
|
|
StopButtonUp,//停止按钮抬起,
|
|
|
DoorOpend,//门被打开,
|
|
|
DoorClosed,//门已关闭
|
|
|
LightButtonPressed,//照明被按下
|
|
|
LightButtonUp,//照明被抬起
|
|
|
SkipButtonPressed,//跳过被按下
|
|
|
SkipButtonUp,//跳过被抬起
|
|
|
RetryButtonPressed,//重试被按下
|
|
|
RetryButtonUp//重试被抬起
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
int msgID = -1;
|
|
|
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;
|
|
|
}
|
|
|
if(!GlobalVar.DisableDoor)
|
|
|
{
|
|
|
signalValue = IoManager.Instance.ReadIn("后安全门禁");
|
|
|
if (signalValue == 0)
|
|
|
{
|
|
|
step = EMonitorButtonStep.DoorOpend;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
signalValue = IoManager.Instance.ReadIn("照明");
|
|
|
if (signalValue == 1)
|
|
|
{
|
|
|
step = EMonitorButtonStep.LightButtonPressed;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
signalValue = IoManager.Instance.ReadIn("跳过");
|
|
|
if (signalValue == 1)
|
|
|
{
|
|
|
step = EMonitorButtonStep.SkipButtonPressed;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
signalValue = IoManager.Instance.ReadIn("重试");
|
|
|
if (signalValue == 1)
|
|
|
{
|
|
|
step = EMonitorButtonStep.RetryButtonPressed;
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
case EMonitorButtonStep.EStopButtonPressed:
|
|
|
MessageQueue.Instance.Insert("急停按钮按下");
|
|
|
MachineManage.Instance.NeedRestoreMove = false;
|
|
|
AxisControl.AllDisable();
|
|
|
DischargeFlow.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)
|
|
|
{
|
|
|
Ops.Start();
|
|
|
//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.Warn($"device {MachineManage.Instance.MachineStatus} status,cann't start!");
|
|
|
}
|
|
|
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();
|
|
|
Ops.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:
|
|
|
Ops.Stop();
|
|
|
string alarminfo = string.Format(AlarmCollection.GetAlarm(AlarmConstID.门禁触发));
|
|
|
PromptMessageBox.Show(AlarmConstID.门禁触发, alarminfo, SchedulingMessageBox.ETipButton.None);
|
|
|
MessageQueue.Instance.Warn("门禁被触发");
|
|
|
step = EMonitorButtonStep.DoorClosed;
|
|
|
break;
|
|
|
case EMonitorButtonStep.DoorClosed:
|
|
|
signalValue = IoManager.Instance.ReadIn("后安全门禁");
|
|
|
if (signalValue == 1)
|
|
|
{
|
|
|
MessageQueue.Instance.Warn("门禁已解除");
|
|
|
PromptMessageBox.CloseWindow(AlarmConstID.门禁触发, ETipButton.None);
|
|
|
step = EMonitorButtonStep.Monitoring;
|
|
|
break;
|
|
|
}
|
|
|
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;
|
|
|
case EMonitorButtonStep.SkipButtonPressed:
|
|
|
//关闭消息
|
|
|
MessageQueue.Instance.Insert("跳过按钮按下");
|
|
|
msgID = TestCenterMessageBox.GetMsgID( SchedulingMessageBox.ETipButton.Skip);
|
|
|
if (msgID>0)
|
|
|
{
|
|
|
SchedulingMessageBox box = new SchedulingMessageBox();
|
|
|
box.Button = SchedulingMessageBox.ETipButton.Skip;
|
|
|
box.Instruction = EInstruction.CloseMessage;
|
|
|
box.TurnoverID = 0;
|
|
|
box.GroupID= 0;
|
|
|
box.ID = msgID;
|
|
|
TestCenter.Instance.ReportToTestCenter(box);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
msgID = AlarmMessageBox.GetMsgID(SchedulingMessageBox.ETipButton.Skip);
|
|
|
if(msgID>0)
|
|
|
{
|
|
|
SchedulingAlarms alarmBoxs = new SchedulingAlarms();
|
|
|
alarmBoxs.Instruction = EInstruction.CancelAlarms;
|
|
|
alarmBoxs.TurnoverID = 0;
|
|
|
alarmBoxs.GroupID = 0;
|
|
|
AlarmItem alarmItem = new AlarmItem();
|
|
|
alarmItem.NO = msgID;
|
|
|
alarmItem.Button = ETipButton.Skip;
|
|
|
alarmBoxs.Alarms.Add(alarmItem);
|
|
|
TestCenter.Instance.ReportToTestCenter(alarmBoxs);
|
|
|
}
|
|
|
}
|
|
|
step = EMonitorButtonStep.SkipButtonUp;
|
|
|
break;
|
|
|
case EMonitorButtonStep.SkipButtonUp:
|
|
|
if (Ops.IsOff("跳过"))
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("跳过按钮抬起");
|
|
|
step = EMonitorButtonStep.Monitoring;
|
|
|
}
|
|
|
break;
|
|
|
case EMonitorButtonStep.RetryButtonPressed:
|
|
|
//关闭消息
|
|
|
MessageQueue.Instance.Insert("重试按钮按下");
|
|
|
msgID = TestCenterMessageBox.GetMsgID( SchedulingMessageBox.ETipButton.Retry);
|
|
|
if (msgID > 0)
|
|
|
{
|
|
|
SchedulingMessageBox box = new SchedulingMessageBox();
|
|
|
box.Button = SchedulingMessageBox.ETipButton.Retry;
|
|
|
box.Instruction = EInstruction.CloseMessage;
|
|
|
box.TurnoverID = 0;
|
|
|
box.GroupID = 0;
|
|
|
box.ID = msgID;
|
|
|
TestCenter.Instance.ReportToTestCenter(box);
|
|
|
}
|
|
|
step = EMonitorButtonStep.RetryButtonUp;
|
|
|
break;
|
|
|
case EMonitorButtonStep.RetryButtonUp:
|
|
|
if (Ops.IsOff("重试"))
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("重试按钮抬起");
|
|
|
step = EMonitorButtonStep.Monitoring;
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
Thread.Sleep(50);
|
|
|
}
|
|
|
}
|
|
|
}
|