LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding Units in the context of Type Casting and References

Solved!
Go to solution

I could not find any information about this on the forums thus far, but I'm having trouble with passing indicator refnums into a subVI so that I can change the value of the indicator as soon as the change occurs in the subVI.

 

The problem I'm having is this:

In my example VI I have an indicator with a unit label of psi. I set this indicator to 100. I then create a reference and try to pass it into my subVI.

UnitsNReferencesClassConflict.PNG 
Here is the subVI as well:

DigNumRefnum.PNG

With this first attempt I get a class conflict on the wire, which I'm not sure how that is the case as both the reference and the input object of the subVI are DigNum Refnum (strict) types. (Note: the wire is connected to the property node in my subVI the screenshot just didn't capture it for some reason)

So I thought lets go ahead and type cast the input before we pass it to the SubVI, which works:
UnitsNReferences.PNG
However, my VI correctly shows 100 psi on startup on the indicator, but after the 5 second delay of the subVI, 200 is inputted into the value property node, and this shows on the indicator on the main.vi:

200ValueAfterTypeCasting.PNG
If I try to put a unit convertor on the wire between the 200 constant and the value property node I get an error, as the property value node says it has no Units, even though the object I'm referencing does. There seems to be some kind of conversion somewhere along the way with this process that isn't properly displaying the 200 psi I'm trying to get to.

Any assistance anyone could provide would be highly appreciated.

Download All
0 Kudos
Message 1 of 6
(1,461 Views)
Solution
Accepted by darrenlwoodson

When a numeric has units, internally the value is always stored as fundamental units (which for pressure is Pascals).  So when you write to it, you are setting it to 200 Pascals.

You could add psi units to your constant, then convert to Pascals; like this:
p.png

 

Some people might tell you to give up on using units, but I like them, and use them (where appropriate).

For example, if a VI has an input that's a physical quantity, I give it units.

"If you weren't supposed to push it, it wouldn't be a button."
Message 2 of 6
(1,436 Views)

Thank you Paul,

That was exactly it. I knew that LabView handled psi in a default Pa unit and just converted when needed. But I didn't realize the conversion needed to be specified on the constant. In my mind since the object being reference was already set to psi, that when given a value of X LabView would already do the conversion to display the psi value not pascals. In fact I didn't realize until you taught me just now that constants can be given units. 

With the real world application I'm deal with its important to keep track of units (testing manufactured components), but its been a learning curve for sure figuring out how LabView handles these units from component to component. 

This is a life saver so again, thank you Paul!

0 Kudos
Message 3 of 6
(1,432 Views)

Paul, 

You don't happen to have any insight on the reason why a Type Casting was necessary in this case? It would seem to me that the object's reference and the input typing in the SubVI were the same but I'm missing something apparently as the Type Casting was necessary for this example to work.

0 Kudos
Message 4 of 6
(1,431 Views)

@darrenlwoodson wrote:

Paul, 

You don't happen to have any insight on the reason why a Type Casting was necessary in this case? It would seem to me that the object's reference and the input typing in the SubVI were the same but I'm missing something apparently as the Type Casting was necessary for this example to work.


Although the wires look the same, numbers with units are a different data type than numbers without units.  Moreover, each physical quantity is a different data type (e.g a number with length units is a different data type than a number with time units).

"If you weren't supposed to push it, it wouldn't be a button."
Message 5 of 6
(1,395 Views)

@paul_cardinale wrote:

When a numeric has units, internally the value is always stored as fundamental units (which for pressure is Pascals).  So when you write to it, you are setting it to 200 Pascals.

You could add psi units to your constant, then convert to Pascals; like this:
p.png

 

Some people might tell you to give up on using units, but I like them, and use them (where appropriate).

For example, if a VI has an input that's a physical quantity, I give it units.


They do have their place.  I like to use them to "normalize" my calculations.  If one parameter is a pure number of 2.5 and it represents MHz and another parameter is 2.5 but it means 2.5 GHz, I can simply convert them accordingly, do my calculation, the re-convert the answer into a pure number to use wherever.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 6
(1,321 Views)