LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data types in producer consumer design pattern

Solved!
Go to solution

Is there a way for me to use any data type in a producer consumer design pattern, without specifying that specific data type?

what I mean is if there is a way to connect a data type with which I can use any other data type besides the one I connected, and if not, how can I specify the data type for a number or any other type of data, to use in a producer consumer design pattern?

0 Kudos
Message 1 of 4
(2,806 Views)
Solution
Accepted by topic author Nando88

You can make an element in your data cluster a variant.  That will take any type of data.  A common architecture for producer/consumer is a cluster that is an enum and a variant.  The enum contains all the possible "commands" you might want to send.  The variant contains the data that could be of any type.

 

In the consumer, you unbundle and get the enum and variant.  Tie the enum to a case structure.  Inside the specific case, convert the variant back into a regular LabVIEW datatype and do with it as you please.

0 Kudos
Message 2 of 4
(2,800 Views)

could you give me an example of how would I use a variant?

thanks.

0 Kudos
Message 3 of 4
(2,791 Views)

RavensFan described everything so you can create the mentioned typedef cluster with an enum and a variant inside.

I only show here how to convert your data into variant in the producer loop before inserting the cluster value into the Queue, and how to convert it back in an actual case in the consumer loop:

 

Example_VI_BD.png

0 Kudos
Message 4 of 4
(2,752 Views)