Package org.yamcs.studio.script
Class PVUtil
java.lang.Object
org.yamcs.studio.script.PVUtil
- Direct Known Subclasses:
PVUtil
The utility class to facilitate Javascript programming for PV operation.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic VType
checkPVValue
(IPV pv) Check PV for valuestatic final IPV
createPV
(String name, AbstractBaseEditPart widget) Create a PV and start it.static final double
Try to get a double number from the PV.static final double
Try to get a double-typed array element from the Value.static final double[]
getDoubleArray
(IPV pv) Try to get a double-typed array from the pv.static final String[]
Get the list of Enum valuesstatic final Long
Try to get a long integer number from the PV.static final long[]
getLongArray
(IPV pv) Try to get an integer-typed array from the pv.static final int
getSeverity
(IPV pv) Get severity of the pv as an integer value.static final String
getSeverityString
(IPV pv) Get severity of the PV as a string.static final double
Get the size of the pv's valuestatic final String
Get the status text that might describe the severity specific to the type of PV.static final String
Converts the given pv's value into a string representation.static final String[]
getStringArray
(IPV pv) Get string array from pv.static final double
Get milliseconds since epoch, i.e. 1 January 1970 0:00 UTC.static final String
getTimeString
(IPV pv) Get the timestamp string of the pvstatic final String
getTimeString
(IPV pv, String formatPattern) Get the timestamp string of the pvstatic String
Try to get the units from the PV.static final void
Write a PV in a background job.static final void
Write a PV in a background job.
-
Constructor Details
-
PVUtil
public PVUtil()
-
-
Method Details
-
createPV
Create a PV and start it. PVListener can be added to the PV to monitor its value change, but please note that the listener is executed in non-UI thread. If the code need be executed in UI thread, please useScriptUtil.execInUI(Runnable, AbstractBaseEditPart)
. The monitor's maximum update rate is 50hz. If the PV updates faster than this rate, some updates will be discarded.- Parameters:
name
- name of the PV.widget
- the reference widget. The PV will stop when the widget is deactivated, so it is not needed to stop the pv in script.- Returns:
- the PV.
- Throws:
Exception
- the exception that might happen while creating the pv.
-
getDouble
Try to get a double number from the PV.Some applications only deal with numeric data, so they want to interprete integer, enum and double values all the same.
- Parameters:
pv
- the PV.- Returns:
- A double, or
Double.NaN
in case the value type does not decode into a number, orDouble.NEGATIVE_INFINITY
if the value's severity indicates that there happens to be no useful value.
-
checkPVValue
Check PV for value- Parameters:
pv
- PV- Returns:
- Value of PV
- Throws:
NullPointerException
- if value is null
-
getLong
Try to get a long integer number from the PV.Some applications only deal with numeric data, so they want to interprete integer, enum and double values all the same.
- Parameters:
pv
- the PV.- Returns:
- A long integer.
-
getDouble
Try to get a double-typed array element from the Value.- Parameters:
pv
- The PV.index
- The array index, 0 ... getSize()-1.- Returns:
- A double, or
Double.NaN
in case the value type does not decode into a number, orDouble.NEGATIVE_INFINITY
if the value's severity indicates that there happens to be no useful value.
-
getDoubleArray
Try to get a double-typed array from the pv.- Parameters:
pv
- the pv.- Returns:
- A double array, or an empty double array in case the value type does not decode into a number, or if the value's severity indicates that there happens to be no useful value.
-
getStringArray
Get string array from pv.- Parameters:
pv
- The PV.- Returns:
- String array. For string array, it's the actual strings. For numeric arrays, the numbers are formatted as strings. For enum array, the labels are returned. For scalar PVs, an array with a single string is returned.
-
getLongArray
Try to get an integer-typed array from the pv.- Returns:
- A long integer array, or an empty long integer array in case the value type does not decode into a number, or if the value's severity indicates that there happens to be no useful value.
-
getSize
Get the size of the pv's value- Returns:
- Array length of the pv value.
1
for scalars.
-
getString
Converts the given pv's value into a string representation. For string values, returns the value. For numeric (double and long) values, returns a non-localized string representation. Double values use a point as the decimal separator. For other types of values, the value's IValue#format() method is called and its result returned.- Returns:
- a string representation of the value.
-
getTimeString
Get the timestamp string of the pv- Returns:
- the timestamp in string.
-
getTimeString
Get the timestamp string of the pv- Parameters:
pv
- the PvformatPattern
- format pattern in the form ofDateTimeFormatter
- Returns:
- the timestamp in string.
-
getTimeInMilliseconds
Get milliseconds since epoch, i.e. 1 January 1970 0:00 UTC.Note that we always return milliseconds relative to this UTC epoch, even if the original control system data source might use a different epoch (example: EPICS uses 1990), because the 1970 epoch is most compatible with existing programming environments.
- Returns:
- milliseconds since 1970.
-
getSeverity
Get severity of the pv as an integer value.- Returns:
- 0:OK; -1: Invalid or Undefined; 1: Major; 2:Minor.
-
getSeverityString
Get severity of the PV as a string.- Parameters:
pv
- the PV.- Returns:
- The string representation of the severity.
-
getStatus
Get the status text that might describe the severity specific to the type of PV.For a Yamcs parameter this can be the value LOW or HIGH.
- Returns:
- the status string.
-
getUnits
Try to get the units from the PV. -
writePV
Write a PV in a background job. It will first creates and connects to the PV. After PV is connected, it will set the PV with the value. If it fails to write, an error dialog will pop up.- Parameters:
pvName
- name of the PV.value
- value to write.timeout
- maximum time to try connection.
-
writePV
Write a PV in a background job. It will first creates and connects to the PV. After PV is connected, it will set the PV with the value. If it fails to write, an error dialog will pop up. The maximum time to try connection is 10 second.- Parameters:
pvName
- name of the PV.value
- value to write.
-
getLabels
Get the list of Enum values- Parameters:
pv
- the PV.- Returns:
- the list of values into a string array
-