Access PV in Script

pvArray

The input PVs for a script can be accessed in script via pvArray object. The order of the input PVs in the configuation list is preserved in pvArray. pvArray[0] is the first input pv. If you have N input PVs, pvArray[N-1] is the last input PV.

In script, you can read/write the input PVs and get the timestamp or severitis of the PVs via the utility APIs provided in PVUtil

Examples:

1. Get double value from PV

importPackage(Packages.org.csstudio.opibuilder.scriptUtil);

var value = PVUtil.getDouble(pvArray[0]);
widgetController.getWidgetModel().setPropertyValue("start_angle", value);

2. Write PV Value

Only the input PVs are allowed to write in the script. If writing a PV is forbidden by PV security, an exception will be returned and shown in console. The method PV.setValue(data) accepts Double, Double[], Integer, String, maybe more.

importPackage(Packages.org.csstudio.platform.data);
pvArray[0].setValue(0);	

3. Get severity of PV

importPackage(Packages.org.csstudio.opibuilder.scriptUtil);

var RED = ColorUtil.RED;
var ORANGE = ColorUtil.getColorFromRGB(255,255,0);
var GREEN = ColorUtil.getColorFromHSB(120.0,1.0,1.0);
var PINK = ColorUtil.PINK;

var severity = PVUtil.getSeverity(pvArray[0]);
var color;

switch(severity){
	case 0:  //OK
		color = GREEN;
		break;
	case 1:  //MAJOR
		color = RED;
		break;
	case 2:  //MINOR
		color = ORANGE;
		break;
	case -1:  //INVALID
	default:
		color = PINK;
}

widgetController.getWidgetModel().setPropertyValue("foreground_color",color);