[no commit message]

This commit is contained in:
Alexander Nozik 2016-02-17 14:05:52 +03:00
parent f3f5af5412
commit 1d1c2698c7
8 changed files with 167 additions and 82 deletions

View File

@ -5,7 +5,6 @@
*/
package inr.numass.readvac.devices;
import hep.dataforge.context.Context;
import hep.dataforge.control.collectors.PointCollector;
import hep.dataforge.control.collectors.ValueCollector;
import hep.dataforge.control.measurements.AbstractMeasurement;
@ -14,7 +13,6 @@ import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.data.DataPoint;
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;
@ -33,22 +31,6 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
private Map<String, Sensor> sensorMap = new HashMap<>();
// /**
// * Sensors in reversed order
// *
// * @param name
// * @param context
// * @param meta
// * @param sensors
// */
// public VacCollectorDevice(String name, Context context, Meta meta, Sensor... sensors) {
// sensorMap = new LinkedHashMap<>(sensors.length);
// for (Sensor sensor : sensors) {
// sensorMap.put(sensor.getName(), sensor);
// }
// //TODO add automatic construction from meta using deviceManager
// }
public void setSensors(Sensor... sensors) {
sensorMap = new LinkedHashMap<>(sensors.length);
for (Sensor sensor : sensors) {
@ -73,6 +55,24 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
return "Numass vacuum";
}
public void setDelay(int delay) throws MeasurementException {
getConfig().setValue("delay", delay);
if (isMeasuring()) {
getMeasurement().stop(false);
getMeasurement().start();
}
}
@Override
public void shutdown() throws ControlException {
super.shutdown();
for (Sensor sensor : getSensors()) {
sensor.shutdown();
}
}
public Collection<Sensor> getSensors() {
return sensorMap.values();
}
@ -92,16 +92,12 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
try {
Object value = entry.getValue().read();
collector.put(entry.getKey(), value);
} catch (MeasurementException ex) {
} catch (Exception ex) {
onError(ex);
collector.put(entry.getKey(), Value.NULL);
}
});
}, 0, getDelay(), TimeUnit.MILLISECONDS);
}
private int getDelay() {
return meta().getInt("delay", 5000);
}, 0, meta().getInt("delay", 5000), TimeUnit.MILLISECONDS);
}
@Override

View File

@ -13,6 +13,7 @@ import hep.dataforge.control.measurements.MeasurementListener;
import hep.dataforge.control.measurements.Sensor;
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;
@ -28,11 +29,18 @@ import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.util.Duration;
import org.controlsfx.control.Notifications;
import org.slf4j.LoggerFactory;
/**
@ -42,6 +50,9 @@ import org.slf4j.LoggerFactory;
*/
public class VacCollectorController implements Initializable, DeviceListener, MeasurementListener<DataPoint> {
private final String[] intervalNames = {"1 sec", "5 sec", "10 sec", "30 sec", "1 min"};
private final int[] intervals = {1000, 5000, 10000, 30000, 60000};
private VacCollectorDevice device;
private final List<VacuumeterView> views = new ArrayList<>();
private PlotContainer plotContainer;
@ -53,11 +64,10 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
private VBox vacBoxHolder;
@FXML
private Label timeLabel;
@Override
public void evaluateDeviceException(Device device, String message, Throwable exception) {
}
@FXML
private ChoiceBox<String> intervalSelector;
@FXML
private ToggleButton startStopButton;
/**
* Initializes the controller class.
@ -65,6 +75,22 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
@Override
public void initialize(URL url, ResourceBundle rb) {
plotContainer = PlotContainer.anchorTo(plotHolder);
intervalSelector.setItems(FXCollections.observableArrayList(intervalNames));
intervalSelector.getSelectionModel().select(1);
intervalSelector.getSelectionModel().selectedIndexProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
if (getDevice() != null) {
try {
getDevice().setDelay(intervals[newValue.intValue()]);
} catch (MeasurementException ex) {
evaluateDeviceException(getDevice(), "Failed to restart measurement", null);
}
}
});
}
@Override
public void evaluateDeviceException(Device device, String message, Throwable exception) {
Notifications.create().darkStyle().hideAfter(Duration.seconds(2d)).text(message).showError();
}
public VacCollectorDevice getDevice() {
@ -78,7 +104,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
@Override
public void onMeasurementFailed(Measurement measurement, Throwable exception) {
LoggerFactory.getLogger(getClass()).error("Exception during measurement", exception);
LoggerFactory.getLogger(getClass()).debug("Exception during measurement: {}", exception.getMessage());
}
@Override
@ -87,7 +113,6 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
plottables.put(result);
}
Platform.runLater(() -> timeLabel.setText(time.toString()));
}
private void setupView() {
@ -135,17 +160,29 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
public void startMeasurement() throws ControlException {
getDevice().startMeasurement().addListener(this);
startStopButton.setSelected(true);
}
public void stopMeasurement() {
try {
getDevice().stopMeasurement(true);
getDevice().stopMeasurement(false);
for (Sensor sensor : getDevice().getSensors()) {
sensor.shutdown();
sensor.stopMeasurement(false);
}
} catch (ControlException ex) {
throw new RuntimeException(ex);
}
}
@FXML
private void onStartStopToggle(ActionEvent event) throws ControlException {
if (startStopButton.isSelected() != getDevice().isMeasuring()) {
if (startStopButton.isSelected()) {
startMeasurement();
} else {
stopMeasurement();
}
}
}
}

View File

@ -25,7 +25,6 @@ import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import org.controlsfx.control.StatusBar;
/**
*
@ -40,15 +39,15 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
@FXML
Label deviceNameLabel;
@FXML
StatusBar status;
@FXML
Label unitLabel;
@FXML
Label valueLabel;
@FXML
Label status;
@Override
@SuppressWarnings("unchecked")
public void accept(Device device, String measurementName, Measurement measurement) {
@ -60,7 +59,7 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
@Override
public void evaluateDeviceException(Device device, String message, Throwable exception) {
Platform.runLater(() -> status.setText("ERROR: " + message));
Platform.runLater(() -> setStatus("ERROR: " + message));
}
public Node getComponent() {
@ -91,7 +90,14 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
@Override
public void onMeasurementFailed(Measurement measurement, Throwable exception) {
Platform.runLater(() -> valueLabel.setText("Err"));
Platform.runLater(() -> {
valueLabel.setText("Err");
setStatus("Error: " + exception.getMessage());
});
}
private void setStatus(String text) {
status.setText(text);
}
@Override
@ -101,13 +107,16 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
@Override
public void onMeasurementProgress(Measurement measurement, double progress) {
Platform.runLater(() -> status.setProgress(progress));
// Platform.runLater(() -> status.setProgress(progress));
}
@Override
public void onMeasurementResult(Measurement<Double> measurement, Double result, Instant time) {
String resString = FORMAT.format(result);
Platform.runLater(() -> valueLabel.setText(resString));
Platform.runLater(() -> {
valueLabel.setText(resString);
setStatus("OK: " + time.toString());
});
}
@Override

View File

@ -13,10 +13,13 @@ import hep.dataforge.meta.MetaBuilder;
import inr.numass.readvac.devices.VacCollectorDevice;
import inr.numass.readvac.fx.VacCollectorController;
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;
/**
*
@ -36,6 +39,12 @@ public class TestVac extends Application {
if (sensor.getState("power").booleanValue()) {
return 1e-6;
} else {
// throw new RuntimeException("not connected");
// try {
// Thread.sleep(2000);
// } catch (InterruptedException ex) {
// LoggerFactory.getLogger(getClass()).info("Sleep interrupted on demo device");
// }
return null;
}
})

View File

@ -1,32 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.String?>
<?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import org.controlsfx.control.StatusBar?>
<?import org.controlsfx.control.ToggleSwitch?>
<AnchorPane prefHeight="170.0" prefWidth="200.0" styleClass="vacBox" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane styleClass="vacBox" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="@/styles/vacstyles.css" />
</stylesheets>
<children>
<VBox layoutX="50.0" layoutY="6.0" prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<VBox layoutX="50.0" layoutY="6.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Pane minHeight="30.0">
<AnchorPane styleClass="namePane">
<children>
<Label id="name" fx:id="deviceNameLabel" alignment="CENTER" prefHeight="40.0" prefWidth="200.0" text="device Name" />
<Label id="name" fx:id="deviceNameLabel" alignment="CENTER" prefHeight="40.0" text="device Name" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
<styleClass>
<String fx:value="beveled" />
<String fx:value="namePane" />
</styleClass>
</Pane>
</AnchorPane>
<Separator />
<BorderPane>
<left>
@ -40,12 +35,20 @@
</center>
</BorderPane>
<Separator />
<Pane minHeight="30.0" VBox.vgrow="ALWAYS">
<Pane minHeight="30.0" prefHeight="30.0" VBox.vgrow="ALWAYS">
<children>
<ToggleSwitch fx:id="powerSwitch" layoutX="58.0" layoutY="8.0" text="Power" />
<ToggleSwitch fx:id="powerSwitch" layoutX="58.0" layoutY="5.0" text="Power" />
</children>
</Pane>
<StatusBar fx:id="status" />
<Separator />
<AnchorPane styleClass="statusPane">
<children>
<Label fx:id="status" maxWidth="200.0" text="Initializing" wrapText="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</AnchorPane>
</children>
</VBox>
</children>

View File

@ -1,33 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.String?>
<?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import org.controlsfx.control.StatusBar?>
<AnchorPane prefHeight="132.0" prefWidth="200.0" styleClass="vacBox" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane styleClass="vacBox" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="@/styles/vacstyles.css" />
</stylesheets>
<children>
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Pane minHeight="30.0">
<AnchorPane styleClass="namePane">
<children>
<Label id="name" fx:id="deviceNameLabel" alignment="CENTER" prefHeight="40.0" prefWidth="200.0" text="device Name" />
<Label id="name" fx:id="deviceNameLabel" alignment="CENTER" prefHeight="40.0" text="device Name" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
<styleClass>
<String fx:value="beveled" />
<String fx:value="namePane" />
</styleClass>
</Pane>
</AnchorPane>
<Separator />
<BorderPane>
<BorderPane VBox.vgrow="ALWAYS">
<left>
<Label id="pressure" fx:id="valueLabel" alignment="CENTER_RIGHT" prefHeight="60.0" prefWidth="100.0" text="#.##E-0" BorderPane.alignment="CENTER" />
</left>
@ -38,7 +33,18 @@
<Pane minWidth="-Infinity" prefWidth="25.0" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<StatusBar fx:id="status" />
<Separator />
<AnchorPane styleClass="statusPane">
<children>
<Label fx:id="status" maxWidth="200.0" text="Initializing" wrapText="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
<VBox.margin>
<Insets />
</VBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</AnchorPane>
</children>
</VBox>
</children>

View File

@ -1,39 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane id="root" prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.readvac.fx.VacCollectorController">
<AnchorPane id="root" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.readvac.fx.VacCollectorController">
<stylesheets>
<URL value="@/styles/vacstyles.css" />
</stylesheets>
<children>
<HBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<VBox fx:id="vacBoxHolder" minWidth="200.0" styleClass="beveled" />
<VBox fx:id="vacBoxHolder" minWidth="200.0" spacing="2.0">
<HBox.margin>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</HBox.margin></VBox>
<Separator orientation="VERTICAL" />
<VBox alignment="TOP_CENTER" HBox.hgrow="ALWAYS">
<children>
<HBox prefHeight="50.0">
<ToolBar>
<items>
<ToggleButton fx:id="startStopButton" mnemonicParsing="false" onAction="#onStartStopToggle" text="Measure" />
<Separator orientation="VERTICAL" />
<Label text="Interval: " />
<ChoiceBox fx:id="intervalSelector" prefWidth="150.0" />
<Separator orientation="VERTICAL" />
</items>
</ToolBar>
<AnchorPane fx:id="plotHolder" VBox.vgrow="ALWAYS" />
<HBox styleClass="beveled">
<children>
<Label alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="180.0" text="Time: ">
<Label alignment="CENTER_RIGHT" text="Time: ">
<font>
<Font size="24.0" />
</font>
</Label>
<Label fx:id="timeLabel" prefHeight="50.0" prefWidth="312.0" text="08.02.2016 15:57" HBox.hgrow="ALWAYS">
<Label fx:id="timeLabel" text="08.02.2016 15:57" HBox.hgrow="ALWAYS">
<font>
<Font size="24.0" />
</font>
</Label>
</children>
</HBox>
<AnchorPane fx:id="plotHolder" VBox.vgrow="ALWAYS" />
</children>
</VBox>
</children>

View File

@ -2,6 +2,10 @@
* Empty Stylesheet file.
*/
.vacBox {
-fx-border-color: blue;
}
.vacBox #pressure{
-fx-font-size: 24;
-fx-font-weight: bold
@ -13,6 +17,11 @@
.vacBox #name{
-fx-font-size: 18;
-fx-font-weight: bold
}
.vacBox .namePane{
-fx-background-color: lavender
}
.beveled{