LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to convert reference of control to strict?

Solved!
Go to solution

I am trying to initialize couple numeric controls with setting default value, min, max and tipstrip text (tell min and max value). These numeric controls can be either floating point (DBL) or integer (Int32). Tipstrip of floating point numeric control should show value with fractional string while tipstrip of integer numeric control should show value with decimal string. I created 2 specific vis and a polymorphic vi for this purpose. Now I try to use the polymorphic vi with an array of digital controls (including dbl and int32 data type). The wire is broken because the source is not strict data type while the destination data type is strict. I guess because it is from polymorphic vi. I wonder how should I solve this issue. Should I somehow convert the input wire to strict type? Currently, I don't know how to do this.

 

Any recommend is welcome.

0 Kudos
Message 1 of 15
(5,745 Views)

Before your Test Setting Default and Limits vi, you combine your references into an array. You may notice some dots on that array, you are coercing those references to generic references. You need to go back to specific reference so you have two options:

  1. In you settings subVI, right-click the DigNum Reference and uncheck "include data type".
  2. Use Type Cast to convert to a strict type for each reference.

Choice 1 is much easier, choice 2 you need to make a case for each kind of reference, once I did choice 1 your VI works.

 

mcduff

 

EDIT: Including a picture, similar to your case.

 

Snap9.png

0 Kudos
Message 2 of 15
(5,715 Views)

@mcduff: I removed data type as your suggestion and use type cast inside the sub vi, but this make the main vi always call the same vi does not matter if the control is dbl or int. I attach the block diagram of 2 sub vis. Please correct me if I am wrong.

0 Kudos
Message 3 of 15
(5,691 Views)

Remove the typecast in your diagram, not needed if you remove data type. The beauty of removing the data type is that you no longer need a polymorphic VI, one subVI to rule them all, that is, it will work for any numeric data type.

 

Type cast would be used if and only if you want to keep "strict" references. So the reference on the type cast would have to include the data type. Then you would need a polymorphic subVI and choose the correct instance in a loop. 

 

Not including the data type is a lot simpler and easier to maintain.

 

mcduff

0 Kudos
Message 4 of 15
(5,685 Views)

@mcduff: The reason I included the datatype originally is that I don't want to show the decimal point in the tip strip text when the control has integer format.

0 Kudos
Message 5 of 15
(5,682 Views)

Just passing through...

 

In This Nugget I offered some ideas how to test control references using a trial and error method.

 

If it does not help then please ignore this post.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 15
(5,672 Views)

@Ben,

I would like to know how to set reference constant to strict in your link.

 

 

0 Kudos
Message 7 of 15
(5,667 Views)
Solution
Accepted by NTT

@NTT wrote:

@mcduff: The reason I included the datatype originally is that I don't want to show the decimal point in the tip strip text when the control has integer format.


I think you can do this to get rid of the decimal point, and it should also work with the integer case. I would include the rounding. This should work for a generic reference, that is, one that does not include the data type.

 

mcduff

 

Snap12.png

Message 8 of 15
(5,665 Views)
Solution
Accepted by NTT

Switch to "To More Specific Class" instead of "Type Cast". It will throw an error if the reference is the wrong class. You will have to have nested structures to determine which class to use. I think you can also use a VIM with a Type Specialization Structure but I haven't tried those yet.

 

I attached a proof of concept. Basically, you can try to coerce the refnum to the more specific class, and if it works, you know it's that class. In my code I only have 2 types, so I know if it throws an error it's the other type. I run different code depending on if the error is thrown or not.

 

Edit: Whoops, looks like I'm late to the game. I'll leave it here, maybe it'll help. To answer your "how to get that reference" question, right click the reference wire and click "Create Constant"

Message 9 of 15
(5,663 Views)

If you go down the route of going to a more specific class, then your "For loop" in one of the VIs that you uploaded would need a case structure in the loop in order to pick the correct class.

 

Someone wise on these forums says, "do more with less code." I suggest you follow that advice.

 

mcduff

 

Snap13.png

0 Kudos
Message 10 of 15
(5,650 Views)