Fixed devices library and vacuum measurements
This commit is contained in:
parent
661de3394b
commit
f41e2869b8
@ -450,7 +450,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
|
||||
public boolean stop(boolean force) throws MeasurementException {
|
||||
try {
|
||||
boolean stop = sendAndWait("ScanStop").isOK();
|
||||
onStop();
|
||||
onFinish();
|
||||
responseDelegate = null;
|
||||
return stop;
|
||||
} catch (PortException ex) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
package inr.numass.readvac.devices;
|
||||
|
||||
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.Sensor;
|
||||
import hep.dataforge.control.ports.ComPortHandler;
|
||||
@ -85,7 +85,7 @@ public class CM32Device extends Sensor<Double> {
|
||||
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";
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
package inr.numass.readvac.devices;
|
||||
|
||||
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.Sensor;
|
||||
import hep.dataforge.control.ports.ComPortHandler;
|
||||
@ -175,7 +175,7 @@ public class MKSVacDevice extends Sensor<Double> {
|
||||
return handler;
|
||||
}
|
||||
|
||||
private class MKSVacMeasurement extends SimpletMeasurement<Double> {
|
||||
private class MKSVacMeasurement extends SimpleMeasurement<Double> {
|
||||
|
||||
@Override
|
||||
protected synchronized Double doMeasure() throws Exception {
|
||||
|
@ -6,7 +6,7 @@
|
||||
package inr.numass.readvac.devices;
|
||||
|
||||
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.Sensor;
|
||||
import hep.dataforge.control.ports.ComPortHandler;
|
||||
@ -89,7 +89,7 @@ public class VITVacDevice extends Sensor<Double> {
|
||||
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";
|
||||
|
||||
|
@ -30,12 +30,19 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
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);
|
||||
sensorMap = new HashMap<>(sensors.length);
|
||||
for (Sensor<Double> sensor : sensors) {
|
||||
for (Sensor sensor : sensors) {
|
||||
sensorMap.put(sensor.getName(), sensor);
|
||||
}
|
||||
//TODO add automatic construction from meta using deviceManager
|
||||
@ -58,7 +65,7 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
|
||||
return "Numass vacuum";
|
||||
}
|
||||
|
||||
public Collection<Sensor<Double>> getSensors(){
|
||||
public Collection<Sensor> getSensors(){
|
||||
return sensorMap.values();
|
||||
}
|
||||
|
||||
@ -73,7 +80,8 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
|
||||
currentTask = executor.scheduleWithFixedDelay(() -> {
|
||||
sensorMap.entrySet().stream().parallel().forEach((entry) -> {
|
||||
try {
|
||||
collector.put(entry.getKey(), entry.getValue().read());
|
||||
Object value = entry.getValue().read();
|
||||
collector.put(entry.getKey(), value);
|
||||
} catch (MeasurementException ex) {
|
||||
onError(ex);
|
||||
collector.put(entry.getKey(), Value.NULL);
|
||||
@ -91,8 +99,8 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
|
||||
boolean isRunning = currentTask != null;
|
||||
if (isRunning) {
|
||||
currentTask.cancel(force);
|
||||
isFinished = true;
|
||||
currentTask = null;
|
||||
onFinish();
|
||||
}
|
||||
return isRunning;
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* FXML Controller class
|
||||
@ -50,7 +51,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
|
||||
@FXML
|
||||
private AnchorPane plotHolder;
|
||||
@FXML
|
||||
private HBox vacBoxHolder;
|
||||
private VBox vacBoxHolder;
|
||||
@FXML
|
||||
private Label timeLabel;
|
||||
|
||||
@ -78,7 +79,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
|
||||
|
||||
@Override
|
||||
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
|
||||
|
@ -15,6 +15,7 @@ import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.values.Value;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.application.Platform;
|
||||
@ -31,6 +32,8 @@ import org.controlsfx.control.StatusBar;
|
||||
*/
|
||||
public class VacuumeterView extends DeviceViewController implements MeasurementListener<Double>, Initializable, Named, Annotated {
|
||||
|
||||
private static final DecimalFormat FORMAT = new DecimalFormat("0.##E0");
|
||||
|
||||
protected Node node;
|
||||
|
||||
@FXML
|
||||
@ -46,6 +49,7 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
|
||||
Label valueLabel;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void accept(Device device, String measurementName, Measurement measurement) {
|
||||
measurement.addListener(this);
|
||||
}
|
||||
@ -98,7 +102,8 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
|
||||
|
||||
@Override
|
||||
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
|
||||
|
@ -7,32 +7,37 @@ 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.control.virtual.Virtual;
|
||||
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 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
public class TestVac extends Application {
|
||||
|
||||
VacCollectorController controller;
|
||||
|
||||
@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);
|
||||
Sensor<Double> sensor2 = VirtualMeasurements.randomDoubleSensor("vac2", Duration.ofMillis(200), 2e-5, 2e-6);
|
||||
Sensor<Double> sensor3 = VirtualMeasurements.randomDoubleSensor("vac3", Duration.ofMillis(200), 1e-7, 1e-8);
|
||||
|
||||
VacCollectorDevice collector = new VacCollectorDevice("collector", GlobalContext.instance(), null, sensor1, sensor2, sensor3);
|
||||
VacCollectorDevice collector = new VacCollectorDevice("collector", GlobalContext.instance(), null, sensor3, sensor2, sensor1);
|
||||
collector.init();
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml"));
|
||||
loader.load();
|
||||
@ -45,18 +50,21 @@ public class TestVac extends Application {
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
controller.startMeasurement();
|
||||
} catch (Exception ex) {
|
||||
throw new Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
if(controller != null){
|
||||
if (controller != null) {
|
||||
controller.stopMeasurement();
|
||||
controller.getDevice().shutdown();
|
||||
}
|
||||
super.stop();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
|
@ -4,31 +4,35 @@
|
||||
<?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="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>
|
||||
<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 AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
<Pane prefHeight="40.0" styleClass="beveled">
|
||||
<Pane styleClass="beveled">
|
||||
<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>
|
||||
</Pane>
|
||||
<Separator prefWidth="200.0" />
|
||||
<Pane prefHeight="60.0" styleClass="beveled">
|
||||
<children>
|
||||
<Label id="pressure" fx:id="valueLabel" alignment="CENTER_RIGHT" layoutX="14.0" prefHeight="60.0" prefWidth="90.0" text="1.22e-7" />
|
||||
<Label id="units" fx:id="unitLabel" layoutX="124.0" prefHeight="60.0" prefWidth="62.0" text="mbar" />
|
||||
</children>
|
||||
</Pane>
|
||||
<Separator prefWidth="200.0" />
|
||||
<Pane maxHeight="1.7976931348623157E308" VBox.vgrow="ALWAYS" />
|
||||
<Separator />
|
||||
<BorderPane>
|
||||
<left>
|
||||
<Label id="pressure" fx:id="valueLabel" alignment="CENTER_RIGHT" prefHeight="60.0" prefWidth="100.0" text="#.##E-0" BorderPane.alignment="CENTER" />
|
||||
</left>
|
||||
<right>
|
||||
<Label id="units" fx:id="unitLabel" prefHeight="60.0" prefWidth="75.0" text="mbar" BorderPane.alignment="CENTER" />
|
||||
</right>
|
||||
<center>
|
||||
<Pane minWidth="-Infinity" prefWidth="25.0" BorderPane.alignment="CENTER" />
|
||||
</center>
|
||||
</BorderPane>
|
||||
<StatusBar fx:id="status" />
|
||||
</children>
|
||||
</VBox>
|
||||
|
@ -2,24 +2,25 @@
|
||||
|
||||
<?import java.net.URL?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Separator?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?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>
|
||||
<URL value="@/styles/vacstyles.css" />
|
||||
</stylesheets>
|
||||
<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>
|
||||
<HBox fx:id="vacBoxHolder" />
|
||||
<BorderPane prefHeight="50.0">
|
||||
<center>
|
||||
<Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<VBox fx:id="vacBoxHolder" styleClass="beveled"/>
|
||||
<Separator orientation="VERTICAL" />
|
||||
<VBox alignment="TOP_CENTER" HBox.hgrow="ALWAYS">
|
||||
<children>
|
||||
<Pane prefHeight="50.0" styleClass="beveled">
|
||||
<children>
|
||||
<Label layoutX="208.0" layoutY="8.0" text="Time: ">
|
||||
<font>
|
||||
@ -33,10 +34,10 @@
|
||||
</Label>
|
||||
</children>
|
||||
</Pane>
|
||||
</center>
|
||||
</BorderPane>
|
||||
<AnchorPane fx:id="plotHolder" VBox.vgrow="ALWAYS" />
|
||||
</children>
|
||||
</VBox>
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
@ -2,24 +2,20 @@
|
||||
* Empty Stylesheet file.
|
||||
*/
|
||||
|
||||
.vacBox {
|
||||
.beveled{
|
||||
-fx-background-color: #BEBEBE;
|
||||
-fx-border-color: #676767 white white #676767;
|
||||
-fx-border-style: solid inside line-join miter;
|
||||
}
|
||||
|
||||
#pressure{
|
||||
.vacBox #pressure{
|
||||
-fx-font-size: 24;
|
||||
-fx-font-weight: bold
|
||||
}
|
||||
|
||||
#units{
|
||||
-fx-font-size: 24;
|
||||
}
|
||||
|
||||
#name{
|
||||
-fx-font-size: 18;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.vacBox #units{
|
||||
-fx-font-size: 24;
|
||||
}
|
||||
|
||||
.vacBox #name{
|
||||
-fx-font-size: 18;
|
||||
}
|
||||
|
||||
.beveled{
|
||||
-fx-border-color: white #676767 #676767 white;
|
||||
-fx-border-style: solid outside line-join bevel;
|
||||
}
|
Loading…
Reference in New Issue
Block a user