LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Malleable VI to parse generic message clusters (string+variant)

Solved!
Go to solution

I often use the usual approach to broadcast messages: a cluster with a string and a variant. Even if not really required, I still make these clusters into type defined controls to preserve the naming, which can be handy if we want to change names at once (like when names are important at User Events, etc.).

 

So when a certain code part/ module gets a message, it needs to parse out the string and the data, then convert the variant into the expected data type (I know OOP approach is much better since you can do the data type conversion in compile time instead of runtime, but this is not the question now).

To save the valuable BD space, I like to wrap up often repeated steps into subVIs. I thought using a malleable VI (.vim) could be practical here. See the snippets below. 

 

Actually I did not know a feature of vims: even if I connect a typdef cluster to the general cluster input of my vim, it adapts to it without coercion dot.

Besides, I would like to ask, what is your opinion about such approach? Is this a proper way to parse these generic typdef message clusters (I have multiple such typedefs throughout my project libraries)?

 

VIM:

 

Communications.lvlib_Message_cluster_parsing_BD.png

 

parseexample.png

 

edit:

This is a bit better, since often a message consists of a single string without data:

 

vim2.png

 

 

0 Kudos
Message 1 of 4
(2,982 Views)

Actually using that "Empty string/path" for the Data Type input is silly, since not all types will be accepted then. Some workarounds are in my mind, the most simple is to have a Boolean input terminal to request or not Data parsing from the cluster...

This is important, since first we need to get the string, get into a Case Structure, where we can decide the required data type... Actually I do not know if I saved any BD space by now... Smiley Very Happy

 

new111.png

 

new3333.png

0 Kudos
Message 2 of 4
(2,964 Views)
Solution
Accepted by topic author Blokk

Seems like you are just running in circles.  I say the VIM is not needed since you are really just making more work for yourself with little to no gain.  You could make a VI that just does the Unbundle, but that just seems silly.  And then all you need for the data is Variant To Data, again seems silly to make another VI(M) just for one node.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 4
(2,946 Views)

@crossrulz wrote:

Seems like you are just running in circles.  I say the VIM is not needed since you are really just making more work for yourself with little to no gain.  You could make a VI that just does the Unbundle, but that just seems silly.  And then all you need for the data is Variant To Data, again seems silly to make another VI(M) just for one node.


Yes, I had this feeling. So instead of using two times this .vim, I use the same number of elements simply: an "unbundle by name" and a "Variant to Data" 🙂

So actually I did not gain anything, haha 😄

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