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 dfc2a78d..0d3fc576 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 @@ -16,7 +16,7 @@ package inr.numass.control.msp; import hep.dataforge.context.Context; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.control.connections.Roles; import hep.dataforge.control.connections.StorageConnection; import hep.dataforge.control.devices.SingleMeasurementDevice; import hep.dataforge.control.measurements.AbstractMeasurement; @@ -380,7 +380,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po private void prepareLoaders() { loaders = new ArrayList<>(); - forEachTypedConnection("storage", StorageConnection.class, (StorageConnection con) -> { + forEachTypedConnection(Roles.STORAGE_ROLE, StorageConnection.class, (StorageConnection con) -> { try { Storage storage = con.getStorage(); 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 2fb70e25..b6cd9472 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 @@ -16,6 +16,7 @@ import hep.dataforge.exceptions.ControlException; import hep.dataforge.exceptions.MeasurementException; import hep.dataforge.meta.Meta; import hep.dataforge.values.Value; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Executors; @@ -43,7 +44,7 @@ public class VacCollectorDevice extends Sensor { @Override protected Object calculateState(String stateName) throws ControlException { //TODO add dot path notation for states - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return Value.NULL; } @Override @@ -55,6 +56,10 @@ public class VacCollectorDevice extends Sensor { public String type() { return "Numass vacuum"; } + + public Collection> getSensors(){ + return sensorMap.values(); + } private class VacuumMeasurement extends AbstractMeasurement { @@ -91,5 +96,5 @@ public class VacCollectorDevice extends Sensor { return isRunning; } } - + } 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 new file mode 100644 index 00000000..a6341299 --- /dev/null +++ b/numass-control/vac/src/main/java/inr/numass/readvac/devices/VirtualVacDevice.java @@ -0,0 +1,40 @@ +/* + * 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/PoweredVacuumeterView.java b/numass-control/vac/src/main/java/inr/numass/readvac/fx/PoweredVacuumeterView.java index a08715a8..219e3781 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,116 +5,28 @@ */ package inr.numass.readvac.fx; -import hep.dataforge.control.connections.DeviceView; -import hep.dataforge.control.devices.Device; -import hep.dataforge.control.measurements.Measurement; -import hep.dataforge.control.measurements.MeasurementListener; -import hep.dataforge.values.Value; -import java.io.IOException; import java.net.URL; -import java.time.Instant; import java.util.ResourceBundle; import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.fxml.Initializable; -import javafx.scene.Node; -import javafx.scene.control.Label; -import org.controlsfx.control.StatusBar; import org.controlsfx.control.ToggleSwitch; /** * * @author Alexander Nozik */ -public class PoweredVacuumeterView extends DeviceView { +public class PoweredVacuumeterView extends VacuumeterView { - private VacuumeterViewNode controller; - private Node node; + @FXML + ToggleSwitch powerSwitch; @Override - public void accept(Device device, String measurementName, Measurement measurement) { - - } - - VacuumeterViewNode getController() { - if (controller == null) { - getComponent(); - } - return controller; - } - - @Override - public void evaluateDeviceException(Device device, String message, Throwable exception) { - //show dialog or tooltip - } - - @Override - public Node getComponent() { - if (getDevice() == null) { - throw new RuntimeException("Connection not attached"); - } else { - if (node == null) { - try { - FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacBox.fxml")); - controller = new VacuumeterViewNode(); - loader.setController(controller); - this.node = loader.load(); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } - return node; - } - } - - @Override - public void notifyDeviceStateChanged(Device device, String name, Value state) { - - } - - private class VacuumeterViewNode implements MeasurementListener, Initializable { - - @FXML - Label deviceNameLabel; - @FXML - Label valueLabel; - @FXML - Label unitLabel; - @FXML - StatusBar status; - @FXML - ToggleSwitch powerSwitch; - - @Override - public void initialize(URL location, ResourceBundle resources) { - unitLabel.setText(getDevice().meta().getString("units", "mbar")); - deviceNameLabel.setText(getDevice().getName()); - powerSwitch.selectedProperty().addListener((ObservableValue observable, Boolean oldValue, Boolean newValue) -> { - getDevice().setState("power", newValue); - }); - } - - @Override - public void onMeasurementFailed(Measurement measurement, Throwable exception) { - valueLabel.setText("Err"); - } - - @Override - public void onMeasurementResult(Measurement measurement, Double result, Instant time) { - valueLabel.setText(Double.toString(result)); - } - - @Override - public void onMeasurementProgress(Measurement measurement, String message) { - status.setText(message); - } - - @Override - public void onMeasurementProgress(Measurement measurement, double progress) { - status.setProgress(progress); - } - + public void initialize(URL location, ResourceBundle resources) { + unitLabel.setText(getDevice().meta().getString("units", "mbar")); + deviceNameLabel.setText(getDevice().getName()); + powerSwitch.selectedProperty().addListener((ObservableValue observable, Boolean oldValue, Boolean newValue) -> { + getDevice().setState("power", newValue); + }); } } 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 new file mode 100644 index 00000000..5d21f526 --- /dev/null +++ b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacCollectorController.java @@ -0,0 +1,128 @@ +/* + * 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.fx; + +import hep.dataforge.control.connections.Roles; +import hep.dataforge.control.devices.Device; +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.meta.Meta; +import hep.dataforge.meta.MetaBuilder; +import hep.dataforge.plots.PlotFrame; +import hep.dataforge.plots.data.DynamicPlottable; +import hep.dataforge.plots.data.DynamicPlottableSet; +import hep.dataforge.plots.fx.PlotContainer; +import hep.dataforge.plots.jfreechart.JFreeChartFrame; +import hep.dataforge.values.Value; +import inr.numass.readvac.devices.MKSVacDevice; +import inr.numass.readvac.devices.VacCollectorDevice; +import java.net.URL; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.ResourceBundle; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.HBox; + +/** + * FXML Controller class + * + * @author Alexander Nozik + */ +public class VacCollectorController implements Initializable, DeviceListener, MeasurementListener { + + private VacCollectorDevice device; + private final List views = new ArrayList<>(); + private PlotContainer plotContainer; + private DynamicPlottableSet plottables; + + @FXML + private AnchorPane plotHolder; + @FXML + private HBox vacBoxHolder; + + @Override + public void evaluateDeviceException(Device device, String message, Throwable exception) { + + } + + /** + * Initializes the controller class. + */ + @Override + public void initialize(URL url, ResourceBundle rb) { + plotContainer = PlotContainer.anchorTo(plotHolder); + } + + public VacCollectorDevice getDevice() { + return device; + } + + @Override + public void notifyDeviceStateChanged(Device device, String name, Value state) { + + } + + @Override + public void onMeasurementFailed(Measurement measurement, Throwable exception) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @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. + } + + private void setupView() { + vacBoxHolder.getChildren().clear(); + plottables = new DynamicPlottableSet(); + views.stream().forEach((controller) -> { + vacBoxHolder.getChildren().add(controller.getComponent()); + plottables.addPlottable(new DynamicPlottable(controller.getTitle(), + controller.meta(), controller.getName())); + }); + plotContainer.setPlot(setupPlot(plottables)); + } + + private PlotFrame setupPlot(DynamicPlottableSet plottables) { + Meta plotConfig = new MetaBuilder("plotFrame") + .setNode(new MetaBuilder("yAxis") + .setValue("logAxis", true) + .setValue("axisTitle", "pressure") + .setValue("axisUnits", "mbar") + ) + .setValue("xAxis.timeAxis", true); + JFreeChartFrame frame = new JFreeChartFrame("pressure", plotConfig); + frame.addAll(plottables); + return frame; + } + + public void setDevice(VacCollectorDevice device) { + this.device = device; + device.getSensors().stream().map((sensor) -> { + VacuumeterView controller; + if (sensor instanceof MKSVacDevice) { + controller = new PoweredVacuumeterView(); + } else { + controller = new VacuumeterView(); + } + sensor.connect(controller, Roles.DEVICE_LISTENER_ROLE, Roles.MEASUREMENT_CONSUMER_ROLE); + return controller; + }).forEach((controller) -> { + views.add(controller); + }); + setupView(); + } + + private void startMeasurement(){ + getDevice().startMeasurement(); + } + +} 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 637c7672..d5b60910 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 @@ -5,10 +5,13 @@ */ package inr.numass.readvac.fx; -import hep.dataforge.control.connections.DeviceView; +import hep.dataforge.content.Named; +import hep.dataforge.control.connections.DeviceViewController; import hep.dataforge.control.devices.Device; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.MeasurementListener; +import hep.dataforge.meta.Annotated; +import hep.dataforge.meta.Meta; import hep.dataforge.values.Value; import java.io.IOException; import java.net.URL; @@ -25,35 +28,37 @@ import org.controlsfx.control.StatusBar; * * @author Alexander Nozik */ -public class VacuumeterView extends DeviceView { +public class VacuumeterView extends DeviceViewController implements MeasurementListener, Initializable, Named, Annotated { - private VacuumeterViewNode controller; - private Node node; + protected Node node; + + @FXML + Label deviceNameLabel; + + @FXML + StatusBar status; + + @FXML + Label unitLabel; + + @FXML + Label valueLabel; @Override public void accept(Device device, String measurementName, Measurement measurement) { - + measurement.addListener(this); } - VacuumeterViewNode getController(){ - if(controller == null){ - getComponent(); - } - return controller; - } - @Override public void evaluateDeviceException(Device device, String message, Throwable exception) { //show dialog or tooltip } - @Override public Node getComponent() { if (node == null) { try { FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacBox.fxml")); - controller = new VacuumeterViewNode(); - loader.setController(controller); + loader.setController(this); this.node = loader.load(); } catch (IOException ex) { throw new RuntimeException(ex); @@ -62,51 +67,48 @@ public class VacuumeterView extends DeviceView { return node; } + @Override + public void initialize(URL location, ResourceBundle resources) { + unitLabel.setText(getDevice().meta().getString("units", "mbar")); + deviceNameLabel.setText(getDevice().getName()); + } + @Override public void notifyDeviceStateChanged(Device device, String name, Value state) { } - - - private class VacuumeterViewNode implements MeasurementListener, Initializable{ - - @FXML - Label deviceNameLabel; - @FXML - Label valueLabel; - @FXML - Label unitLabel; - @FXML - StatusBar status; - - @Override - public void initialize(URL location, ResourceBundle resources) { - unitLabel.setText(getDevice().meta().getString("units", "mbar")); - deviceNameLabel.setText(getDevice().getName()); - } - - @Override - public void onMeasurementFailed(Measurement measurement, Throwable exception) { - valueLabel.setText("Err"); - } - - @Override - public void onMeasurementResult(Measurement measurement, Double result, Instant time) { - valueLabel.setText(Double.toString(result)); - } - - @Override - public void onMeasurementProgress(Measurement measurement, String message) { - status.setText(message); - } - - @Override - public void onMeasurementProgress(Measurement measurement, double progress) { - status.setProgress(progress); - } - - + @Override + public void onMeasurementFailed(Measurement measurement, Throwable exception) { + valueLabel.setText("Err"); } + @Override + public void onMeasurementProgress(Measurement measurement, String message) { + status.setText(message); + } + + @Override + public void onMeasurementProgress(Measurement measurement, double progress) { + status.setProgress(progress); + } + + @Override + public void onMeasurementResult(Measurement measurement, Double result, Instant time) { + valueLabel.setText(Double.toString(result)); + } + + @Override + public String getName(){ + return getDevice().getName(); + } + + @Override + public Meta meta() { + return getDevice().meta(); + } + + public String getTitle(){ + return meta().getString("title", getName()); + } } diff --git a/numass-control/vac/src/main/resources/fxml/PoweredVacBox.fxml b/numass-control/vac/src/main/resources/fxml/PoweredVacBox.fxml index 45db8e34..a01e4acf 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/VacCollector.fxml b/numass-control/vac/src/main/resources/fxml/VacCollector.fxml new file mode 100644 index 00000000..43be5acd --- /dev/null +++ b/numass-control/vac/src/main/resources/fxml/VacCollector.fxml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+
+ + + + + + +
+
+
+