Jump to content

Best way to mimic fixed-size array use in clusters?


Recommended Posts

When using a fixed-size array inside a cluster, I am unable to use the cluster with functions that demand a fixed-size data type.  This even though the cluster is actually a fixed size.

 

 post-38039-0-99059900-1371673456.png

 

The alternative is to add an individual element for each entry in the array, but that quickly gets unwieldy and results in messy, overcomplicated code.

 

post-38039-0-43834600-1371673457.png

 

I've run into this issue several times and haven't found an elegant alternative to manually wiring up every single entry.  Hoping y'all have some good ideas in lieu of NI fixing the issue.

 

Thanks

Link to post

Hmm, I can't really help with your specific question, but is it possible to break out the fixed size array (unbundle) and just use that with the RT FIFO and update whatever the integer is (channel number?) in the same command (perhaps via control), right before you load the array in?


Alternatively, but slightly messier, you could have FIFOs that dequeue at the same time, one for the array, one for the int.

Link to post

It might be kind of clunky but in this particular case you could convert the I32 to a double and append to either the front or back of the array (so you would just be sending a fixed size array of doubles) and then remove it on the other end.

Link to post

On thing you can do (although I haven't tested this with RT FIFOs) is create a type definition for the cluster that is the fixed-size array. Then, put that cluster inside the cluster that contains the integer. It is then easy to convert the nested cluster into an array (using cluster to array). Going the other direction is only slightly more complicated. If you know that the array size won't change, you can use array to cluster. Otherwise you can typecast the array to the cluster type definition; this may be less efficient (my understanding is that typecast will always flatten to a string, then unflatten to the new representation, instead of a more direct conversion) but is more flexible.

  • Like 1
Link to post

I don't think you can do exactly what you want. Easiest way is to probably break out the array data from the cluster and send it down it's own FIFO. Reassemble the cluster on the receiving end from the data received from each FIFO if need be. The RT FIFO create primitive has an input that allows you to specify array size.

Link to post
On thing you can do (although I haven't tested this with RT FIFOs) is create a type definition for the cluster that is the fixed-size array. Then, put that cluster inside the cluster that contains the integer. It is then easy to convert the nested cluster into an array (using cluster to array). Going the other direction is only slightly more complicated. If you know that the array size won't change, you can use array to cluster. Otherwise you can typecast the array to the cluster type definition; this may be less efficient (my understanding is that typecast will always flatten to a string, then unflatten to the new representation, instead of a more direct conversion) but is more flexible.

 

Cool. That's what I ended up doing.  Submitted a feature request for what I was asking:  http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Implement-full-support-for-fixed-size-arrays-in-Labview/idi-p/2467734

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By Fred chen
      Hi
       
      When I call the DLL, there is a structure:
      struct Signal { uint32 nStartBit; uint32 nLen; double nFactor; double nOffset; double nMin; double nMax; double nValue; uint64 nRawValue; bool is_signed; char unit[11]; char strName[66]; char strComment[201]; };  
       
      There is another  Message structure to the above Signal:
       
      struct Message { uint32 nSignalCount; uint32 nID; uint8 nExtend; uint32 nSize; Signal vSignals[513]; char strName[66]; char strComment[201]; }  
        The point is  Signal vSignals[513];
       
      I've tried to solve it like this,but the program will crash.
       
      How to create struct Message ,any good suggestions?  Thanks a lot.
       

      message.vi
    • By Taylorh140
      After working on the set cluster element by name xnode, it made me realize i could use the same concept to convert a variant array to a cluster. The technique is actually pretty simple, the xnode generates a case structure for each element in a cluster in cluster order, wherein a bundle by name is used to set the value and an unbundle by name is used to get the type, a variant to data is used to convert the data. This has some benefits over some methods, you are not limited to 255 elements, although that is not usually the case some of us are paranoid that clusterosaurus giganticous will be larger than expected. It also has a draw back  that is that when converting from a variant array all the elements must have unique, non-blank names, and this is usually the case. 

      I think this technique (though very brute-force) might be useful for some other things let me know what you guys think.

      VariantArrayToCluster.zip
    • By Taylorh140
      This Xnode allows setting a cluster element by label string without using references. I pulled a great deal of inspiration from Hooovahhs Variant Array to cluster xnode, which i suppose this could be used for, another benefit is its not limited to 255 elements. Its mostly experimental because I haven't used it much. 
       
      SetClusterElement.zip

      SetClusterElementLV2013.zip
    • By Porter
      Is there any way to automatically wire an index array block to a bundle by name block?

      Auto-wire (pressing space) just adds one wire.
      Note that my cluster contains data of different types so converting the cluster to an array doesn't work.
      If there is a quick-drop shortcut for this I would be very impressed.
    • By GregFreeman
      Edit: found this in context help: Arrays and strings in hierarchical data types such as clusters always include size information.
       
      http://forums.ni.com/t5/LabVIEW/Write-to-Binary-File-Cluster-Size/td-p/3199224
       
      I have a cluster of data I am writing to a file (all different types of numerics, and some U8 arrays). I write the cluster to the binary file with prepend array size set to false. It seems, however, that there is some additional data included (probably so LabVIEW can unflatten back to a cluster). I have proven this by unbundling every element and type casting each one, then getting string lengths for the individual elements and summing them all. The result is the correct number of bytes. But, if I flatten the cluster to string and get that length, it's 48 bytes larger and matches the file size. Am I correct in assuming that LabVIEW is adding some additional metadata for unflattening the binary file back to a cluster, and is there any way to get LabVIEW to not do this?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.