What to know
In JMobile it is possible to change during runtime the systems of units used by simply applying a dynamic scale factor to the received data.
The example explained in this document shows how to configure an application to use 2 different system of units that can be changed during runtime.
What to do
This example uses a dynamic scale conversion that allows to change the visualization of data from Metric to Imperial Standard, the corresponding Jmobile Studio application can be downloaded from the apposite link placed at the bottom of this page.
The application starts from the assumption that the data received from the PLC are expressed in meters, to display the data in feet the following formula must be applied:
ft = m * 3.2808
These are the Tags used by the application:
– Value: the value received from the PLC, as per our assumptions it contains the measure in meters.
– DistanceScale: The scaling factor applied to the Value tag that determines the conversion between Metric and Imperial systems.
– Units: (optional) a boolean tag used into a message widget that reports the unit of measure, meters “m” or feet “ft”.
Note: For demonstration purposes in the example we use only the Variables protocol.
The conversion between meters and feet applied to the numeric field in page is based on the Scaling feature applied on the Value property of the numeric field itself.
The below image shows the configuration of the Scaling, here a dynamic scale factor has been applied by attaching the DistanceScale tag to the numerator of the scaling formula.
If the DistanceScale tag value is 1 the resulting scaling formula is 1/1 x Value +0 so the tag value does not change.
If, according to the formula reported previously, the DistanceScale tag value is 3.2808 the resulting scaling formula is 3.2808/1 x Value +0, the result of the scaling is the distance value converted in feet units.
The runtime selection of the system of units to be applied is done by setting the DistanceScale tag to the required value using a Write to Controller action programmed in the OnMouseClick event of the buttons in page. The “Metric” button as explained above sets the DistanceScale tag value to 1, the Imperial button sets the value to 3.2808.
The same approach is used to change the Units tag values, so the correct unit of measurement can be displayed into the message field according to the selected system of units.
Applies to
JMobile Studio
Share this Post: