FSM in OOP

  • Thread starter Thread starter Marco Trapanese
  • Start date Start date
M

Marco Trapanese

Hi to all,

sorry for the strange object and for my English too :)

The object should sound as "how to implement a Finite State Machine with
an Object Oriented Programming language".

In embedded systems - such as PIC or AVR microcontrollers - FSMs are
often used to hard code a predefined sequence of operations that will be
followed as the inputs change.

The point is I always know the execution path of my program. In an OOP
language, you know, all actions are based on events. Sometimes one needs
(or thinks so) to emulate such a FSM to do a sequence of operations.

Example: an external unit (let's say a PLC) sends over a serial
connection some data. Let's call these information our 'inputs'. They
tell us which is the next action to do related to the current one.


There are some advantages when using FSMs: straight implementation of
complex tasks, taking care of all possible combinations of inputs,
almost same code used for more targets.

After all, the questions are:

1) does it make sense to implement a FSM in OOP language? Or should one
rethink the behavior of the system in terms of events?

2) if you answered 'yes' at point 1) what is the best way to achieve
that? Where put the processing routine? Currently, I put it into a timer
tick event: check the inputs and the state variables then update outputs
and state variables as well.


What do you think about that?

Any comment is appreciated!
Marco / iw2nzm
 
1) does it make sense to implement a FSM in OOP language? Or should one
rethink the behavior of the system in terms of events?

2) if you answered 'yes' at point 1) what is the best way to achieve
that? Where put the processing routine? Currently, I put it into a timer
tick event: check the inputs and the state variables then update outputs
and state variables as well.

You can use .NET 3.0's Windows Workflow Foundations to build your FSM. WWF
has a very rich API for this sort of thing :)
 
Hi to all,

sorry for the strange object and for my English too :)

The object should sound as "how to implement a Finite State Machine with
an Object Oriented Programming language".

In embedded systems - such as PIC or AVR microcontrollers - FSMs are
often used to hard code a predefined sequence of operations that will be
followed as the inputs change.

The point is I always know the execution path of my program. In an OOP
language, you know, all actions are based on events. Sometimes one needs
(or thinks so) to emulate such a FSM to do a sequence of operations.

Example: an external unit (let's say a PLC) sends over a serial
connection some data. Let's call these information our 'inputs'. They
tell us which is the next action to do related to the current one.


There are some advantages when using FSMs: straight implementation of
complex tasks, taking care of all possible combinations of inputs,
almost same code used for more targets.

After all, the questions are:

1) does it make sense to implement a FSM in OOP language? Or should one
rethink the behavior of the system in terms of events?

2) if you answered 'yes' at point 1) what is the best way to achieve
that? Where put the processing routine? Currently, I put it into a timer
tick event: check the inputs and the state variables then update outputs
and state variables as well.


What do you think about that?

Any comment is appreciated!
Marco / iw2nzm

..NET 3.0 - Windows Workflows.
 
Spam Catcher ha scritto:
You can use .NET 3.0's Windows Workflow Foundations to build your FSM. WWF
has a very rich API for this sort of thing :)

Thanks you both!
I'll look at WWF.

Any suggestion for a VB2005 and .NET 2.0?
I have several project based on this framework.

Bye
Marco / iw2nzm
 
Spam Catcher ha scritto:


Thanks you both!
I'll look at WWF.

Any suggestion for a VB2005 and .NET 2.0?
I have several project based on this framework.

Bye
Marco / iw2nzm

WF works in VS2005, however - it requires the 3.0 framework. This
upgrade is very painless however, since it is simply additional
libraries on top of the 2.0 runtime.

If you want to get the add-in for windows workflows for 2005 go here:

http://www.microsoft.com/downloads/...9E-1FA3-48CF-8023-E8F38E709BA6&displaylang=en
 
Back
Top