This repository has moved to GitHub!

Source Code on GitHub
Documentation on GitHub



Project Description
UML and Statechart inspired state machine library with hierarchical and orthogonal states. Implemented in C#. Portable assembly, runs on Windows, Mono and NETMF


Features
Provides a state machine execution environment that serves as a foundation for both plain state machines as well as complex state machines with hierarchical (composite) and orthogonal (concurrent) states.
Fork and join transitions.
Entry-, exit-, do- and transition-actions.
Guard conditions.
Shallow history.
Run-to-completion processing.
Provides Statecharts functionality comparable to SCXML.
Low garbage object creation during runtime.
Free from runtime thread synchronization calls and timers.
Multiple state machine instances can be created from a single state machine definition.
Optional code generation based on Microsoft Visio diagrams.
Delivered as
- Portable assembly for .NET Framework 4, Silverlight 5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8 and higher versions, runs on Mono.
- Assembly for .NET Micro Framework 4.3
Detailed description on http://StaMa.org/.


.NET Micro Framework

StaMa perfectly matches the limitations of small devices and NETMF.
In particular...
Ticket vending machine sample
A sample demonstrates StaMa usage in the NETMF Sample Emulator

TicketVendingNETMF.png

TicketVendingNETMFVisio.png




Sample complex state machine
Code and Microsoft Visio diagram is part of the release download.

ClockSample.png


Sample code for a simple state machine
Corresponding Visio diagram below.

namespace SimpleWatch
{
    class AppMain
    {
        [STAThread]
        static void Main(string[] args)
        {
            SimpleWatch watch = new SimpleWatch();

            watch.SendTriggerEvent(SimpleWatch.Event.LeftButtonPressed);
            watch.SendTriggerEvent(SimpleWatch.Event.RightButtonPressed);

            watch = null;
        }
    }


    // The wrapper around the state machine controller provides the code of the entry and exit callbacks.
    class SimpleWatch
    {
        public enum Event
        {
            RightButtonPressed,
            LeftButtonPressed
        }

        // The state machine controller.
        private StateMachine m_stateMachine = null;


        public SimpleWatch()
        {
            StateMachineTemplate t = new StateMachineTemplate();

            //## Begin Structure
            // Generated from <file:S:\StaMa_State_Machine_Controller_Library\Samples\Clock\DlgMain.vst>
            // at 01-31-2008 23:20:24 using StaMaShapes Version 2
            t.Region("DisplayTime", false);
                t.State("DisplayDate", EnterDisplayDate, null);
                    t.Transition("RightButtonPressed", "DisplayDate", "DisplayTime", Event.RightButtonPressed, null, null);
                t.EndState();
                t.State("DisplayTime", EnterDisplayTime, null);
                    t.Transition("LeftButtonPressed", "DisplayTime", "DisplayDate", Event.LeftButtonPressed, null, null);
                t.EndState();
            t.EndRegion();
            //## End Structure

            m_stateMachine = t.CreateStateMachine();

            m_stateMachine.Startup();
            System.Console.WriteLine("After startup. Active state is {0}", m_stateMachine.ToString());
        }


        // Forwards the trigger events to the embedded state machine
        public void SendTriggerEvent(Event ev)
        {
            m_stateMachine.SendTriggerEvent(ev, null);
            System.Console.WriteLine("After event {0}. Active state is {1}", ev, m_stateMachine.ToString());
        }

  
        // Entry callback method for state "DisplayTime".
        private void EnterDisplayDate(StateMachine stateMachine, object triggerEvent, EventArgs eventArgs)
        {
            System.Console.WriteLine("EnterDisplayDate called.");
        }


        // Entry callback method for state "DisplayDate".
        private void EnterDisplayTime(StateMachine stateMachine, object triggerEvent, EventArgs eventArgs)
        {
            System.Console.WriteLine("EnterDisplayTime called.");
        }
    }
}


SimpleClockSample.png



Comments are greatly appreciated. If You decide to evaluate or actually use StaMa in some real world application it would be excellent if You leave a note whether or not StaMa met Your needs.