Why is my LabVIEW Array not working properly?
This error is typically due to array management. Working with LabVIEW arrays and sending them through RTI Connext DDS can be tricky. Here you have some guidelines on how to fix this error
For versions of the RTI DDS Toolkit previous to 1.2.0.90
In LabVIEW, arrays are declared with an initial length of 0 and resized when valid data are attached to them. RTI DDS Toolkit for LabVIEW, however, expects arrays to be initialized before using them. You can see that an array has size 0 because it is grayed out as shown in the image.
As mentioned in the Getting Started Guide [1], you need to connect exactly the same type to Create Reader and Read subVIs. Thus, if you provide an uninitialized array as input to Create Reader, all you can connect to Read is another uninitialized array. Otherwise, you will get an RTI Connext DDS exception (shown in an external command window) saying: "Type code incorrect" or "Type mismatch".
Note: This also happens for Create Writer and Write subVIs.
How to avoid the exceptions
Since you probably need your array length to be greater than 0, you should initialize your arrays to the maximum length they will ever hold. Arrays inside clusters must be initialized as well. There are two initialization options:
- Use the Initialize Array function of the array palette [2] (recommended). This function sets the length of each of the array dimensions and initializes each of the elements to a given value.
- Manually initialize the array (not recommended). If you click and drag your array (using the positioning tool), you can resize the array to the desired length. Once that is done, you will still need to provide a value to each of the elements in the array.
Note: RTI DDS Toolkit for LabVIEW expects arrays to be initialized to their maximum size first time they are used, i.e., array resizing is not allowed.
From version 1.2.0.90 and below of the RTI DDS Toolkit for LabVIEW
Starting in version 1.2.0.90, the LabVIEW arrays have been mapped as DDS Sequences by default. This means that array resizing is possible.
The only requirement is to set the maximum sequence lenght when creating a new Reader/Wrtier. Following the steps metioned above, you should initialize the array connected to the Create function to the maximun leght of your array (MAX_LENGTH). From that moment, you do not need to worry about your LabVIEW array length. Any array which size is smaller than MAX_LENGHT can be connected to the Read/Write subVIs.
However, you can come back to the old behavior by setting the flag 'forceArray' when creating your VI (using Advanced Create Reader/Writer subVIs).
References:
- RTI_DDS_Toolkit_for_LabVIEW_GettingStarted.pdf found in <LabVIEW folder>/help/RTI DDS Toolkit for LabVIEW after installing the toolkit.
- LabVIEW Help: Initialize Array function