Jump to content

How to use variant?


alphaone

Recommended Posts

Hi,

I wrote a sub VI whose parameter is variant. and i must convert this parameter to normal by "Variant to Data" function. How can i know which type this variant will be?? As the following figure shows,the variant may contain totally different types ,how to set the "type" of "Variant to Data" function as what i need??

post-2988-1129515281.jpg?width=400

Link to comment
Hi,

I wrote a sub VI whose parameter is variant. and i must convert this parameter to normal by "Variant to Data" function. How can i know which type this variant will be?? As the following figure shows,the variant may contain totally different types ,how to set the "type" of "Variant to Data" function as what i need??

Download OpenG Commander and install the lvdata package. This has tools for variant introspection and manipulation.

Link to comment
Thank you,but i don't wanna use OpenG in my program, is there another method?

If you want to set a control, you can try using the VI class "Set Control Value (Variant)" method. This will allow you to use a variant directly, but has its own dangers and downsides.

If you want to convert the data into a wire, you will have to have duplicate code at least to some degree, because the wire coming out of the function can only have one data type. You can have this duplicated code in polymorphic VIs, but that will also require some work. The OpenG VIs use the Type Descriptor to process the data. You could do the same, but since the work was already done, it seems a shame to do it all over.

Link to comment

Yes, it's easily done looking the descriptors. Time ago, I prepared an evolutioned version of the OpenG method, so if the variant is an array or a cluster, it says what kind of contents has (so the answer is "array of I32" instead just "array", or "array of clusters of string, boolean, refnum", etc).

I hope you'll find it useful. Keep in mind is just a VI I did for a particular purpose in a project, it's not really hard-validated. Just works for usual tasks.

Saludos,

Aitor

Download File:post-1450-1129539061.llb

Link to comment
Download OpenG Commander and install the lvdata package. This has tools for variant introspection and manipulation.

Thanks,i have read it. I can use the "typedescriptor" to judge what data type the variant contains. but , how about cluster?? we can see the types contained in a cluster,but we can't create a cluster by the types,at least i can't. because the parameter "type" of "Variant to Data" need a real cluster not a typedescriptor.

Yes, it's easily done looking the descriptors. Time ago, I prepared an evolutioned version of the OpenG method, so if the variant is an array or a cluster, it says what kind of contents has (so the answer is "array of I32" instead just "array", or "array of clusters of string, boolean, refnum", etc).

I hope you'll find it useful. Keep in mind is just a VI I did for a particular purpose in a project, it's not really hard-validated. Just works for usual tasks.

Saludos,

Aitor

Thanks,your vi is nice.i can analyse the types contained by a variant. But how to use the type descriptor to create real controls??

Link to comment
Thanks,i have read it. I can use the "typedescriptor" to judge what data type the variant contains. but , how about cluster?? we can see the types contained in a cluster,but we can't create a cluster by the types,at least i can't. because the parameter "type" of "Variant to Data" need a real cluster not a typedescriptor.

Thanks,your vi is nice.i can analyse the types contained by a variant. But how to use the type descriptor to create real controls??

You need to parse and construct data strings and type descriptors. This is not trivial. You might as well use the OpenG tools -- why do you think that you shouldn't use them?

Link to comment
and my project is not complex to use Goop, so i don't want to install it. and i think it will be better if you do this by yourself. :)

There might be a communication break down here.

OpenG Tools and Libraries accessible through OpenG commander are not Goop Class.

The OpenG Tools are made of several libraries such as File IO, Arrays Manipulation, String Manipulation, Application Controls, LV Data Tools (<- This is the one that will interest you) and more. Each of these library are packaged in a special zip fil called "ogp" (for OpenG Package) and can be installed in your system by using OpenG Commander (See image below for a screen shot of the commander showing a list of the most recent packages).

post-121-1129648258.png?width=400

One of these packages is a Goop Class template (hence maybe the confusion), but this one of many.

If you do not want to use the Free OpenG Tools, this is fine. But why redo the work that someone has already done ?

PJM

Link to comment
how to construct?use "unflatten from string" or "unflatten to variant"?

and my project is not complex to use Goop, so i don't want to install it. and i think it will be better if you do this by yourself. :)

maybe i havn't expressed my question clearly.that is :

A sub vi's parameter is variant.

In this sub vi, i have to transfer variant to a real control even a cluster. then ,i use this cluster to control my equipments.

For example, i want to control VSA by GPIB,so pass the GPIB address and center freqenecy. At other time,i want control my AWG, so pass a different type parameters.That's why i use variant as a sub vi's parameter.

The cluster maybe the following struct:

Equipment ID

VISA command

...

Testment ID

Testing parameter

...

that's all ,so i want to transfer the variant to a cluster,after all ,i don't know the detail of the variant at design phase util the vi is running.

If you don't know what the datatype is at design time then you have a significant challenge ahead of you. I've done exactly what you describe using variants for a flexible test system I built, however I used the OpenG variant tools. The OpenG variant tools are really cool! :thumbup: You can do everything you describe. They were created by the one and only jpdrolet . The best part... you don't have to write a single line of code. :P

Link to comment
If you don't know what the datatype is at design time then you have a significant challenge ahead of you. I've done exactly what you describe using variants for a flexible test system I built, however I used the OpenG variant tools. The OpenG variant tools are really cool! :thumbup: You can do everything you describe. They were created by the one and only jpdrolet . The best part... you don't have to write a single line of code. :P

Oh,it's a good news! i have already been despaired.Can i download only the Variant Tools of Goop? My comany's network blocks me and i can not user Commander to do it.

Thanks.

Link to comment
Can i download only the Variant Tools of Goop? My comany's network blocks me and i can not user Commander to do it.

That's a very good question.

I'd like to update the OpenG libraries on a machine that is no longer connected to an open network.

I wonder what folder of files I need to copy from an up-to-date machine to effectively update a machine where Commander won't work...

Link to comment

I have posted info on how to do this here:

There are a couple ways to get all of the OpenG packages.

1) You can download them individually. Most of them are located here: http://sourceforge.net/projects/opengtoolkit

2) You can download them all using Commander on a machine that has internet access and then transfer them to the computer that does not have internet access. Commander keeps all of it's packages in a "cache" folder. You can see the location of the cache by navigating to Tools (menu) >> Options (menu) >> Advanced (button) >> Cache (tab).

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
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.