From f41e2869b875845def5cdadddad3ea45d46507f0 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 13 Feb 2016 18:41:35 +0300 Subject: [PATCH] Fixed devices library and vacuum measurements --- .../inr/numass/control/msp/MspDevice.java | 2 +- .../numass/readvac/devices/CM32Device.java | 4 +- .../numass/readvac/devices/MKSVacDevice.java | 4 +- .../numass/readvac/devices/VITVacDevice.java | 4 +- .../readvac/devices/VacCollectorDevice.java | 20 +++++--- .../readvac/fx/VacCollectorController.java | 7 +-- .../inr/numass/readvac/fx/VacuumeterView.java | 7 ++- .../java/inr/numass/readvac/test/TestVac.java | 46 +++++++++++-------- .../vac/src/main/resources/fxml/VacBox.fxml | 32 +++++++------ .../src/main/resources/fxml/VacCollector.fxml | 25 +++++----- .../src/main/resources/styles/vacstyles.css | 36 +++++++-------- 11 files changed, 105 insertions(+), 82 deletions(-) diff --git a/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java b/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java index 0d3fc576..de5320e3 100644 --- a/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java +++ b/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java @@ -450,7 +450,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po public boolean stop(boolean force) throws MeasurementException { try { boolean stop = sendAndWait("ScanStop").isOK(); - onStop(); + onFinish(); responseDelegate = null; return stop; } catch (PortException ex) { diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/devices/CM32Device.java b/numass-control/vac/src/main/java/inr/numass/readvac/devices/CM32Device.java index 00caa12b..210efcfc 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/devices/CM32Device.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/devices/CM32Device.java @@ -6,7 +6,7 @@ package inr.numass.readvac.devices; import hep.dataforge.context.Context; -import hep.dataforge.control.measurements.SimpletMeasurement; +import hep.dataforge.control.measurements.SimpleMeasurement; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Sensor; import hep.dataforge.control.ports.ComPortHandler; @@ -85,7 +85,7 @@ public class CM32Device extends Sensor { return meta().getInt("timeout", 400); } - private class CMVacMeasurement extends SimpletMeasurement { + private class CMVacMeasurement extends SimpleMeasurement { private static final String CM32_QUERY = "MES R PM 1\r\n"; diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/devices/MKSVacDevice.java b/numass-control/vac/src/main/java/inr/numass/readvac/devices/MKSVacDevice.java index ef365ca9..9d43133c 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/devices/MKSVacDevice.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/devices/MKSVacDevice.java @@ -6,7 +6,7 @@ package inr.numass.readvac.devices; import hep.dataforge.context.Context; -import hep.dataforge.control.measurements.SimpletMeasurement; +import hep.dataforge.control.measurements.SimpleMeasurement; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Sensor; import hep.dataforge.control.ports.ComPortHandler; @@ -175,7 +175,7 @@ public class MKSVacDevice extends Sensor { return handler; } - private class MKSVacMeasurement extends SimpletMeasurement { + private class MKSVacMeasurement extends SimpleMeasurement { @Override protected synchronized Double doMeasure() throws Exception { diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/devices/VITVacDevice.java b/numass-control/vac/src/main/java/inr/numass/readvac/devices/VITVacDevice.java index 0f5940a5..8352fd36 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/devices/VITVacDevice.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/devices/VITVacDevice.java @@ -6,7 +6,7 @@ package inr.numass.readvac.devices; import hep.dataforge.context.Context; -import hep.dataforge.control.measurements.SimpletMeasurement; +import hep.dataforge.control.measurements.SimpleMeasurement; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Sensor; import hep.dataforge.control.ports.ComPortHandler; @@ -89,7 +89,7 @@ public class VITVacDevice extends Sensor { return meta().getInt("timeout", 400); } - private class CMVacMeasurement extends SimpletMeasurement { + private class CMVacMeasurement extends SimpleMeasurement { private static final String VIT_QUERY = ":010300000002FA\r\n"; diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/devices/VacCollectorDevice.java b/numass-control/vac/src/main/java/inr/numass/readvac/devices/VacCollectorDevice.java index 1efaf40b..59622c67 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/devices/VacCollectorDevice.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/devices/VacCollectorDevice.java @@ -30,12 +30,19 @@ import java.util.concurrent.TimeUnit; */ public class VacCollectorDevice extends Sensor { - private final Map> sensorMap; + private final Map sensorMap; - public VacCollectorDevice(String name, Context context, Meta meta, Sensor... sensors) { + /** + * Sensors in reversed order + * @param name + * @param context + * @param meta + * @param sensors + */ + public VacCollectorDevice(String name, Context context, Meta meta, Sensor... sensors) { super(name, context, meta); sensorMap = new HashMap<>(sensors.length); - for (Sensor sensor : sensors) { + for (Sensor sensor : sensors) { sensorMap.put(sensor.getName(), sensor); } //TODO add automatic construction from meta using deviceManager @@ -58,7 +65,7 @@ public class VacCollectorDevice extends Sensor { return "Numass vacuum"; } - public Collection> getSensors(){ + public Collection getSensors(){ return sensorMap.values(); } @@ -73,7 +80,8 @@ public class VacCollectorDevice extends Sensor { currentTask = executor.scheduleWithFixedDelay(() -> { sensorMap.entrySet().stream().parallel().forEach((entry) -> { try { - collector.put(entry.getKey(), entry.getValue().read()); + Object value = entry.getValue().read(); + collector.put(entry.getKey(), value); } catch (MeasurementException ex) { onError(ex); collector.put(entry.getKey(), Value.NULL); @@ -91,8 +99,8 @@ public class VacCollectorDevice extends Sensor { boolean isRunning = currentTask != null; if (isRunning) { currentTask.cancel(force); - isFinished = true; currentTask = null; + onFinish(); } return isRunning; } diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacCollectorController.java b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacCollectorController.java index d326af5b..bea9c146 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacCollectorController.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacCollectorController.java @@ -33,7 +33,8 @@ import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Label; import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import org.slf4j.LoggerFactory; /** * FXML Controller class @@ -50,7 +51,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me @FXML private AnchorPane plotHolder; @FXML - private HBox vacBoxHolder; + private VBox vacBoxHolder; @FXML private Label timeLabel; @@ -78,7 +79,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me @Override public void onMeasurementFailed(Measurement measurement, Throwable exception) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + LoggerFactory.getLogger(getClass()).error("Exception during measurement", exception); } @Override diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java index 5a3a290a..0cea5b77 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java @@ -15,6 +15,7 @@ import hep.dataforge.meta.Meta; import hep.dataforge.values.Value; import java.io.IOException; import java.net.URL; +import java.text.DecimalFormat; import java.time.Instant; import java.util.ResourceBundle; import javafx.application.Platform; @@ -31,6 +32,8 @@ import org.controlsfx.control.StatusBar; */ public class VacuumeterView extends DeviceViewController implements MeasurementListener, Initializable, Named, Annotated { + private static final DecimalFormat FORMAT = new DecimalFormat("0.##E0"); + protected Node node; @FXML @@ -46,6 +49,7 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL Label valueLabel; @Override + @SuppressWarnings("unchecked") public void accept(Device device, String measurementName, Measurement measurement) { measurement.addListener(this); } @@ -98,7 +102,8 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL @Override public void onMeasurementResult(Measurement measurement, Double result, Instant time) { - Platform.runLater(() -> valueLabel.setText(Double.toString(result))); + String resString = FORMAT.format(result); + Platform.runLater(() -> valueLabel.setText(resString)); } @Override diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/test/TestVac.java b/numass-control/vac/src/main/java/inr/numass/readvac/test/TestVac.java index 1276ff29..fe612dd7 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/test/TestVac.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/test/TestVac.java @@ -7,55 +7,63 @@ package inr.numass.readvac.test; import hep.dataforge.context.GlobalContext; import hep.dataforge.control.measurements.Sensor; -import hep.dataforge.control.virtual.VirtualMeasurements; +import hep.dataforge.control.virtual.Virtual; import hep.dataforge.exceptions.ControlException; import inr.numass.readvac.devices.VacCollectorDevice; import inr.numass.readvac.fx.VacCollectorController; import java.io.IOException; import java.time.Duration; +import java.util.logging.Level; +import java.util.logging.Logger; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; +import org.slf4j.LoggerFactory; /** * * @author Alexander Nozik */ public class TestVac extends Application { + VacCollectorController controller; @Override - public void start(Stage primaryStage) throws IOException, ControlException { + public void start(Stage primaryStage) { + try { + Sensor sensor1 = Virtual.randomDoubleSensor("vac1", Duration.ofMillis(200), 1e-5, 2e-6); + Sensor sensor2 = Virtual.randomDoubleSensor("vac2", Duration.ofMillis(200), 2e-5, 2e-6); + Sensor sensor3 = Virtual.randomDoubleSensor("vac3", Duration.ofMillis(200), 1e-7, 1e-8); - Sensor sensor1 = VirtualMeasurements.randomDoubleSensor("vac1", Duration.ofMillis(200), 1e-5, 2e-6); - Sensor sensor2 = VirtualMeasurements.randomDoubleSensor("vac2", Duration.ofMillis(200), 2e-5, 2e-6); - Sensor sensor3 = VirtualMeasurements.randomDoubleSensor("vac3", Duration.ofMillis(200), 1e-7, 1e-8); + VacCollectorDevice collector = new VacCollectorDevice("collector", GlobalContext.instance(), null, sensor3, sensor2, sensor1); + collector.init(); - VacCollectorDevice collector = new VacCollectorDevice("collector", GlobalContext.instance(), null, sensor1, sensor2, sensor3); - - FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml")); - loader.load(); - controller = loader.getController(); - controller.setDevice(collector); - - Scene scene = new Scene(loader.getRoot(), 800, 600); + FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml")); + loader.load(); + controller = loader.getController(); + controller.setDevice(collector); - primaryStage.setTitle("Vacuum measurement test"); - primaryStage.setScene(scene); - primaryStage.show(); - controller.startMeasurement(); + Scene scene = new Scene(loader.getRoot(), 800, 600); + + primaryStage.setTitle("Vacuum measurement test"); + primaryStage.setScene(scene); + primaryStage.show(); + controller.startMeasurement(); + } catch (Exception ex) { + throw new Error(ex); + } } @Override public void stop() throws Exception { - if(controller != null){ + if (controller != null) { controller.stopMeasurement(); + controller.getDevice().shutdown(); } super.stop(); System.exit(0); } - /** * @param args the command line arguments diff --git a/numass-control/vac/src/main/resources/fxml/VacBox.fxml b/numass-control/vac/src/main/resources/fxml/VacBox.fxml index 34e64536..fb394b36 100644 --- a/numass-control/vac/src/main/resources/fxml/VacBox.fxml +++ b/numass-control/vac/src/main/resources/fxml/VacBox.fxml @@ -4,32 +4,36 @@ + - + - + - + - - - - - - - - - + + + + + + +
+ +
+
+
diff --git a/numass-control/vac/src/main/resources/fxml/VacCollector.fxml b/numass-control/vac/src/main/resources/fxml/VacCollector.fxml index fc87a462..e4dd5ac2 100644 --- a/numass-control/vac/src/main/resources/fxml/VacCollector.fxml +++ b/numass-control/vac/src/main/resources/fxml/VacCollector.fxml @@ -2,24 +2,25 @@ + - - + - + - + - - -
- + + + + + -
-
- + +
+
- +
diff --git a/numass-control/vac/src/main/resources/styles/vacstyles.css b/numass-control/vac/src/main/resources/styles/vacstyles.css index 42e6e67b..d8e62ae2 100644 --- a/numass-control/vac/src/main/resources/styles/vacstyles.css +++ b/numass-control/vac/src/main/resources/styles/vacstyles.css @@ -2,24 +2,20 @@ * Empty Stylesheet file. */ -.vacBox { - .beveled{ - -fx-background-color: #BEBEBE; - -fx-border-color: #676767 white white #676767; - -fx-border-style: solid inside line-join miter; - } - - #pressure{ - -fx-font-size: 24; - -fx-font-weight: bold - } - - #units{ - -fx-font-size: 24; - } - - #name{ - -fx-font-size: 18; - } - +.vacBox #pressure{ + -fx-font-size: 24; + -fx-font-weight: bold } + +.vacBox #units{ + -fx-font-size: 24; +} + +.vacBox #name{ + -fx-font-size: 18; +} + +.beveled{ + -fx-border-color: white #676767 #676767 white; + -fx-border-style: solid outside line-join bevel; +} \ No newline at end of file