State machine in C#, reading and writing from txt file

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi guys!
I`m working on a school project, and can`t quite get a grip on what to do here..
The assignment is to use a state machine, and then implement it into C# code.
I`m not sure if there is a "standard" way of making a state machine, but we are taught to define "States, events and actions", and then implement it in C#.
The problem already starts at this stage, i cant get my head around what the different states will be..
I will try to translate my assignment into english, and hopefully somenone can give me a guidance where to start:
A system is supposed to receieve messages via a serial communications-port, one sign at a time. The actual messages is marked with a two-sign startsequence:
ESC - ASCII-code 27
STX - ASCII-code 02
And a corresponding endsequence:
ESC - ASCII-code 27
ETX - ASCII-code 03
Between the messages, there might be data wich are not supposed to be registered. Endsequence recieved outside of a message indicates that there will not be any further messages, which means that the program can stop.
The content of the messages will be stored as lines in a txt file. When all the messages have been recieved and stored, the following information is to be stored in the same txt file:
Summary of session:
Number of messages:
Number of words in total:
Number of signs in total:
A word is defined as a sequence of signs, bounded by "blanks" (space, enter, tab or a start/stop sequence). A message with no content(only a start/stop sequence) may occur. The number of words in such a message equals zero, the number of signs is also equal to zero. A startsequence recieved within a message does not count as a "blank".
*phew*
Now to the actual assignment:
a)
Construct and describe a state machine for such a system. Use "circle-notation" with states with textet arrows for the transitions (never mind the graphics, i`m just after what the actual states will be)
b)
Write a C# program which implements the constructed state machine. The flow of signs is supposed to be recieved from a file (INPUT.TXT), and messages and summary will be stored in another file (SESJON.TXT).
And thats it.. If someone has any advice on how to solve this, i would be really happy! :)
Thanx for reading, regards from Norway! :D

View the full article
 
Back
Top