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.

98 lines
2.8 KiB
C#

using Rs.Motion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace Rs.MotionPlat.Flow
{
public enum ELightStatus
{
Red,
Yellow,
Green,
YellowBlink,
}
public class LightManger
{
Timer timer;
ELightStatus LightStatus = ELightStatus.YellowBlink;
bool on = false;
private LightManger() {
timer = new Timer();
timer.Interval = 1000;
timer.Elapsed += Timer_Elapsed;
timer.Enabled = true;
IoManager.Instance.WriteOut("黄灯", 1);
IoManager.Instance.WriteOut("红灯", 1);
IoManager.Instance.WriteOut("绿灯", 1);
}
private static LightManger instance;
public static LightManger Instance
{
get
{
if(instance == null)
instance = new LightManger();
return instance;
}
}
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
switch (LightStatus)
{
case ELightStatus.YellowBlink:
if(!on)
{
IoManager.Instance.WriteOut("黄灯", 0);
on = true;
}
else
{
IoManager.Instance.WriteOut("黄灯", 1);
on = false;
}
break;
case ELightStatus.Red:
if (!on)
{
IoManager.Instance.WriteOut("黄灯", 1);
IoManager.Instance.WriteOut("红灯", 0);
IoManager.Instance.WriteOut("绿灯", 1);
on = true;
}
break;
case ELightStatus.Yellow:
if (!on)
{
IoManager.Instance.WriteOut("黄灯", 0);
IoManager.Instance.WriteOut("红灯", 1);
IoManager.Instance.WriteOut("绿灯", 1);
on = true;
}
break;
case ELightStatus.Green:
if (!on)
{
IoManager.Instance.WriteOut("黄灯", 1);
IoManager.Instance.WriteOut("红灯", 1);
IoManager.Instance.WriteOut("绿灯", 0);
on =true;
}
break;
}
}
public void SetStatus(ELightStatus status)
{
LightStatus=status;
on = false;
}
}
}