From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
11-11-2012 12:20 PM - edited 11-11-2012 12:20 PM
I have not used a variant before, normally I use a cluster containing a string(with state info) and enum (with states) to pass data between a producer and a consumer.loop. But I fail to understand the use of variant (usually instead of strings) in such cases. Can anyone please explain to me the motivation behind using variants (specially in a producer consumer design pattern)? I knw that primarily they are used to convert from one data type to another,but how does that help ? can you pass the data using a variant?
I tried to experiment with the variant but to no avail,I keep getting this error "The data type of variant is not compatible with the data type wired to the type input" -
I know these are too many questions, but if anyone have a VI i could use to understand the concept behind variant, it would be great.
Thanks
Solved! Go to Solution.
11-11-2012 12:56 PM
We cannot really troubleshoot this from a picture, please attach the actual VI instead.
You enqueue a cluster containing an empty variant, but then try to read is as a variant containing I32. Try to convert a I32 numeric value to a variant before enqueueing or simply ignore the variant in the start case.
11-11-2012 01:05 PM
sorry for that.
Yes I can see that, can you please elaborate?
11-11-2012 02:55 PM
Here's a quick illustration.
You can see that the various commands have different data type (I32, string, boolean, resp.) and the consumer loop handles them accordingly.
Whan you convert from variant you need to match the type of the data.
(Also note that latch action booleans belong inside their event case, else they don't properly reset.)
11-11-2012 04:56 PM
Thank you so much. This helped a lot.