You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.2 KiB
71 lines
2.2 KiB
using FSM.Machines;
|
|
using FSM.Recipes;
|
|
using FSM.States;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace FSM
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
PrintMessage("********** Start of the program **********");
|
|
|
|
IdleState initialState = new IdleState();
|
|
Recipe recipe = new Recipe("Main recipe",
|
|
new List<string>()
|
|
{
|
|
"MainRecipe_Step1",
|
|
"MainRecipe_Step2",
|
|
"MainRecipe_Step3",
|
|
"MainRecipe_Step4",
|
|
"MainRecipe_Step5",
|
|
});
|
|
initialState.SetRecipe(recipe);
|
|
|
|
var machine = new EquipmentStateMachine(initialState);
|
|
machine.OnHandleEvent -= machine_OnHandleEvent;
|
|
machine.OnHandleEvent += machine_OnHandleEvent;
|
|
|
|
List<EquipmentEvent> eventCommands = new List<EquipmentEvent>()
|
|
{
|
|
EquipmentEvent.Start,
|
|
EquipmentEvent.Pause,
|
|
EquipmentEvent.Resume,
|
|
EquipmentEvent.Stop,
|
|
EquipmentEvent.Start,
|
|
EquipmentEvent.EmergencyStop,
|
|
EquipmentEvent.Resume,
|
|
EquipmentEvent.Stop,
|
|
EquipmentEvent.Start,
|
|
EquipmentEvent.Stop,
|
|
};
|
|
|
|
foreach (EquipmentEvent evt in eventCommands)
|
|
{
|
|
machine.HandleEvent(evt);
|
|
Thread.Sleep(10 * 1000);
|
|
}
|
|
|
|
PrintMessage("********** End of the program **********" + Environment.NewLine);
|
|
PrintMessage("********** Press any key to exit the program **********");
|
|
Console.ReadKey();
|
|
}
|
|
|
|
private static void machine_OnHandleEvent(object sender, EquipmentEventHandler e)
|
|
{
|
|
string message = string.Format("{0} (State: {1}, Event: {2})", e.Message, e.CurrentState, e.EquipmentEvent);
|
|
PrintMessage(message);
|
|
}
|
|
|
|
static void PrintMessage(string message)
|
|
{
|
|
Console.WriteLine(string.Format("[{0}] {1}", DateTime.Now, message));
|
|
}
|
|
}
|
|
}
|
|
|