|
A
PC Interface for Hand-Held Devices
by Kock Kin Ko
Start
Creating GUI and Menu PC
Interface Software CVI Windows Programming
Basics Working Together
Plotting Performance Graphs How
Serial Com Operates Big Endian Data
Becomes Little Sources
BIG ENDIAN DATA BECOMES LITTLE
Consider the four-byte hex number 0x87654321.
The four bytes would be stored in descending order (87, 65, 43, 21)
in a Big Endian machine (Hitachi micro) and in ascending order (21,
43, 65, 87) in a Little Endian machine (PC). In a Big Endian machine,
the most significant byte of any integer comes first.
During the program debugging stage, I
did a little experiment to confirm that the Hitachi micro and the
PC were of different Endian machines. I ran the Hitachi emulator and
sent the data structure, via serial link, from the Hitachi micro to
a PC on which the CVI IDE was executing. In the variable windows on
both sides, it was clearly shown that the received data was arranged
in a reverse order.
To convert data from Big Endian format
into Little Endian format, Fmt(&target, "format string",
source) should be used where the target is in Little Endian format
and the source is in Big Endian format.
To convert a two-byte short integer,
the format string is %x[ub2]<%x[ub2o10]. CVI provides an
easy way to write the format string. All you have to do is run the
Format Wizard in the Utility program and click to select the data
format for the target (in this case it is the hexadecimal unsigned
two-byte short integer %x[ub2]) and the data format for the
source (the same as the target but with data order 10, meaning most
significant byte comes first). The Wizard generates the format string
automatically. Then, just copy the format string into your code.
To convert a four-byte long integer,
Format Wizard provides the format string as %x[u]%x[uo3210].
The car data structure tag was defined as:
struct statistic_form {
char elapse_time[3];
unsigned long int milli_amp_sec;
unsigned short int total_distance;
unsigned short int sum_inc_count;
};
Note that there are short integer and
long integer variables. The car data records, sent over from hand-held
unit to the PC, are defined as struct statistic_form image[13];
where the array size 13 refers to 13 different ranges of speed.
To convert the received data image[i]
from Big Endian into Little Endian format, a four-byte conversion
applies to image[i].milli_amp_sec, a two-byte conversion to
image[i].total_distance, and another two-byte conversion to
image[i].sum_inc_count. Listing
8 shows the details for CVI_reverse_order(). The conversion
goes through a for-loop for the 13 different ranges of speed index.
THATS ALL FOR NOW
Ive listed the most essential steps
for creating the PC serial-com interface software, and Ive shown
you that Windows programming is easy and CVI is straightforward to
use. Perhaps there will be a future article to discuss how to add
a CVI database for keeping the received data.
PREVIOUS
NEXT
Circuit Cellar provides up-to-date information
for engineers. Visit www.circuitcellar.com
for more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe
online. ęCircuit Cellar, the Magazine for Computer Applications.
Posted with permission.
|