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 b6cd9472..1efaf40b 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 @@ -49,6 +49,7 @@ public class VacCollectorDevice extends Sensor { @Override protected Measurement createMeasurement() { + //TODO use meta return new VacuumMeasurement(); } @@ -72,7 +73,7 @@ public class VacCollectorDevice extends Sensor { currentTask = executor.scheduleWithFixedDelay(() -> { sensorMap.entrySet().stream().parallel().forEach((entry) -> { try { - collector.put(entry.getKey(), entry.getValue().getMeasurement().getResult()); + collector.put(entry.getKey(), entry.getValue().read()); } catch (MeasurementException ex) { onError(ex); collector.put(entry.getKey(), Value.NULL); diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/devices/VirtualVacDevice.java b/numass-control/vac/src/main/java/inr/numass/readvac/devices/VirtualVacDevice.java deleted file mode 100644 index a6341299..00000000 --- a/numass-control/vac/src/main/java/inr/numass/readvac/devices/VirtualVacDevice.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package inr.numass.readvac.devices; - -import hep.dataforge.context.Context; -import hep.dataforge.control.measurements.Measurement; -import hep.dataforge.control.measurements.Sensor; -import hep.dataforge.exceptions.ControlException; -import hep.dataforge.meta.Meta; -import hep.dataforge.values.Value; - -/** - * - * @author Alexander Nozik - */ -public class VirtualVacDevice extends Sensor { - - public VirtualVacDevice(String name, Context context, Meta meta) { - super(name, context, meta); - } - - @Override - protected Object calculateState(String stateName) throws ControlException { - return Value.NULL; - } - - @Override - protected Measurement createMeasurement() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public String type() { - return "Virtual vacuumeter device"; - } - -} 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 5d21f526..d326af5b 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 @@ -11,6 +11,8 @@ import hep.dataforge.control.devices.DeviceListener; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.MeasurementListener; import hep.dataforge.data.DataPoint; +import hep.dataforge.exceptions.ControlException; +import hep.dataforge.exceptions.MeasurementException; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; import hep.dataforge.plots.PlotFrame; @@ -26,8 +28,10 @@ import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; +import javafx.application.Platform; import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.scene.control.Label; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.HBox; @@ -47,6 +51,8 @@ public class VacCollectorController implements Initializable, DeviceListener, Me private AnchorPane plotHolder; @FXML private HBox vacBoxHolder; + @FXML + private Label timeLabel; @Override public void evaluateDeviceException(Device device, String message, Throwable exception) { @@ -77,7 +83,11 @@ public class VacCollectorController implements Initializable, DeviceListener, Me @Override public void onMeasurementResult(Measurement measurement, DataPoint result, Instant time) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (plottables != null) { + plottables.put(result); + } + Platform.runLater(() -> timeLabel.setText(time.toString())); + } private void setupView() { @@ -85,7 +95,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me plottables = new DynamicPlottableSet(); views.stream().forEach((controller) -> { vacBoxHolder.getChildren().add(controller.getComponent()); - plottables.addPlottable(new DynamicPlottable(controller.getTitle(), + plottables.addPlottable(new DynamicPlottable(controller.getTitle(), controller.meta(), controller.getName())); }); plotContainer.setPlot(setupPlot(plottables)); @@ -94,11 +104,11 @@ public class VacCollectorController implements Initializable, DeviceListener, Me private PlotFrame setupPlot(DynamicPlottableSet plottables) { Meta plotConfig = new MetaBuilder("plotFrame") .setNode(new MetaBuilder("yAxis") - .setValue("logAxis", true) + .setValue("type", "log") .setValue("axisTitle", "pressure") .setValue("axisUnits", "mbar") ) - .setValue("xAxis.timeAxis", true); + .setValue("xAxis.type", "time"); JFreeChartFrame frame = new JFreeChartFrame("pressure", plotConfig); frame.addAll(plottables); return frame; @@ -120,9 +130,17 @@ public class VacCollectorController implements Initializable, DeviceListener, Me }); setupView(); } - - private void startMeasurement(){ - getDevice().startMeasurement(); + + public void startMeasurement() throws ControlException { + getDevice().startMeasurement().addListener(this); + } + + public void stopMeasurement() { + try { + getDevice().stopMeasurement(true); + } catch (MeasurementException ex) { + throw new RuntimeException(ex); + } } } 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 d5b60910..5a3a290a 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 @@ -17,6 +17,7 @@ import java.io.IOException; import java.net.URL; import java.time.Instant; import java.util.ResourceBundle; +import javafx.application.Platform; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; @@ -69,8 +70,10 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL @Override public void initialize(URL location, ResourceBundle resources) { - unitLabel.setText(getDevice().meta().getString("units", "mbar")); - deviceNameLabel.setText(getDevice().getName()); + Platform.runLater(() -> { + unitLabel.setText(getDevice().meta().getString("units", "mbar")); + deviceNameLabel.setText(getDevice().getName()); + }); } @Override @@ -80,26 +83,26 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL @Override public void onMeasurementFailed(Measurement measurement, Throwable exception) { - valueLabel.setText("Err"); + Platform.runLater(() -> valueLabel.setText("Err")); } @Override public void onMeasurementProgress(Measurement measurement, String message) { - status.setText(message); + Platform.runLater(() -> status.setText(message)); } @Override public void onMeasurementProgress(Measurement measurement, double progress) { - status.setProgress(progress); + Platform.runLater(() -> status.setProgress(progress)); } @Override public void onMeasurementResult(Measurement measurement, Double result, Instant time) { - valueLabel.setText(Double.toString(result)); + Platform.runLater(() -> valueLabel.setText(Double.toString(result))); } @Override - public String getName(){ + public String getName() { return getDevice().getName(); } @@ -107,8 +110,8 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL public Meta meta() { return getDevice().meta(); } - - public String getTitle(){ + + public String getTitle() { return meta().getString("title", getName()); - } + } } 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 new file mode 100644 index 00000000..1276ff29 --- /dev/null +++ b/numass-control/vac/src/main/java/inr/numass/readvac/test/TestVac.java @@ -0,0 +1,67 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +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.exceptions.ControlException; +import inr.numass.readvac.devices.VacCollectorDevice; +import inr.numass.readvac.fx.VacCollectorController; +import java.io.IOException; +import java.time.Duration; +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.stage.Stage; + +/** + * + * @author Alexander Nozik + */ +public class TestVac extends Application { + VacCollectorController controller; + + @Override + public void start(Stage primaryStage) throws IOException, ControlException { + + 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, 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); + + primaryStage.setTitle("Vacuum measurement test"); + primaryStage.setScene(scene); + primaryStage.show(); + controller.startMeasurement(); + } + + @Override + public void stop() throws Exception { + if(controller != null){ + controller.stopMeasurement(); + } + super.stop(); + System.exit(0); + } + + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + launch(args); + } + +} diff --git a/numass-control/vac/src/main/resources/fxml/PoweredVacBox.fxml b/numass-control/vac/src/main/resources/fxml/PoweredVacBox.fxml index a01e4acf..45db8e34 100644 --- a/numass-control/vac/src/main/resources/fxml/PoweredVacBox.fxml +++ b/numass-control/vac/src/main/resources/fxml/PoweredVacBox.fxml @@ -9,7 +9,7 @@ - + diff --git a/numass-control/vac/src/main/resources/fxml/VacBox.fxml b/numass-control/vac/src/main/resources/fxml/VacBox.fxml index 6c16cb87..34e64536 100644 --- a/numass-control/vac/src/main/resources/fxml/VacBox.fxml +++ b/numass-control/vac/src/main/resources/fxml/VacBox.fxml @@ -8,7 +8,7 @@ - + diff --git a/numass-control/vac/src/main/resources/fxml/VacCollector.fxml b/numass-control/vac/src/main/resources/fxml/VacCollector.fxml index 43be5acd..fc87a462 100644 --- a/numass-control/vac/src/main/resources/fxml/VacCollector.fxml +++ b/numass-control/vac/src/main/resources/fxml/VacCollector.fxml @@ -1,45 +1,42 @@ - - - - - - - + + + + + + + + - + - - - - -
- - - - - - -
-
- - - - - - -
-
-
+ + + + + +
+ + + + + + +
+
+ +
+
+
diff --git a/numass-control/vac/src/main/resources/styles/vacstyles.css b/numass-control/vac/src/main/resources/styles/vacstyles.css index e831d71c..42e6e67b 100644 --- a/numass-control/vac/src/main/resources/styles/vacstyles.css +++ b/numass-control/vac/src/main/resources/styles/vacstyles.css @@ -11,7 +11,7 @@ #pressure{ -fx-font-size: 24; - -fx-font-style: bold + -fx-font-weight: bold } #units{