Professional Documents
Culture Documents
OOP HWjoker
OOP HWjoker
When you press the Select File button, it will allow you to select the Sensor_data.dat file. (Put
Sensor_data.dat file under the Debug folder. )
Sensor_data.dat file includes data from a sensor:
00
00
00
00
AA
56
34
12
02
AA
00
00
Pay attention to the data that the end of each line includes space. Hence, you must use the Trim method
of string class.
If you look at the file, you can see that one package is including less than 5 data, and another one
has more than 5 data. This may happen because of the loss of data in the communication. Your
code should handle such problems.
After you select the file and press Open, all data in the file will be assigned to a List<string> collection:
Lets name it as msgStore.
After selecting the file, when you press the Start Reading button, timer control will start to tick. Time
interval is 10ms. At each tick, the code will call the LogMe method by sending the each element of
msgStore consecutively: LogMe(msgStore[cntr]);
In LogMe method, at first, the code will look for the AA. Till AA comes, at each tick, Waiting for AA will
be written to the listbox. Pay attention to the methods BeginUpdate and EndUpdate of listbox
control. If you do not use them properly, your code may not work.
When the whole package is read, the reading value will be added to the listbox as shown below. Do not
forget the item number in the listbox. Note that, there is no item number for the line Waiting for AA.
When the reading has reached to the end of list, the timer must stop.
Your code will convert the data to the meaningful readings and will handle corrupted
data(communication problems). Your output screen will be exactly as shown below.