From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variant conversion depending on enum value

Hi everybody

I developed a conception for our test equipment which I d'like to share with you because I'm hoping that somebody might have a good idea how to ease the following issue:

I've got a separate VI which handles the communication to all test equipment. A test program communicates with this VI by means of a queue. There are a lot of commands to be sent through the queue to the receiver-VI. A sample of a command looks like this:

Command.png
Sorry for the german expressions. As you can see, the queue data type is a cluster of type def enum and variant. The enum specifies the action to be executed by the receiving VI. The variant provides some necessary parameters. Example:

- Enum value: "Set Multimeter Range"

- Parameter value: 10 (Double)

This command sets the multimeter's range to 10V.

There are plenty of data types which are converted to variant. Double, int, array of int, bool, type def clusters, and many others. And every action (enum selection) requires the correct data type for the parameter.

My problem is that I don't know the necessary data type to pass through the queue without checking it up in the block diagram of the receiving VI where the variant is reconverted into its original data type. One option is to create subVIs for every possible data type but this would make my code more confusing. I'd like to have one caller-VI if possible. Does anyone know a possibility to build a workaround in order to get the correct data type depending on the enum selection?

Many thanks for every help!

Thomas

0 Kudos
Message 1 of 3
(2,512 Views)

Hi

 

If I understood your question correctly, this is what you want:

 

when programming/coding/developing, you want to know the correct data type which should be converted to variant in the caller vi, without havign to open the client vi everytime and check waht it needs for a specific action.


Example:

- Enum value: "Set Multimeter Range"

- Parameter value: 10 (Double)

This command sets the multimeter's range to 10V.


instead of wiring a boolean to the 'to variant' function in your code, you want to confirm that you need only a double for Set Multimeter Range action.

 

right?

 

I believe that the enum action control you have in the cluster is a typedef.

 

if so, you can open the typedef of the Aktion enum control, edit all the items to have '_<datatye>' in the name.

 

Example:

 

Aktion: 'Set Multimeter Range_float'

 

This will be a one time task and will reflect in the entire code without making much changes.

 

I hope this is useful

Regards
Freelance_LV
TestAutomation Consultant
0 Kudos
Message 2 of 3
(2,501 Views)

From a readability stand point I would recommend that your create subVIs for each message you want to post. It's connector pain will have the proper data type for the data for the specific message. In addition you do not have to wire the ENUM so the calling code doesn't even need to know that. It only needs to know what the message means logically and pass the correct data to it. You are really creating an API for your command set and it should hide specific details from the calling code. By doing so it is easier for you to modify the communication layer without impacting code that uses it.

 

You may also want to look into using LVOOP. You can pass objects as messages and each object will contain the details for the specific message. There are examples of the actor framework which would show you how this can be accomplished.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 3
(2,482 Views)