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
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