10-15-2008 06:15 PM
Thanks again for all your help NathanD.
As far as the variable data length issue you raise, my plan is to set the cluster control strings and arrays to values whose lengths correspond to the C structure definition. Then I'll pass a reference to that cluster to my elusive generic cluster filler from byte array VI, aka GCFFBA.vi. So LabVIEW will know the length of all the data types - they will be set in the cluster whose reference I will pass to the GCFFBA.vi
I will be using the cluster typedef to display strings to the user, so isn't acceptable to show it as a string subcluster. It needs to be in easily readable form.
My dream is that GCFFBA.vi will be able to fill any current or future cluster without modifiying or creating any additional VIs, by just modifiying or creating the cluster typedef.
I am thinking more about what else would have to be done to handle programmatically filling cluster values of various data types from a byte array. It will be complex and may require recursion. If and when I get a VI together that does this part of the job, I'll post a PNG of the block diagram.
In the meantime, does anyone know how to get the size of a cluster in LabVIEW assuming all its strings and arrays are initialized to fixed sizes?
Thanks,
Hans
.
10-16-2008 02:33 AM
Hi Hans,
in the attached vi, you can see what i meant in my first post. I think with this you can get enough information to do what you want.
Hope it helps.
Mike
10-21-2008 02:45 PM
Thank you MikeS. Your VI gave me a couple insights that will indeed help.
Insight 1 - Variant to Flattened String puts out a Type Descriptor array as well as the flattened string. Somehow I had missed that. I had seen the Type Descriptor explanation in the LabVIEW help, but thought that info was embedded in the flattened string.
Insight 2 - The least significant byte of the second element of the Type Descriptor array is an enumerated value that gives the data type of a control. That will be useful in making an easily readable case structure to switch on the data type and use the appropriate method to get the size of that data type. It looks like the size info will be available in different bytes of the flattened string for different data types.
I'm confident now that I'll be able to acheive my dream VI, but it may be a while before I work on it because the project that I will use it in has been moved to a lower priority. I'll post when I make more progress.
Thanks again,
Hans
08-11-2009 12:34 PM
I use this to get length of any structure. Works so far.
08-13-2009 11:23 PM
I like the idea of least effort, but when I tried that diagram, it returned a length of 21 when the actual cluster size is 5 bytes for the string + 4 for the I32 + 8 for the double = 17.
Hans
08-13-2009 11:43 PM
08-13-2009 11:56 PM
08-14-2009 03:43 AM
Idea wrote:I use this to get length of any structure. Works so far.
I believe you can simplify this by using flatten to string directly on the cluster. Also, you should note that some languages (e.g. Japanese) use more than one byte per character. I believe string length returns the number of bytes anyway, but you would want to make sure.
08-17-2009 04:22 AM
nathand wrote:I think you are making this more complicated than necessary. If you are willing to accept fixed-size data in your LabVIEW data types (as you are in your C program by declaring the size in the header file), you don't need any cluster-filling VI at all - you can use LabVIEW's typecast to directly convert your byte array into LabVIEW data. You can build up your initial fixed-sized cluster using "array to cluster" so that if your C header changes you can just right-click once and update the cluster size. If you have not already done so, take a look in the LabVIEW help for "How LabVIEW stores data in memory."
As far as I know, unlike LabVIEW, C provides no way to determine the length of an array even when the length is specifically declared. The only way to get a string length in C is to iterate through each character until a null is found, regardless of the length that may have been declared for the string. LabVIEW is able to provide string lengths and array dimensions because it stores that information as part of the data type; C treats an array as a pointer plus an offset without setting any limit on that offset.
Actually all modern C compilers should return the maximum size of all fixed size data resulting in the value 100 for following sizeof():
char test[100;
int length = sizeof(test);
The result will be always 100 independant of the actual string being present or not in the fixed size string variable test.
Rolf Kalbermatter
09-20-2019 10:38 AM
There is a much simpler way to accomplish this providing your input is a defined cluster (as opposed to dynamically built). Pass a reference to the cluster, rather than wiring the cluster to a variant. Now you can use property nodes to access the cluster. See attached example. Note this will not work for a LabVIEW class.