/** {@inheritDoc} */ @Override public void dispose() { if (pv != null) pv.close(); super.dispose(); }
public void setPVFormula(String pvFormula) { log.log(Level.FINE, "setPVFormula ({0})", pvFormula); // $NON-NLS-1$ // If we are already scanning that pv, do nothing if (this.pvFormula != null && this.pvFormula.equals(pvFormula)) { return; } this.pvFormula = pvFormula; // The PV is different, so disconnect and reset the visuals if (pv != null) { pv.close(); pv = null; } valuePanel.changeValue(null, false); changeValuePanel.reset(); metadataPanel.changeValue(null); detailsPanel.changeValue(null, null); viewerPanel.changeValue(null); setLastError(null); copyValueAction.setEnabled(false); // If name is blank, update status to waiting and quit if ((pvFormula == null) || pvFormula.trim().isEmpty()) { setStatus(Messages.Probe_statusWaitingForPV); pvFormula = null; } // Update displayed name, unless it's already current if (!(Objects.equals(pvFomulaInputBar.getPVFormula(), pvFormula))) { pvFomulaInputBar.setPVFormula(pvFormula); } if (pvFormula != null) { setStatus(Messages.Probe_statusSearching); DesiredRateReadWriteExpression<?, Object> expression = formula(pvFormula); pv = PVManager.readAndWrite(expression) .timeout(ofMillis(5000), Messages.Probe_retryAfterTimeout) .readListener( new PVReaderListener<Object>() { @Override public void pvChanged(PVReaderEvent<Object> event) { Object value = event.getPvReader().getValue(); setLastError(event.getPvReader().lastException()); viewerPanel.changeValue(value); if (event.getPvReader().isConnected()) { setStatus(Messages.Probe_statusConnected); } else { setStatus(Messages.Probe_statusSearching); } valuePanel.changeValue(value, event.getPvReader().isConnected()); metadataPanel.changeValue(value); copyValueAction.setEnabled(export.canExport(value)); } }) .readListener(changeValuePanel.getReaderListener()) .writeListener(changeValuePanel.getWriterListener()) .notifyOn(swtThread(this)) .asynchWriteAndMaxReadRate(ofHertz(25)); changeValuePanel.setPvWriter(pv); // Show the PV name as the title setPartName(pvFormula); detailsPanel.changeValue(expression, pvFormula); } }