National Instruments 320682C Musical Toy Instrument User Manual


 
Formatting and I/O Library Chapter 2
LabWindows/CVI Standard Libraries 2-66 © National Instruments Corporation
This code shows how to insert an ASCII NUL at the end of the transferred bytes. After the
assignment, s is NUL-terminated.
Integer Array to Real Array
int ivals[100];
double dvals[100];
Scan (ivals, "%100i>%100f", dvals);
Remarks
Each integer in ivals is converted to real number and then written into dvals.
Integer Array to Real Array with Byte Swapping
int ivals[100];
double dvals[100];
Scan (ivals, "%100i[o10]>%100f", dvals);
Remarks
Each integer in ivals is byte-swapped, converted to a real number, and written into dvals.
Byte swapping is useful when a programmable instrument sends back 2-byte integers with the
high byte first, followed by the low byte. When this data is read into an integer array, the
placement of the bytes is such that the high byte is interpreted as the low byte. The
o10 modifier specifies that the bytes be interpreted in the opposite order.
Integer Array Containing 1-Byte Integers to Real Array
int ivals[50]; /* 100 1-byte integers */
double dvals[100]; /* 100 8-byte real numbers */
Scan (ivals, "%100i[b1]>%100f", dvals);
Scan (ivals, "%100i[b1u]>%100f", dvals);
Remarks
Sometimes, each element in an integer array is used to store two 1-byte integers. This example
shows how to unpack the 1-byte integers and store them in a real array. The b1 indicates that
each binary integer is only one byte long.