diff --git a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java index 9a83ccf5..8a9bad52 100644 --- a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java +++ b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java @@ -42,12 +42,10 @@ import java.util.*; */ public class PKT8Device extends PortSensor { - private static final String[] CHANNEL_DESIGNATIONS = {"a", "b", "c", "d", "e", "f", "g", "h"}; - public static final String PGA = "pga"; public static final String SPS = "sps"; public static final String ABUF = "abuf"; - + private static final String[] CHANNEL_DESIGNATIONS = {"a", "b", "c", "d", "e", "f", "g", "h"}; /** * The key is the letter (a,b,c,d...) as in measurements */ @@ -77,6 +75,7 @@ public class PKT8Device extends PortSensor { } super.init(); + //update parameters from meta if (meta().hasValue("pga")) { getLogger().info("Setting dynamic range to " + meta().getInt("pga")); @@ -95,9 +94,11 @@ public class PKT8Device extends PortSensor { @Override public void shutdown() throws ControlException { + if (collector != null) { + collector.clear(); + collector = null; + } super.shutdown(); - collector.clear(); - collector = null; } @Override @@ -154,7 +155,7 @@ public class PKT8Device extends PortSensor { private String spsToStr(int sps) { switch (sps) { case 0: - return "2,5 SPS"; + return "2.5 SPS"; case 1: return "5 SPS"; case 2: @@ -196,9 +197,9 @@ public class PKT8Device extends PortSensor { case 4: return "± 312.5 mV"; case 5: - return "± 156,25 mV"; + return "± 156.25 mV"; case 6: - return "± 78,125 mV"; + return "± 78.125 mV"; default: return "unknown value"; } @@ -274,6 +275,10 @@ public class PKT8Device extends PortSensor { return this.getMeasurement(); } else { try { + if (getHandler().isLocked()) { + getLogger().error("Breaking hold on handler because it is locked"); + getHandler().breakHold(); + } return new PKT8Measurement(getHandler()); } catch (ControlException e) { throw new MeasurementException(e); @@ -286,11 +291,12 @@ public class PKT8Device extends PortSensor { //clearing PKT queue try { getHandler().send("p"); - getHandler().sendAndWait("p", null, 1000); + getHandler().sendAndWait("p", 400); } catch (ControlException e) { + getLogger().error("Failed to clear PKT8 port"); // throw new MeasurementException(e); } - if(collector == null){ + if (collector == null) { setupStorage(); } return super.startMeasurement(); @@ -307,6 +313,10 @@ public class PKT8Device extends PortSensor { @Override public void start() { + if (isStarted()) { + getLogger().warn("Trying to start measurement which is already started"); + } + try { handler.holdBy(this); handler.send("s"); @@ -314,20 +324,26 @@ public class PKT8Device extends PortSensor { } catch (PortException ex) { error("Failed to start measurement", ex); } + } @Override public boolean stop(boolean force) throws MeasurementException { + if (isFinished()) { + getLogger().warn("Trying to stop measurement which is already stopped"); + } + try { - getHandler().send("p"); - if (collector != null) { - collector.clear(); - } - return true; + String response = getHandler().sendAndWait("p", 400).trim(); + // Должно быть именно с большой буквы!!! + return "Stopped".equals(response) || "stopped".equals(response); } catch (Exception ex) { error(ex); return false; } finally { + if (collector != null) { + collector.clear(); + } handler.unholdBy(this); } } @@ -338,8 +354,8 @@ public class PKT8Device extends PortSensor { String trimmed = message.trim(); if (isStarted()) { - if (trimmed.equals("stopped")) { - afterStop(); + if (trimmed.equals("Stopped") || trimmed.equals("stopped")) { + afterPause(); getLogger().info("Measurement stopped"); } else { String designation = trimmed.substring(0, 1); @@ -354,7 +370,6 @@ public class PKT8Device extends PortSensor { } else { result(new PKT8Result(designation, rawValue, -1)); } - setMeasurementState(MeasurementState.OK); } } } diff --git a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java index ae569d17..360ee258 100644 --- a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java +++ b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java @@ -15,7 +15,6 @@ */ package inr.numass.cryotemp; -import hep.dataforge.context.GlobalContext; import hep.dataforge.control.devices.Device; import hep.dataforge.control.devices.DeviceListener; import hep.dataforge.control.measurements.Measurement; @@ -33,6 +32,8 @@ import hep.dataforge.plots.fx.FXPlotFrame; import hep.dataforge.plots.fx.PlotContainer; import hep.dataforge.plots.jfreechart.JFreeChartFrame; import hep.dataforge.values.Value; +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -58,18 +59,17 @@ import java.util.ResourceBundle; public class PKT8MainViewController implements Initializable, DeviceListener, MeasurementListener, AutoCloseable { public static final String DEFAULT_CONFIG_LOCATION = "devices.xml"; + ConsoleFragment consoleFragment; private PKT8Device device; private FXPlotFrame plotFrame; private TimePlottableGroup plottables; - private Meta currentPlotConfig; - - ConsoleFragment consoleFragment; - @FXML private Button loadConfigButton; @FXML private ToggleButton startStopButton; @FXML + private ToggleButton rawDataButton; + @FXML private AnchorPane plotArea; @FXML private ToggleButton consoleButton; @@ -89,6 +89,17 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me setupPlotFrame(null); this.consoleFragment = new ConsoleFragment(); consoleFragment.bindTo(consoleButton); + rawDataButton.selectedProperty().addListener(new InvalidationListener() { + @Override + public void invalidated(Observable observable) { + if (plotFrame != null) { + setupPlotFrame(plotFrame.getConfig()); + if (device != null) { + setupChannels(); + } + } + } + }); } @FXML @@ -96,7 +107,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open configuration file"); fileChooser.setInitialFileName(DEFAULT_CONFIG_LOCATION); - fileChooser.setInitialDirectory(GlobalContext.instance().io().getRootDirectory()); +// fileChooser.setInitialDirectory(GlobalContext.instance().io().getRootDirectory()); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("xml", "*.xml", "*.XML")); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("json", "*.json", "*.JSON")); // fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("all", "*.*")); @@ -129,7 +140,6 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me } setupPlotFrame(plotConfig.getNode("plotFrame", null)); - currentPlotConfig = plotConfig; } if (config.hasNode("device")) { @@ -144,7 +154,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me /** * Set o reset plot area */ - private void setupPlotFrame(Meta plotFrameMeta) { + private synchronized void setupPlotFrame(Meta plotFrameMeta) { plottables = new TimePlottableGroup(); plotArea.getChildren().clear(); plotFrame = new JFreeChartFrame(plotFrameMeta); @@ -169,8 +179,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me device.init(); } - @Override - public void notifyDeviceInitialized(Device device) { + private void setupChannels() { Collection channels = this.device.getChanels(); //plot config from device configuration @@ -188,16 +197,18 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me plottables.addPlottable(plottable); plotFrame.add(plottable); }); + plottables.applyConfig(plotFrame.getConfig()); + } + + @Override + public void notifyDeviceInitialized(Device device) { + setupChannels(); startStopButton.setDisable(false); - - if (currentPlotConfig != null) { - applyViewConfig(currentPlotConfig); - } } - public void applyViewConfig(Meta viewConfig) { - plottables.applyConfig(viewConfig); - } +// public void applyViewConfig(Meta viewConfig) { +// plottables.applyConfig(viewConfig); +// } @Override public void notifyDeviceShutdown(Device device) { @@ -213,8 +224,12 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me @Override - public void onMeasurementResult(Measurement measurement, PKT8Result result, Instant time) { - plottables.put(result.channel, result.temperature); + public synchronized void onMeasurementResult(Measurement measurement, PKT8Result result, Instant time) { + if (rawDataButton.isSelected()) { + plottables.put(result.channel, result.rawValue); + } else { + plottables.put(result.channel, result.temperature); + } } @Override diff --git a/numass-control/cryotemp/src/main/resources/config/thermo-1.xml b/numass-control/cryotemp/src/main/resources/config/thermo-1.xml new file mode 100644 index 00000000..2141e114 --- /dev/null +++ b/numass-control/cryotemp/src/main/resources/config/thermo-1.xml @@ -0,0 +1,31 @@ + + + + + 192.168.111.36:4001 + 1 + "PT60S" + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/numass-control/cryotemp/src/main/resources/fxml/PKT8MainView.fxml b/numass-control/cryotemp/src/main/resources/fxml/PKT8MainView.fxml index c7f5b76a..54ca0c24 100644 --- a/numass-control/cryotemp/src/main/resources/fxml/PKT8MainView.fxml +++ b/numass-control/cryotemp/src/main/resources/fxml/PKT8MainView.fxml @@ -16,11 +16,11 @@ See the License for the specific language governing permissions and limitations under the License. --> - - +
@@ -28,6 +28,7 @@ limitations under the License. +