Fixed devices library and vacuum measurements

This commit is contained in:
Alexander Nozik 2016-02-14 15:28:44 +03:00
parent f41e2869b8
commit b74775efc4
7 changed files with 69 additions and 32 deletions

View File

@ -5,10 +5,13 @@
*/ */
package inr.numass.readvac.fx; package inr.numass.readvac.fx;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import org.controlsfx.control.ToggleSwitch; import org.controlsfx.control.ToggleSwitch;
/** /**
@ -19,6 +22,21 @@ public class PoweredVacuumeterView extends VacuumeterView {
@FXML @FXML
ToggleSwitch powerSwitch; 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 @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {

View File

@ -119,7 +119,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
this.device = device; this.device = device;
device.getSensors().stream().map((sensor) -> { device.getSensors().stream().map((sensor) -> {
VacuumeterView controller; VacuumeterView controller;
if (sensor instanceof MKSVacDevice) { if (sensor.hasState("power")) {
controller = new PoweredVacuumeterView(); controller = new PoweredVacuumeterView();
} else { } else {
controller = new VacuumeterView(); controller = new VacuumeterView();

View File

@ -33,7 +33,7 @@ import org.controlsfx.control.StatusBar;
public class VacuumeterView extends DeviceViewController implements MeasurementListener<Double>, Initializable, Named, Annotated { public class VacuumeterView extends DeviceViewController implements MeasurementListener<Double>, Initializable, Named, Annotated {
private static final DecimalFormat FORMAT = new DecimalFormat("0.##E0"); private static final DecimalFormat FORMAT = new DecimalFormat("0.##E0");
protected Node node; protected Node node;
@FXML @FXML
@ -56,7 +56,7 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
@Override @Override
public void evaluateDeviceException(Device device, String message, Throwable exception) { public void evaluateDeviceException(Device device, String message, Throwable exception) {
//show dialog or tooltip Platform.runLater(() -> status.setText("ERROR: " + message));
} }
public Node getComponent() { public Node getComponent() {

View File

@ -7,19 +7,15 @@ package inr.numass.readvac.test;
import hep.dataforge.context.GlobalContext; import hep.dataforge.context.GlobalContext;
import hep.dataforge.control.measurements.Sensor; import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.virtual.SensorFactory;
import hep.dataforge.control.virtual.Virtual; import hep.dataforge.control.virtual.Virtual;
import hep.dataforge.exceptions.ControlException;
import inr.numass.readvac.devices.VacCollectorDevice; import inr.numass.readvac.devices.VacCollectorDevice;
import inr.numass.readvac.fx.VacCollectorController; import inr.numass.readvac.fx.VacCollectorController;
import java.io.IOException;
import java.time.Duration; import java.time.Duration;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.slf4j.LoggerFactory;
/** /**
* *
@ -35,8 +31,16 @@ public class TestVac extends Application {
Sensor<Double> sensor1 = Virtual.randomDoubleSensor("vac1", Duration.ofMillis(200), 1e-5, 2e-6); Sensor<Double> sensor1 = Virtual.randomDoubleSensor("vac1", Duration.ofMillis(200), 1e-5, 2e-6);
Sensor<Double> sensor2 = Virtual.randomDoubleSensor("vac2", Duration.ofMillis(200), 2e-5, 2e-6); Sensor<Double> sensor2 = Virtual.randomDoubleSensor("vac2", Duration.ofMillis(200), 2e-5, 2e-6);
Sensor<Double> sensor3 = Virtual.randomDoubleSensor("vac3", Duration.ofMillis(200), 1e-7, 1e-8); Sensor<Double> sensor3 = Virtual.randomDoubleSensor("vac3", Duration.ofMillis(200), 1e-7, 1e-8);
Sensor<Double> poweredSensor = new SensorFactory<Double>("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(); collector.init();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml"));

View File

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.String?>
<?import java.net.URL?> <?import java.net.URL?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?> <?import javafx.scene.control.Separator?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?> <?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import org.controlsfx.control.StatusBar?> <?import org.controlsfx.control.StatusBar?>
@ -16,20 +18,29 @@
<children> <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" prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children> <children>
<Pane prefHeight="40.0" styleClass="beveled"> <Pane minHeight="30.0">
<children> <children>
<Label id="name" fx:id="deviceNameLabel" alignment="CENTER" layoutX="12.0" prefHeight="40.0" prefWidth="176.0" text="device Name" /> <Label id="name" fx:id="deviceNameLabel" alignment="CENTER" prefHeight="40.0" prefWidth="200.0" text="device Name" />
</children> </children>
<styleClass>
<String fx:value="beveled" />
<String fx:value="namePane" />
</styleClass>
</Pane> </Pane>
<Separator prefWidth="200.0" /> <Separator />
<Pane prefHeight="60.0" styleClass="beveled"> <BorderPane>
<children> <left>
<Label id="pressure" fx:id="valueLabel" alignment="CENTER_RIGHT" layoutX="14.0" prefHeight="60.0" prefWidth="90.0" text="1.22e-7" /> <Label id="pressure" fx:id="valueLabel" alignment="CENTER_RIGHT" prefHeight="60.0" prefWidth="100.0" text="#.##E-0" BorderPane.alignment="CENTER" />
<Label id="units" fx:id="unitLabel" layoutX="124.0" prefHeight="60.0" prefWidth="62.0" text="mbar" /> </left>
</children> <right>
</Pane> <Label id="units" fx:id="unitLabel" prefHeight="60.0" prefWidth="75.0" text="mbar" BorderPane.alignment="CENTER" />
<Separator prefWidth="200.0" /> </right>
<Pane VBox.vgrow="ALWAYS"> <center>
<Pane minWidth="-Infinity" prefWidth="25.0" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<Separator />
<Pane minHeight="30.0" VBox.vgrow="ALWAYS">
<children> <children>
<ToggleSwitch fx:id="powerSwitch" layoutX="58.0" layoutY="8.0" text="Power" /> <ToggleSwitch fx:id="powerSwitch" layoutX="58.0" layoutY="8.0" text="Power" />
</children> </children>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.String?>
<?import java.net.URL?> <?import java.net.URL?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?> <?import javafx.scene.control.Separator?>
@ -16,10 +17,14 @@
<children> <children>
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children> <children>
<Pane styleClass="beveled"> <Pane minHeight="30.0">
<children> <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" prefWidth="200.0" text="device Name" />
</children> </children>
<styleClass>
<String fx:value="beveled" />
<String fx:value="namePane" />
</styleClass>
</Pane> </Pane>
<Separator /> <Separator />
<BorderPane> <BorderPane>
@ -29,9 +34,9 @@
<right> <right>
<Label id="units" fx:id="unitLabel" prefHeight="60.0" prefWidth="75.0" text="mbar" BorderPane.alignment="CENTER" /> <Label id="units" fx:id="unitLabel" prefHeight="60.0" prefWidth="75.0" text="mbar" BorderPane.alignment="CENTER" />
</right> </right>
<center> <center>
<Pane minWidth="-Infinity" prefWidth="25.0" BorderPane.alignment="CENTER" /> <Pane minWidth="-Infinity" prefWidth="25.0" BorderPane.alignment="CENTER" />
</center> </center>
</BorderPane> </BorderPane>
<StatusBar fx:id="status" /> <StatusBar fx:id="status" />
</children> </children>

View File

@ -5,7 +5,6 @@
<?import javafx.scene.control.Separator?> <?import javafx.scene.control.Separator?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
@ -16,24 +15,24 @@
<children> <children>
<HBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <HBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children> <children>
<VBox fx:id="vacBoxHolder" styleClass="beveled"/> <VBox fx:id="vacBoxHolder" minWidth="200.0" styleClass="beveled" />
<Separator orientation="VERTICAL" /> <Separator orientation="VERTICAL" />
<VBox alignment="TOP_CENTER" HBox.hgrow="ALWAYS"> <VBox alignment="TOP_CENTER" HBox.hgrow="ALWAYS">
<children> <children>
<Pane prefHeight="50.0" styleClass="beveled"> <HBox prefHeight="50.0">
<children> <children>
<Label layoutX="208.0" layoutY="8.0" text="Time: "> <Label alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="180.0" text="Time: ">
<font> <font>
<Font size="24.0" /> <Font size="24.0" />
</font> </font>
</Label> </Label>
<Label fx:id="timeLabel" layoutX="271.0" layoutY="8.0" text="08.02.2016 15:57"> <Label fx:id="timeLabel" prefHeight="50.0" prefWidth="312.0" text="08.02.2016 15:57" HBox.hgrow="ALWAYS">
<font> <font>
<Font size="24.0" /> <Font size="24.0" />
</font> </font>
</Label> </Label>
</children> </children>
</Pane> </HBox>
<AnchorPane fx:id="plotHolder" VBox.vgrow="ALWAYS" /> <AnchorPane fx:id="plotHolder" VBox.vgrow="ALWAYS" />
</children> </children>
</VBox> </VBox>