From b74775efc44bcff34a85e4a11d4456c159f327ab Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 14 Feb 2016 15:28:44 +0300 Subject: [PATCH] Fixed devices library and vacuum measurements --- .../readvac/fx/PoweredVacuumeterView.java | 18 ++++++++++ .../readvac/fx/VacCollectorController.java | 2 +- .../inr/numass/readvac/fx/VacuumeterView.java | 4 +-- .../java/inr/numass/readvac/test/TestVac.java | 16 +++++---- .../main/resources/fxml/PoweredVacBox.fxml | 33 ++++++++++++------- .../vac/src/main/resources/fxml/VacBox.fxml | 13 +++++--- .../src/main/resources/fxml/VacCollector.fxml | 15 ++++----- 7 files changed, 69 insertions(+), 32 deletions(-) diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/fx/PoweredVacuumeterView.java b/numass-control/vac/src/main/java/inr/numass/readvac/fx/PoweredVacuumeterView.java index 219e3781..0493bac0 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/fx/PoweredVacuumeterView.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/fx/PoweredVacuumeterView.java @@ -5,10 +5,13 @@ */ package inr.numass.readvac.fx; +import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Node; import org.controlsfx.control.ToggleSwitch; /** @@ -19,6 +22,21 @@ public class PoweredVacuumeterView extends VacuumeterView { @FXML ToggleSwitch powerSwitch; + + + @Override + public Node getComponent() { + if (node == null) { + try { + FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/PoweredVacBox.fxml")); + loader.setController(this); + this.node = loader.load(); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + return node; + } @Override public void initialize(URL location, ResourceBundle resources) { 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 bea9c146..abe6dd56 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 @@ -119,7 +119,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me this.device = device; device.getSensors().stream().map((sensor) -> { VacuumeterView controller; - if (sensor instanceof MKSVacDevice) { + if (sensor.hasState("power")) { controller = new PoweredVacuumeterView(); } else { controller = new VacuumeterView(); 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 0cea5b77..356b93d1 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 @@ -33,7 +33,7 @@ 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 @@ -56,7 +56,7 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL @Override public void evaluateDeviceException(Device device, String message, Throwable exception) { - //show dialog or tooltip + Platform.runLater(() -> status.setText("ERROR: " + message)); } public Node getComponent() { 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 fe612dd7..e08a51ce 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,19 +7,15 @@ package inr.numass.readvac.test; import hep.dataforge.context.GlobalContext; import hep.dataforge.control.measurements.Sensor; +import hep.dataforge.control.virtual.SensorFactory; 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; /** * @@ -35,8 +31,16 @@ public class TestVac extends Application { 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 poweredSensor = new SensorFactory("vac4", (sensor) -> { + if (sensor.getState("power").booleanValue()) { + return 1e-6; + } else { + return null; + } + }).addState("power").build(); - VacCollectorDevice collector = new VacCollectorDevice("collector", GlobalContext.instance(), null, sensor3, sensor2, sensor1); + VacCollectorDevice collector = new VacCollectorDevice("collector", + GlobalContext.instance(), null, poweredSensor, sensor3, sensor2, sensor1); collector.init(); FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml")); diff --git a/numass-control/vac/src/main/resources/fxml/PoweredVacBox.fxml b/numass-control/vac/src/main/resources/fxml/PoweredVacBox.fxml index 45db8e34..da965b02 100644 --- a/numass-control/vac/src/main/resources/fxml/PoweredVacBox.fxml +++ b/numass-control/vac/src/main/resources/fxml/PoweredVacBox.fxml @@ -1,9 +1,11 @@ + + @@ -16,20 +18,29 @@ - + - + + + + - - - - - - - + + + + + + +
+ +
+
+ + diff --git a/numass-control/vac/src/main/resources/fxml/VacBox.fxml b/numass-control/vac/src/main/resources/fxml/VacBox.fxml index fb394b36..3cc92c45 100644 --- a/numass-control/vac/src/main/resources/fxml/VacBox.fxml +++ b/numass-control/vac/src/main/resources/fxml/VacBox.fxml @@ -1,5 +1,6 @@ + @@ -16,10 +17,14 @@ - + + + + + @@ -29,9 +34,9 @@ -
- -
+
+ +
diff --git a/numass-control/vac/src/main/resources/fxml/VacCollector.fxml b/numass-control/vac/src/main/resources/fxml/VacCollector.fxml index e4dd5ac2..43ecf083 100644 --- a/numass-control/vac/src/main/resources/fxml/VacCollector.fxml +++ b/numass-control/vac/src/main/resources/fxml/VacCollector.fxml @@ -5,7 +5,6 @@ - @@ -16,24 +15,24 @@ - + - - - + +