Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

a state machine design question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tat - 31 Mar 2008 22:02 GMT
Hi all,

Sorry if this question is off-topic. I would like have your
suggestion .

I need to write one application which control a machine via serial
port. There are 5 states in the following sequence: active, set,
check, command, and clear. In each state, there are two sub-states: do
and wait. For example, in active state: do() sub-state performs the
activation and the sub-state wait() waits for signal from serial port.
If it is either timeout or the message has bad CRC, it goes back to
substate do(). Otherwise, it will go to set state, etc.

I think that it is more straightforward to have 10 different states.
Because in this case I can just use state pattern with one abstract
state, one context and 10 concrete states.

I also think that it is nicer to use 5 states and each has substate.
However, I am kind of confused if you want to do it this way because
active state now plays both a role of context and a role of concrete
state. In this case , there seems to be two different abstract states
(one for sub-states do() and wait(), the other for five states).
I am not really sure what to do in this case. I would be appreciate
any suggestion. If you happen to know a similar example, I would
really appreciate if you let me know.
Thanks,
tat
Peter Morris - 31 Mar 2008 22:25 GMT
Going for sub-regions is only really useful in my opinion if you wish to be
able to ask

"Which *main* state am I in?" and get an answer like Active, Set, Check, or
Command.  For example, if your object is persisted and you wish to find all
objects that are in the state "Active".

If you don't need to do this (which I don't think you will in this example)
then I see no point in having sub-regions instead of one long list of states

ActiveWait
ActiveDo
SetWait
SetDo
etc

which will be easier to write :-)

Pete
Tom Dacon - 31 Mar 2008 23:44 GMT
Think of it this way: would you rather have one state machine to code, or
six? If you use substates, you've got one state machine to handle
transitions among the five main states, and each one of those states has its
own two-state state machine.

In a relatively simple situation like this, I'd do it as a single state
machine. But that's just me.

Tom Dacon
Dacon Software Consulting

> Hi all,
>
[quoted text clipped - 23 lines]
> Thanks,
> tat

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.