Jump to content

Read All Attributes


Recommended Posts

Hi people,

I would like to know, if it is possible to read all attributes of a Labview class by getting an Array of Variants? I would like to have such a Read Method because I will use all attributes of my class as the description of a TDMS-File. The attributes Type Descriptor Name will be the Property Name in my TDMS and the Value will be the TDMS Property Value.

Instead of calling all Read Methods for each single attribute in my class I would like to have a Generic VI with such properties:

-Input is a Variant, so I can wire any Class to that input.

-Output is a Array of Variants containing all attributes of the input class.

This Generic VI will then be a SubVI of the "Read_All" Method of each class to be able to access private attributes.

Has anyone an idea how to "typecast" or "Variant To Data" my Input Variant to a Generic Labview Class Reference, where I can access the attributes and their values to put them in my Array of Variants?

Bye

Corrected Version of my VI, I'm sorry for that.

Edited by KoBe
Link to comment

I would like to know, if it is possible to read all attributes of a Labview class by getting an Array of Variants? I would like to have such a Read Method because I will use all attributes of my class as the description of a TDMS-File. The attributes Type Descriptor Name will be the Property Name in my TDMS and the Value will be the TDMS Property Value.

Interesting challenge. I do not have a solution.

From a different perspective, can you even do what you want with a arbitrary cluster? That is, go from a cluster directly to an array of variants.

For a lame solution, the Read_All method has access to all of the class's private data. So you could just use the Unbundle method on the class's data, wire each element to the 'To Variant' method and build the array. Tedious, but perhaps better that calling all of the Read functions.

Kurt

Edited by kugr
Link to comment

From a different perspective, can you even do what you want with a arbitrary cluster? That is, go from a cluster directly to an array of variants.

Kurt

That work, I've a VI which takes a Cluster (input is Variant) and searches for it's contained datatype in the flattened data. Ouput is then an array of clusters. If I would be able to typecast / convert or extract the data cluster (attributes) of my class into a variant (containing this cluster) i could use my VI and .... finished.

But I don't know how to get the whole attribute cluster. If I look at the class as flattend data I can't find the type descriptor of the cluster, just class name and something else containing the class name. In the data string there seems to be all data, but I can not extract that in general if I don't have a meaningful type descriptor.

Let's try it the other way round: how could I get the the needed type descriptor out of the classname? Would that be possible maybe?

Bye

Link to comment
But I don't know how to get the whole attribute cluster.
You don't have a mechanism to do this, and if you find one, it's a bug that should be fixed. The class' data is private. If the class does not provide a mechanism for you to get at all of its fields, you do not have any way to get at all of its fields. This is by design.

Some folks have figured out ways to take the flattened string for some known cases and manipulate that directly. That's a hack that can be made to work, but there are limitations to that approach.

The Read All Attribute VIs mechanism that you mention at the start is the right, good and correct way of doing this.

Link to comment

From a different perspective, can you even do what you want with a arbitrary cluster? That is, go from a cluster directly to an array of variants.

The Variant To Data function can do this. Wire in an array of variants into the type input and a variant representing your cluster into the variant input. See the attached image. This also lets you go from a variant containing an array to an array of variants.

post-17400-018236800 1278515738_thumb.pn

Link to comment

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...

Important Information

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