beautypg.com

ProSoft Technology ProSoft i-View User Manual

Page 59

background image

ProSoft i-View ♦ Mobile Process Monitoring and Control Application

Data Source Files

Version 2.0.2

User Manual

ProSoft Technology, Inc.

Page 59 of 106

September 29, 2011

In this case we extract separately the hours, minutes and seconds as numeric values
from the string, we multiply them by 3600, 60 and 1 respectively and then sum them to
get the total number of seconds. The extraction of each value from the original string is
performed by the split method using ‘:’ as delimiter. The relevant element from the split
array is obtained with the fetch method. We use 0 as the default value for fetching.
Note that we could have used simple array indexing such as t.split(":")[-3] to get each
part of the original string but this would lead to potential out of bound errors if the original
string had some missing part. Particularly, if the original string did only contain minutes
and seconds, such as "50:30" ( 50 minutes, 30 seconds) the referred indexed expression
would give an out of bounds error as it would attempt to access a non existing element
(the one before the first one). Note also that in all cases we use negative indexing
because we interpret that the last part is always meant to be the seconds, the previous to
the last one the minutes and so on.
The proposed expression can be optionally optimized by storing the split string in a
temporary variable so that the splitting is only performed once. If we apply this
optimization.the final solution would look as follows:


tspt

STRING[3]

INTERNAL

value = t.split(":") ;

seconds DINT

INTERNAL

value = 3600*tspt.fetch(-

3,0).to_i + 60*tspt.fetch(-2,0).to_i + tspt.fetch(-1,0).to_i;

Creating a row that alternates between displaying the current time and an
arbitrary value

In this example we will create a row that shows a living digital clock showing the current
time. Every 5 seconds the time is alternated with a temperature value given in a variable
named temp. In order to achieve this we enter the following expression in a row.

value = $SMPulse10s ? "Time: "+$SMDate.split(" ")[1] : "Temperature: "+temp.to_s("%3.1f")+" ºC" ;

We use the ternary operator to switch between the time and the temperature depending
on the $SMPulse10 system pulse variable. For the clock we take $SMDate and discard
the date portion by splitting it out. The temperature is presented formatted with a custom
prefix and suffix appended to the actual value. We can alternatively use the format
function to simplify a bit some portions of the expression


value = $SMPulse10s ? format("Time: %s", $SMDate.split(" ")[1]) : format("Temp: %3.1f F",

9/5*celsius+32) ;