use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.
the class PVFactoryTest method testPVFactory.
@Test
public void testPVFactory() throws Exception {
final RuntimePV pv = PVFactory.getPV("loc://test(3.14)");
try {
// vtype.pv uses the base name, without initializer
assertThat(pv.getName(), equalTo("loc://test"));
final CountDownLatch updates = new CountDownLatch(1);
final AtomicReference<Number> number = new AtomicReference<>();
RuntimePVListener listener = new RuntimePVListener() {
@Override
public void valueChanged(RuntimePV pv, VType value) {
System.out.println(pv.getName() + " = " + value);
number.set(VTypeUtil.getValueNumber(value));
updates.countDown();
}
};
pv.addListener(listener);
updates.await();
assertThat(number.get(), equalTo(3.14));
} finally {
PVFactory.releasePV(pv);
}
}
use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.
the class PVNameToValueBinding method connect.
private void connect() {
final String pv_name = name.getValue();
if (pv_name.isEmpty()) {
listener.valueChanged(null, PVWidget.RUNTIME_VALUE_NO_PV);
return;
}
logger.log(Level.FINE, "Connecting {0} {1}", new Object[] { name.getWidget(), name });
final RuntimePV pv;
try {
pv = PVFactory.getPV(pv_name);
} catch (Exception ex) {
logger.log(Level.WARNING, "Cannot connect to PV " + pv_name, ex);
return;
}
pv.addListener(listener);
runtime.addPV(pv, need_write_access);
pv_ref.set(pv);
}
use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.
the class ArrayWidgetRuntime method start.
@Override
public void start() throws Exception {
super.start();
RuntimePV pv = getPrimaryPV().orElse(null);
if (pv != null)
dispatcher = new ArrayPVDispatcher(pv, pvid, assign_pv_names);
for (final Widget child : widget.runtimeChildren().getValue()) RuntimeUtil.startRuntime(child);
widget.runtimeChildren().addPropertyListener(children_listener);
}
use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.
the class ScriptUtil method getPVByName.
/**
* Get widget's PV by name
*
* <p>Locates widget's PV by name, including the primary PV
* as well as PVs from scripts and rules.
*
* @param widget Widget to get PV from
* @param name Name of PV to get
* @return PV of given widget with given name; otherwise, if not found,
* <code>null</code>
*/
public static RuntimePV getPVByName(final Widget widget, final String name) {
final Collection<RuntimePV> pvs = getPVs(widget);
for (RuntimePV pv : pvs) if (name.equals(pv.getName()))
return pv;
logger.warning("Could not find PV with name '" + name + "' for " + widget);
return null;
}
use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.
the class PVUtil method createPV.
/**
* Create a PV.
*
* <p>Ideally, scripts use the PVs of widgets or the script 'input' PVs,
* where the display runtime handles the PV connection.
* In rare cases it might be necessary to create a PV in a script,
* in which case the script <b>must</b> then also release the PV.
*
* @param pv_name Mame of the PV
* @param timeout Connection timeout in milliseconds
* @return PV
* @throws Exception on error
* @see #releasePV(RuntimePV)
*/
public static RuntimePV createPV(final String pv_name, final int timeout_ms) throws Exception {
final CountDownLatch connected = new CountDownLatch(1);
final RuntimePVListener await_connection = new RuntimePVListener() {
@Override
public void valueChanged(final RuntimePV pv, final VType value) {
if (value != null)
connected.countDown();
}
};
final RuntimePV pv = PVFactory.getPV(pv_name);
pv.addListener(await_connection);
try {
if (!connected.await(timeout_ms, TimeUnit.MILLISECONDS)) {
PVFactory.releasePV(pv);
throw new Exception("Failed to connect to '" + pv_name + "' within " + timeout_ms + " ms");
}
} finally {
pv.removeListener(await_connection);
}
return pv;
}
Aggregations