LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Set Value (Signaling) using Displayed Units

Solved!
Go to solution

I'm trying to figure out a good way to use VI Server to set a value (signaling) to a front panel control with the currently chosen units.

 

Normally, via VI Server, it assumes the value being set is in SI units.  So, somehow I need to be able to take the value that I get (as a string) and set it to the control but it needs to be interpretted as the units that were chosen by the user.

 

A potential solution that I found was to set "Numeric Text.Text", get the value, set value with signaling.  This works most of the time but fails under the following scenario:

 

  1. Format set to "%.1f"
  2. Set Units to Visible and set to "m"
  3. Set the value with the above procedure to "1.5"
  4. Displayed value becomes "1.5" and the variable's value is 1.5 m
  5. Set the value with the above procedure to 1.525
  6. Displayed value is still "1.5" and the variable's value is 1.525 m
  7. Set the value with the above procedure to "1.5"
  8. Displayed value is still "1.5" and the variable's value is still 1.525 m

 

Ideally, when I set the value back to "1.5", I need the variable to become 1.5 m.

 

If I do step 7 with the standard UI (with keyboard and mouse to type "1.5" on top of the current "1.5" and hitting enter) the variable value behaves as expected (i.e. the variable's value becomes 1.5 m).

 

Does anyone have any other ideas?

 

 

 

0 Kudos
Message 1 of 12
(5,336 Views)

Hi Nathan,

 

Normally, via VI Server, it assumes the value being set is in SI units.

Which is nice as you minimize unit conversion problems this way!

Everyone should stick with SI units to avoid crashing space probes😄

 

Why don't you set the value using SI units in your BD? LabVIEW will convert automatically to the user-choosen unit on the FP:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 12
(5,303 Views)

Personally, I would love to force my customer to use SI units but I don't have that option in this project.

 

It will not be known what type of unit (lenth, speed, volume, etc.) is being used for a particular control because we are using VI Server to manipulate UI controls from an external application.  The methodology used must be agnostic since the external application will be used on many different applications and controls.  Also, the thing that I'm getting from the "customer" is a string that doesn't have any sort of unit association which is why they want it to assume that the incoming data is of the units currently selected for that control.

 

Currently the only option for us is to use static units (meaning not using UI control unit labels at all) but it makes the UI much less user friendly and can cause issues if we ever need to change the static unit on the UI (because the customer's application will have no way of knowing that it changed).

0 Kudos
Message 3 of 12
(5,264 Views)

Hi Nathan,

 

It will not be known what type of unit (lenth, speed, volume, etc.) is being used for a particular control because we are using VI Server to manipulate UI controls from an external application.

I think it will be hard to change the unit in the runtime as it is part of the datatype of the control!

So your control will have a unit assigned when you create the VI/executable!

Why do you think you will change the unit at runtime?

 

The methodology used must be agnostic since the external application will be used on many different applications and controls.

Then use combinations of numeric display and string for unit. You could even create and use XControls, which do the "hard" part of updating the value internally…

 

Also, the thing that I'm getting from the "customer" is a string that doesn't have any sort of unit association which is why they want it to assume that the incoming data is of the units currently selected for that control.

Another reason to split numeric value and unit into two different things…

 

Conclusion:

- IMHO you should split numeric value from unit, as the unit will be fixed.

- Changing units to a different physical value (like from "m" to "kg") doesn't make any sense once the control is wired in a LabVIEW VI as you would (attempt to) change the datatype at runtime!

- When the user should be able to change the unit (like from "m" to "in") you need to keep track of those changes on your own. I do similar things when reading measurement configuration files to allow additional scalings, so the user can have it's measurement results in g/s when the sensor is calibrated to kg/h…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 12
(5,259 Views)

The physical value is never changing.  It is just the representation that changes.  So, if the unit is gal/h and they send me "1.5" then I need the control's value to be 1.5 gal/h.  If the control unit is L/h and they send me "1.5" then the control's value should be 1.5 L/h.

 

I was hoping to avoid the cumbersome method of managing unit display and conversions in my code since LabVIEW already has this implemented.  The hard part is that I have to set it via VI Server.

 

I was so close to getting this working with the numeric text but since I was able to find the aforementioned flaw in my method so easily, I'm worried that this might end up causing issues at some point down the road.

0 Kudos
Message 5 of 12
(5,251 Views)

A little extension of Gerd's advice. If you need to manipulate data, you need to know what units they are in (not just have them on an indicator). I would convert unit string to typedef and check valid units and their conversion rules. If they send X in meters, Y in grams, want to add them and get result in miles, something is wrong. 

0 Kudos
Message 6 of 12
(5,249 Views)

Yes, I understand your problem. Setting the same numeric text does not update value if new text is the same as old one.

Simple way is to extend numeric text up and set numeric.text property to INF. This resets value and second numeric text sets always updates value.

0 Kudos
Message 7 of 12
(5,243 Views)

My advice would be stay well clear of built in units in LabVIEW. They are far more hassle than they are worth.

 

Example:

 

Take a control of unit [m] multiply it by itself for result of [m^2] as expected.

 

Take a control of unit [m] and pass it to the square primitive and result unit is still [m].

 

There are loads of other instances of similar garbage. Give it a miss.

 

 

Message 8 of 12
(5,238 Views)

I understand the limitations of doing math with LabVIEW built-in units.  In my case, I will never do math on variables that have units associated with them.  I am only using them for the UI.  On my block diagram, I always convert them to my preferred unit immediately (giving me a non-unit variable).  For example, I will always do calculations in m, kg, s so I convert my UI controls to this unit and then do calculations on that.

 

In this respect, units work great (for UI only).  The problem comes when I need to do stuff with VI Server.

0 Kudos
Message 9 of 12
(5,217 Views)
Solution
Accepted by NathanJD

This works, if I understand your problem correct. First text resets value, second sets the one you need.

Property node is supposed to be linked to Numeric.

value through text.png

0 Kudos
Message 10 of 12
(5,213 Views)