Utilizing LabVIEW Polymorphic VIs to Access Variables Directly by Name

Back to Document

For engineers who need direct access to variables by label name, LabVIEW polymorphic VIs is a method within the graphical programming language that incorporates benefits of dataflow based programming architecture with traditional text based variable accessibility. Unlike text based programming languages, LabVIEW has the power to incorporate both methods of handling variables. This document described the approach and provides an example program.

Table of Contents:
      Utilizing LabVIEW Polymorphic VIs to Access Variables Directly by Name
        Introduction

      Traditional text based programming languages allow access to variables directly by name. When the number of variables increase to several hundreds or even thousands, it is sometimes necessary to access these variables by name to:

      1. Avoid having to handle indexing of arrays or un-bundle / bundle clusters every time a variable is being accessed.
      2. Avoid excessive wire clutter in the graphical program if proper bundling techniques are not utilized.

      LabVIEW is a graphical programming language that typically transports data in wires of different types.
          Utilizing LabVIEW Polymorphic VIs to Access Variables Directly by Name
            Polymorphic VI functioning as a memory location

          The basic approach described here utilizes polymorphic VIs to access variables directly by name. Two types of operation on the variables are described: Get and Set. In this example, a data array is given to the main program. This data-array is an array of clusters. Each cluster contains one of each type variable that needs to be accessed. Attached to the data-array is an index array, providing label name for every index in the array of cluster elements (Figure 1).



          Figure 1: Index array, providing label name for every index in the array of cluster elements.


          The memory VI stores the data in an un-initialized shift register (Figure 2):



          Figure 2: Storing the initial memory data


          The general operation of the polymorphic memory VI (getting and setting values) is described in Figure 3 and 4.



          Figure 3: Setting the value of a memory location (Boolean data type in this example).




          Figure 4: Getting the value of a memory location (Boolean data type in this example).
              Utilizing LabVIEW Polymorphic VIs to Access Variables Directly by Name
                Accessing the memory location

              The memory elements are now accessed by calling them by name and selecting a datatype. In the Set case, the datatype wired into the polymorphic VI selects the instance of the VI that is executed. Polymorphic VIs are not intended to adapt to the type of an indicator wired to an output. Hence, it is necessary to wire a type input to the polymorphic VI that will be used in the "Get" case (see figure 5 below).




              Figure 5: Example of how to get a double precision memory value, adding 5 to its value, and storing it again. As seen, access to the memory location is by name.


              As with all type propagation, all information flows downstream from controls through nodes to indicators. Another way of adding the data type manually is by right clicking on the polymorphic VI and selecting type instead of automatic (for a particular instance of the Sub-VI). This can in several cases turn out to be the best choice since the number of wires are minimized.



              Figure 6: The next state entered in the machine accesses the new variable value by name, and the data type is set by right-clicking on the polymorphic VI instead.

                  Utilizing LabVIEW Polymorphic VIs to Access Variables Directly by Name
                    Conclusion

                  It has been demonstrated that by utilizing polymorphic VIs and un-initialized shift registers, calling variables by name to and from a memory location can be simulated.

                      Related Links:
                      Accessing LabVIEW Variables Directly by Name

                      你可能感兴趣的:(variable)