45
The mechanism to receive the data uses events and methods as
described below:
The transmission sends blocks of information.
Stage 1
Except the last one, each block generates the event
DataArrivalInFastMode
. When the event occurs, run the method
Get_CurrentBlock
to read the current block. The block consists of
integer weights
separated by a Carriage Return. At this stage, just store
the blocks into a string array. This stage repeats until the last block
arrives. That is, if there are 10 blocks, then ‘stage 1’ occurs 9 times.
Stage 2
The last block generates the event
DataArrivalLastInFastMode
. Run
the method
Get_LastBlock
in order to read the last portion of the
integer
weights
and store them too in the string array used in stage 1.
Run the method
Get_Time_ms
in order to get the time stamp.
Stage 3
After the last block was received and stored, the weights may be
processed:
1. Recalling that the values are separated by Carriage Return, parse the
string array and keep the individual values in a numeric array. One clean
way to do that is write the array to file by Print and read back the file
using Input. Note that a value may be split between two blocks, e.g., the
value ‘123’ may appear as ‘12’ in the end of one block and ‘3’ in the
beginning of the next block. The above way using a file handles the
parsing well.
2. As described in the beginning of this section, the values are integers
that were accepted by multiplying the actual weight by
1, 10, 100, 1000 or 10000. You may find the actual weight by
multiplying the integer weight by a “Resolution_Factor” which is
1, 0.1, 0.01, 0.001 or 0.0001, respectively. You may find the
Resolution_Factor yourself, but for your convenience there is the method
Get_Resolution_Factor which returns the proper value.