02-13-2019 11:29 AM
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.
Solved! Go to Solution.
02-13-2019 02:31 PM - edited 02-13-2019 02:34 PM
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:
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.
02-14-2019 08:44 AM
@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.
02-14-2019 09:54 AM
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
02-14-2019 10:05 AM
@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.
02-14-2019 10:33 AM
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
02-14-2019 10:42 AM
@Ben,
I would like to know how to set reference constant to strict in your link.
02-14-2019 10:44 AM
@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
02-14-2019 10:46 AM - edited 02-14-2019 10:48 AM
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"
02-14-2019 10:57 AM
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