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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Code Review

Consider some of the following improvements:

 

jyang72211.png

 

1. Terminals outside the case structures allow "inplace-ness" for dataflow from the parent diagram into the SubVI.

2. The Variant array is using a Build Array inside the loop. Typically, try not to do this, since you're making a call to the Memory Manager each time. It's better to preallocate arrays, or in your case, autoindexing the output should be used since the output dimension matches the auto-indexed input dimensions.

3. All of the code in every case was identical except for the polymorphic VI and consequently the datatype of the wire going into the To Variant. I have created a sequence structure around what should become one SubVI. That VI takes "Type" as an argument, and inside that one VI is a single case structure with multiple cases to handle your type conversions. Note that the sequence structure represents a functional block with identical inputs (Type, and data) and outputs (Variant Array). This is good news, meaning you can get rid of the polymorphic VI and replace it with just one VI.

4. Note that on Loops and Structures you can click "Visible Items > Label" to type descriptive comments of what's going on inside.

0 Kudos
Message 11 of 14
(581 Views)

Hi Jack,

 

A lot of good comments.

 

2. good catch.

3. The subvi that would get types and handle all the cases is the subvi that I have attached.  So after all, I have to make a subvi that has many cases, right?

4. I love the visible label for structure.  I forgot about that somehow, thanks for reminding me. 

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 12 of 14
(560 Views)

Jack's basically done what i suggested (+1 clever detail in autobuilding the array), he's sending out a Variant from the sub-vi, thus it can be polymorphic and have identical outputs. Since you're building a variant array to allow for a mix of datatypes (as i understand it), it's logical to use variant as output from the sub-vi. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 13 of 14
(549 Views)

Yamaeda wrote:

"thus it can be polymorphic"


The SubVI doesn't need to be polymorphic, but it will have several cases, yes, because this is one of the caveats of having several datatypes. If you upload an image and the code of a couple of those subVI's, we may even be able to get rid of the cases.

 

My biggest curiosity is the purpose of this VI altogether. It starts off with an encoded array of data, and you end up with an encoded array of data. I wonder if this whole operation could be simplified, looking at the processes that use this VI?

0 Kudos
Message 14 of 14
(536 Views)