Fixed devices library and vacuum measurements

This commit is contained in:
Alexander Nozik 2016-02-13 18:41:35 +03:00
parent 661de3394b
commit f41e2869b8
11 changed files with 105 additions and 82 deletions

View File

@ -450,7 +450,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
public boolean stop(boolean force) throws MeasurementException { public boolean stop(boolean force) throws MeasurementException {
try { try {
boolean stop = sendAndWait("ScanStop").isOK(); boolean stop = sendAndWait("ScanStop").isOK();
onStop(); onFinish();
responseDelegate = null; responseDelegate = null;
return stop; return stop;
} catch (PortException ex) { } catch (PortException ex) {

View File

@ -6,7 +6,7 @@
package inr.numass.readvac.devices; package inr.numass.readvac.devices;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.control.measurements.SimpletMeasurement; import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.Sensor; import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.ports.ComPortHandler; import hep.dataforge.control.ports.ComPortHandler;
@ -85,7 +85,7 @@ public class CM32Device extends Sensor<Double> {
return meta().getInt("timeout", 400); return meta().getInt("timeout", 400);
} }
private class CMVacMeasurement extends SimpletMeasurement<Double> { private class CMVacMeasurement extends SimpleMeasurement<Double> {
private static final String CM32_QUERY = "MES R PM 1\r\n"; private static final String CM32_QUERY = "MES R PM 1\r\n";

View File

@ -6,7 +6,7 @@
package inr.numass.readvac.devices; package inr.numass.readvac.devices;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.control.measurements.SimpletMeasurement; import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.Sensor; import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.ports.ComPortHandler; import hep.dataforge.control.ports.ComPortHandler;
@ -175,7 +175,7 @@ public class MKSVacDevice extends Sensor<Double> {
return handler; return handler;
} }
private class MKSVacMeasurement extends SimpletMeasurement<Double> { private class MKSVacMeasurement extends SimpleMeasurement<Double> {
@Override @Override
protected synchronized Double doMeasure() throws Exception { protected synchronized Double doMeasure() throws Exception {

View File

@ -6,7 +6,7 @@
package inr.numass.readvac.devices; package inr.numass.readvac.devices;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.control.measurements.SimpletMeasurement; import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.Sensor; import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.ports.ComPortHandler; import hep.dataforge.control.ports.ComPortHandler;
@ -89,7 +89,7 @@ public class VITVacDevice extends Sensor<Double> {
return meta().getInt("timeout", 400); return meta().getInt("timeout", 400);
} }
private class CMVacMeasurement extends SimpletMeasurement<Double> { private class CMVacMeasurement extends SimpleMeasurement<Double> {
private static final String VIT_QUERY = ":010300000002FA\r\n"; private static final String VIT_QUERY = ":010300000002FA\r\n";

View File

@ -30,12 +30,19 @@ import java.util.concurrent.TimeUnit;
*/ */
public class VacCollectorDevice extends Sensor<DataPoint> { public class VacCollectorDevice extends Sensor<DataPoint> {
private final Map<String, Sensor<Double>> sensorMap; private final Map<String, Sensor> sensorMap;
public VacCollectorDevice(String name, Context context, Meta meta, Sensor<Double>... sensors) { /**
* Sensors in reversed order
* @param name
* @param context
* @param meta
* @param sensors
*/
public VacCollectorDevice(String name, Context context, Meta meta, Sensor... sensors) {
super(name, context, meta); super(name, context, meta);
sensorMap = new HashMap<>(sensors.length); sensorMap = new HashMap<>(sensors.length);
for (Sensor<Double> sensor : sensors) { for (Sensor sensor : sensors) {
sensorMap.put(sensor.getName(), sensor); sensorMap.put(sensor.getName(), sensor);
} }
//TODO add automatic construction from meta using deviceManager //TODO add automatic construction from meta using deviceManager
@ -58,7 +65,7 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
return "Numass vacuum"; return "Numass vacuum";
} }
public Collection<Sensor<Double>> getSensors(){ public Collection<Sensor> getSensors(){
return sensorMap.values(); return sensorMap.values();
} }
@ -73,7 +80,8 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
currentTask = executor.scheduleWithFixedDelay(() -> { currentTask = executor.scheduleWithFixedDelay(() -> {
sensorMap.entrySet().stream().parallel().forEach((entry) -> { sensorMap.entrySet().stream().parallel().forEach((entry) -> {
try { try {
collector.put(entry.getKey(), entry.getValue().read()); Object value = entry.getValue().read();
collector.put(entry.getKey(), value);
} catch (MeasurementException ex) { } catch (MeasurementException ex) {
onError(ex); onError(ex);
collector.put(entry.getKey(), Value.NULL); collector.put(entry.getKey(), Value.NULL);
@ -91,8 +99,8 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
boolean isRunning = currentTask != null; boolean isRunning = currentTask != null;
if (isRunning) { if (isRunning) {
currentTask.cancel(force); currentTask.cancel(force);
isFinished = true;
currentTask = null; currentTask = null;
onFinish();
} }
return isRunning; return isRunning;
} }

View File

@ -33,7 +33,8 @@ import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.VBox;
import org.slf4j.LoggerFactory;
/** /**
* FXML Controller class * FXML Controller class
@ -50,7 +51,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
@FXML @FXML
private AnchorPane plotHolder; private AnchorPane plotHolder;
@FXML @FXML
private HBox vacBoxHolder; private VBox vacBoxHolder;
@FXML @FXML
private Label timeLabel; private Label timeLabel;
@ -78,7 +79,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
@Override @Override
public void onMeasurementFailed(Measurement measurement, Throwable exception) { public void onMeasurementFailed(Measurement measurement, Throwable exception) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. LoggerFactory.getLogger(getClass()).error("Exception during measurement", exception);
} }
@Override @Override

View File

@ -15,6 +15,7 @@ import hep.dataforge.meta.Meta;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.text.DecimalFormat;
import java.time.Instant; import java.time.Instant;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.application.Platform; import javafx.application.Platform;
@ -31,6 +32,8 @@ 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");
protected Node node; protected Node node;
@FXML @FXML
@ -46,6 +49,7 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
Label valueLabel; Label valueLabel;
@Override @Override
@SuppressWarnings("unchecked")
public void accept(Device device, String measurementName, Measurement measurement) { public void accept(Device device, String measurementName, Measurement measurement) {
measurement.addListener(this); measurement.addListener(this);
} }
@ -98,7 +102,8 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
@Override @Override
public void onMeasurementResult(Measurement<Double> measurement, Double result, Instant time) { public void onMeasurementResult(Measurement<Double> measurement, Double result, Instant time) {
Platform.runLater(() -> valueLabel.setText(Double.toString(result))); String resString = FORMAT.format(result);
Platform.runLater(() -> valueLabel.setText(resString));
} }
@Override @Override

View File

@ -7,32 +7,37 @@ 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.VirtualMeasurements; import hep.dataforge.control.virtual.Virtual;
import hep.dataforge.exceptions.ControlException; 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.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;
/** /**
* *
* @author Alexander Nozik * @author Alexander Nozik
*/ */
public class TestVac extends Application { public class TestVac extends Application {
VacCollectorController controller; VacCollectorController controller;
@Override @Override
public void start(Stage primaryStage) throws IOException, ControlException { public void start(Stage primaryStage) {
try {
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> sensor3 = Virtual.randomDoubleSensor("vac3", Duration.ofMillis(200), 1e-7, 1e-8);
Sensor<Double> sensor1 = VirtualMeasurements.randomDoubleSensor("vac1", Duration.ofMillis(200), 1e-5, 2e-6); VacCollectorDevice collector = new VacCollectorDevice("collector", GlobalContext.instance(), null, sensor3, sensor2, sensor1);
Sensor<Double> sensor2 = VirtualMeasurements.randomDoubleSensor("vac2", Duration.ofMillis(200), 2e-5, 2e-6); collector.init();
Sensor<Double> 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")); FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml"));
loader.load(); loader.load();
@ -45,18 +50,21 @@ public class TestVac extends Application {
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.show(); primaryStage.show();
controller.startMeasurement(); controller.startMeasurement();
} catch (Exception ex) {
throw new Error(ex);
}
} }
@Override @Override
public void stop() throws Exception { public void stop() throws Exception {
if (controller != null) { if (controller != null) {
controller.stopMeasurement(); controller.stopMeasurement();
controller.getDevice().shutdown();
} }
super.stop(); super.stop();
System.exit(0); System.exit(0);
} }
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */

View File

@ -4,31 +4,35 @@
<?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?>
<AnchorPane prefHeight="170.0" prefWidth="200.0" styleClass="vacBox" xmlns:fx="http://javafx.com/fxml/1"> <AnchorPane prefHeight="132.0" prefWidth="200.0" styleClass="vacBox" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets> <stylesheets>
<URL value="@/styles/vacstyles.css" /> <URL value="@/styles/vacstyles.css" />
</stylesheets> </stylesheets>
<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 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 styleClass="beveled">
<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>
</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 maxHeight="1.7976931348623157E308" VBox.vgrow="ALWAYS" /> <center>
<Pane minWidth="-Infinity" prefWidth="25.0" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<StatusBar fx:id="status" /> <StatusBar fx:id="status" />
</children> </children>
</VBox> </VBox>

View File

@ -2,24 +2,25 @@
<?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.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?> <?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?>
<AnchorPane id="AnchorPane" prefHeight="600.0" prefWidth="600.0" styleClass="mainFxmlClass" 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="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.readvac.fx.VacCollectorController">
<stylesheets> <stylesheets>
<URL value="@/styles/vacstyles.css" /> <URL value="@/styles/vacstyles.css" />
</stylesheets> </stylesheets>
<children> <children>
<VBox prefHeight="200.0" prefWidth="100.0" 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>
<HBox fx:id="vacBoxHolder" /> <VBox fx:id="vacBoxHolder" styleClass="beveled"/>
<BorderPane prefHeight="50.0"> <Separator orientation="VERTICAL" />
<center> <VBox alignment="TOP_CENTER" HBox.hgrow="ALWAYS">
<Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER"> <children>
<Pane prefHeight="50.0" styleClass="beveled">
<children> <children>
<Label layoutX="208.0" layoutY="8.0" text="Time: "> <Label layoutX="208.0" layoutY="8.0" text="Time: ">
<font> <font>
@ -33,10 +34,10 @@
</Label> </Label>
</children> </children>
</Pane> </Pane>
</center>
</BorderPane>
<AnchorPane fx:id="plotHolder" VBox.vgrow="ALWAYS" /> <AnchorPane fx:id="plotHolder" VBox.vgrow="ALWAYS" />
</children> </children>
</VBox> </VBox>
</children> </children>
</HBox>
</children>
</AnchorPane> </AnchorPane>

View File

@ -2,24 +2,20 @@
* Empty Stylesheet file. * Empty Stylesheet file.
*/ */
.vacBox { .vacBox #pressure{
.beveled{
-fx-background-color: #BEBEBE;
-fx-border-color: #676767 white white #676767;
-fx-border-style: solid inside line-join miter;
}
#pressure{
-fx-font-size: 24; -fx-font-size: 24;
-fx-font-weight: bold -fx-font-weight: bold
} }
#units{ .vacBox #units{
-fx-font-size: 24; -fx-font-size: 24;
} }
#name{ .vacBox #name{
-fx-font-size: 18; -fx-font-size: 18;
} }
.beveled{
-fx-border-color: white #676767 #676767 white;
-fx-border-style: solid outside line-join bevel;
} }