Many instruments return a waveform as an ASCII string or a binary string. Assuming the same waveform, a binary string transfer is faster and requires less memory than an ASCII string transfer. Binary encoding requires fewer bytes than ASCII encoding.
ASCII Waveforms
As an example, consider a waveform composed of 1,024 points, each point having a value between 0 and 255. Using ASCII encoding, you would need a maximum of 4 bytes to represent each point (a maximum of 3 bytes for the value of the point and 1 byte for the separator, such as a comma). You would need a maximum of 4,096 ( 4×1,024) bytes plus any header and trailer bytes to represent the waveform as an ASCII string. Figure 1 is an ASCII waveform string.
You can use the
Extract Numbers
VI located in the C:\Exercises\LabVIEW Basics I
directory to convert an ASCII waveform into a numeric array, as follows. This VI outputs the waveform as a double precision array.Binary Waveforms Encoded as 1-Byte Integers
The same waveform using binary encoding requires only 1,024 bytes ( 1×1,024) plus any header and trailer bytes to be represented as a binary string. Using binary encoding, you need only 1 byte to represent the point, assuming each point is an unsigned 8-bit integer. Figure 3 is a binary waveform string.
Converting the binary string to a numeric array is a little more complex. You must convert the string to an integer array. You can do this by using the String To Byte Array function located on the
Functions>>All Functions>>String>>String/Array/Path Conversion
palette. You must remove all header and trailer information from the string before you can convert it to an array. Otherwise, this information also is converted.Binary Waveforms Encoded as 2-Byte Integers
If each point in the binary waveform string is encoded as a 2-byte integer, it is easier and much faster to use the
Type Cast
function located on the Functions>>All Functions>>Advanced>>Data Manipulation
palette. Refer to the LabVIEW Basics II: Development Course Manual for more information about type casting.For example, consider a GPIB oscilloscope that transfers waveform data in binary notation. The waveform is composed of 1,024 data points. Each data point is a 2-byte signed integer. Therefore, the entire waveform is composed of 2,048 bytes. In Figure 5, the waveform has a 4-byte header DATA and a 2-byte trailer--a carriage return followed by a linefeed.
The block diagram in Figure 6 shows how you can use the
Type Cast
function to cast the binary waveform string into an array of 16-bit integers.You might need to use the Swap Bytes function located on the
Functions>>All Functions>>Advanced>>Data Manipulation
palette to swap the most significant 8 bits and the least significant 8 bits for every element. Remember, the GPIB is an 8-bit bus. It can transfer only one byte at a time. If the instrument first sends the low byte and then the high byte, you do not need to use the Swap Bytes
function.In the example, you needed to use the Swap Bytes function because the instrument sent the most significant byte first. Because the most significant byte is received first, it is placed in a lower memory location than the least significant byte sent after the most significant byte.
No comments:
Post a Comment