Search in sources :

Example 6 with RuntimePVListener

use of org.csstudio.display.builder.runtime.pv.RuntimePVListener in project org.csstudio.display.builder by kasemir.

the class XYPlotWidgetRuntime method bindMarker.

private void bindMarker(final WidgetProperty<String> name_prop, final WidgetProperty<Double> value_prop) {
    final String pv_name = name_prop.getValue();
    if (pv_name.isEmpty())
        return;
    logger.log(Level.FINER, "Connecting {0} to Marker PV {1}", new Object[] { widget, pv_name });
    try {
        final RuntimePV pv = PVFactory.getPV(pv_name);
        addPV(pv);
        marker_pvs.add(pv);
        // Write value changes to the PV
        final WidgetPropertyListener<Double> prop_listener = (prop, old, value) -> {
            // Ignore if PV already has same value to break update loops
            double pv_value = VTypeUtil.getValueNumber(pv.read()).doubleValue();
            if (value == pv_value)
                return;
            try {
                // System.out.println("Writing " + value_prop + " to PV " + pv_name);
                pv.write(value);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Error writing marker value to PV " + pv_name, ex);
                // Restore property to the unchanged value of the PV
                value_prop.setValue(pv_value);
            }
        };
        value_prop.addPropertyListener(prop_listener);
        marker_prop_listeners.put(value_prop, prop_listener);
        // Write PV updates to the value
        final RuntimePVListener pv_listener = new RuntimePVListener() {

            @Override
            public void valueChanged(final RuntimePV pv, final VType value) {
                final double number = VTypeUtil.getValueNumber(value).doubleValue();
                if (number == value_prop.getValue())
                    return;
                // System.out.println("Writing " + number + " from PV " + pv_name + " to " + value_prop);
                value_prop.setValue(number);
            }
        };
        pv.addListener(pv_listener);
        marker_pv_listeners.put(pv, pv_listener);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Error connecting Marker PV " + pv_name, ex);
    }
}
Also used : VTypeUtil(org.csstudio.display.builder.model.util.VTypeUtil) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WidgetRuntime(org.csstudio.display.builder.runtime.WidgetRuntime) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener) PVFactory(org.csstudio.display.builder.runtime.pv.PVFactory) RuntimePlugin.logger(org.csstudio.display.builder.runtime.RuntimePlugin.logger) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) PVNameToValueBinding(org.csstudio.display.builder.runtime.PVNameToValueBinding) List(java.util.List) XYPlotWidget(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget) Map(java.util.Map) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) TraceWidgetProperty(org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.TraceWidgetProperty) RuntimeAction(org.csstudio.display.builder.runtime.RuntimeAction) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) MarkerProperty(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget.MarkerProperty) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

Aggregations

RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)6 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)6 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)4 WidgetPropertyListener (org.csstudio.display.builder.model.WidgetPropertyListener)4 VType (org.diirt.vtype.VType)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Level (java.util.logging.Level)2 VTypeUtil (org.csstudio.display.builder.model.util.VTypeUtil)2 ROIWidgetProperty (org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty)2 TraceWidgetProperty (org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.TraceWidgetProperty)2 PVNameToValueBinding (org.csstudio.display.builder.runtime.PVNameToValueBinding)2 RuntimeAction (org.csstudio.display.builder.runtime.RuntimeAction)2 RuntimePlugin.logger (org.csstudio.display.builder.runtime.RuntimePlugin.logger)2 WidgetRuntime (org.csstudio.display.builder.runtime.WidgetRuntime)2