Using the Flatten To String Function

The Flatten To String function takes LabVIEW data and converts it into a string. This string, when used in conjunction with the various communication functions or I/O functions, can be stored in a file or database or be sent to other computers.

The string created by the Flatten To String function is a LabVIEW string. If the prepend array or string size? input of the Flatten To String function is TRUE, the LabVIEW string has a 4-byte number, which is a 32-bit, signed integer data type, at the beginning of the string that specifies the length of the string. Specifying the length of the string enables a LabVIEW string to include NULL characters, such as the ASCII character zero (0). If a LabVIEW string is passed to external code and used as a C string, NULL characters embedded in the string might cause problems because C strings are interpreted as terminating at the first NULL character.

To pass the flattened form of LabVIEW data to C code, convert the flattened LabVIEW data from a binary string format to an alphanumeric string format. For example, suppose your string consists of the following five characters:

* character 35 (#)

* character 65 (A)

* character 0 (NULL)

* character 50 (2)

* character 107 (k)

Complete the following steps to convert the preceding five characters from a binary string format to an alphanumeric string format.

  1. Convert the decimal values of the five characters into hexadecimal values.

    35d = 0x23

    65d = 0x41

    0d = 0x00

    50d = 0x32

    107d = 0x6B

  2. Write down the actual alphanumeric characters for the hexadecimal values and include only a single NULL value at the end.

    * character 50 (2)

    * character 51 (3)

    * character 52 (4)

    * character 49 (1)

    * character 48 (0)

    * character 48 (0)

    * character 51 (3)

    * character 50 (2)

    * character 54 (6)

    * character 66 (B)

    * character 0 (NULL)

Converting from a binary string format to an alphanumeric string format doubles the size of the string. However, converting to an alphanumeric format preserves the information in the string when you use the string in an environment where you have to replace LabVIEW strings with C strings.