Search in sources :

Example 6 with RuntimePV

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);
    }
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) VType(org.diirt.vtype.VType) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener) Test(org.junit.Test)

Example 7 with RuntimePV

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);
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV)

Example 8 with RuntimePV

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);
}
Also used : ArrayPVDispatcher(org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) ArrayWidget(org.csstudio.display.builder.model.widgets.ArrayWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) Widget(org.csstudio.display.builder.model.Widget)

Example 9 with RuntimePV

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;
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV)

Example 10 with RuntimePV

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;
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) VType(org.diirt.vtype.VType) CountDownLatch(java.util.concurrent.CountDownLatch) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

Aggregations

RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)21 CountDownLatch (java.util.concurrent.CountDownLatch)6 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)6 List (java.util.List)5 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 WidgetPropertyListener (org.csstudio.display.builder.model.WidgetPropertyListener)4 ArrayPVDispatcher (org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher)4 VType (org.diirt.vtype.VType)4 Test (org.junit.Test)4 Listener (org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher.Listener)3 Collection (java.util.Collection)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Level (java.util.logging.Level)2 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)2 VTypeUtil (org.csstudio.display.builder.model.util.VTypeUtil)2 ROIWidgetProperty (org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty)2