vacuum fix

This commit is contained in:
Alexander Nozik 2017-05-18 12:53:21 +03:00
parent 94cd39bbb6
commit 2c58a16fac
12 changed files with 71 additions and 101 deletions

View File

@ -37,7 +37,7 @@ task installAll(type: Copy) {
}
}
if (!configRoot.children().isEmpty()) {
File outFile = file("$buildDir/install/numass-control/config/devices.xml")
File outFile = file("$buildDir/install/numass-control/bin/numass-control.xml")
outFile.getParentFile().mkdirs();
outFile.createNewFile();
new XmlNodePrinter(outFile.newPrintWriter()).print(configRoot)

View File

@ -19,6 +19,7 @@ import hep.dataforge.context.Context;
import hep.dataforge.control.RoleDef;
import hep.dataforge.control.connections.Roles;
import hep.dataforge.control.connections.StorageConnection;
import hep.dataforge.control.devices.PortSensor;
import hep.dataforge.control.devices.SingleMeasurementDevice;
import hep.dataforge.control.devices.StateDef;
import hep.dataforge.control.measurements.AbstractMeasurement;
@ -51,7 +52,7 @@ import java.util.function.Consumer;
*/
@RoleDef(name = Roles.STORAGE_ROLE, objectType = StorageConnection.class)
@RoleDef(name = Roles.VIEW_ROLE)
@StateDef(name = "connected", writable = true, info = "Connection with the device itself")
@StateDef(name = PortSensor.CONNECTED_STATE, writable = true, info = "Connection with the device itself")
@StateDef(name = "storing", writable = true, info = "Define if this device is currently writes to storage")
@StateDef(name = "filamentOn", writable = true, info = "Mass-spectrometer filament on")
@StateDef(name = "filamentStatus", info = "Filament status")
@ -134,7 +135,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
case "storing":
return false;
default:
throw new ControlException("State not defined");
return super.computeState(stateName);
}
}
@ -146,7 +147,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
@Override
protected void requestStateChange(String stateName, Value value) throws ControlException {
switch (stateName) {
case "connected":
case PortSensor.CONNECTED_STATE:
setConnected(value.booleanValue());
case "filamentOn":
setFileamentOn(value.booleanValue());
@ -195,7 +196,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
return false;
}
// connected = true;
updateState("connected", true);
updateState(PortSensor.CONNECTED_STATE, true);
return true;
} else {
handler.unholdBy(this);
@ -267,7 +268,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
}
public boolean isConnected() {
return getState("connected").booleanValue();
return getState(PortSensor.CONNECTED_STATE).booleanValue();
}
public boolean isSelected() {

View File

@ -62,12 +62,12 @@ public abstract class NumassControlApplication<D extends Device> extends Applica
.orElseGet(() -> NumassControlUtils.readResourceMeta("/config/devices.xml"));
Context ctx = NumassControlUtils.setupContext(config);
Meta mspConfig = NumassControlUtils.findDeviceMeta(config, this::acceptDevice)
Meta deviceConfig = NumassControlUtils.findDeviceMeta(config, this::acceptDevice)
.orElseThrow(() -> new RuntimeException("Device configuration not found"));
try {
D d = getDeviceFactory().build(ctx, mspConfig);
D d = getDeviceFactory().build(ctx, deviceConfig);
d.init();
NumassControlUtils.connectStorage(d, config);
Platform.runLater(() -> {

View File

@ -14,6 +14,8 @@ import hep.dataforge.storage.commons.StorageFactory;
import hep.dataforge.storage.commons.StorageManager;
import inr.numass.client.ClientUtils;
import javafx.application.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
@ -38,7 +40,7 @@ public class NumassControlUtils {
if (config.hasMeta("storage") && device.acceptsRole(Roles.STORAGE_ROLE)) {
String numassRun = ClientUtils.getRunName(config);
config.getMetaList("storage").forEach(node -> {
device.getContext().getLogger().debug("Creating storage for device with meta: {}", node);
device.getContext().getLogger().info("Creating storage for device with meta: {}", node);
//building storage in a separate thread
new Thread(() -> {
Storage storage = StorageFactory.buildStorage(device.getContext(), node);
@ -65,7 +67,9 @@ public class NumassControlUtils {
public static Optional<Meta> getConfig(Application app) {
String configFileName = app.getParameters().getNamed().get("config");
Logger logger = LoggerFactory.getLogger(app.getClass());
if (configFileName == null) {
logger.info("Configuration path not defined. Loading configuration from {}",DEFAULT_CONFIG_LOCATION);
configFileName = DEFAULT_CONFIG_LOCATION;
}
File configFile = new File(configFileName);
@ -78,6 +82,7 @@ public class NumassControlUtils {
throw new RuntimeException(e);
}
} else {
logger.warn("Configuration file not found");
return Optional.empty();
}
}

View File

@ -54,29 +54,6 @@ public class CM32Device extends PortSensor<Double> {
return meta().getString("type", "Leibold CM32");
}
// @Override
// protected int timeout() {
// return meta().getInt("timeout", 1000);
// }
@Override
protected Object computeState(String stateName) throws ControlException {
if (getHandler() == null) {
notifyError("No port connection", null);
return null;
}
notifyError("State not found: " + stateName, null);
return null;
//TODO add connection check here
// switch (stateName) {
// case "connection":
// return !talk("T?").isEmpty();
// default:
// notifyError("State not found: " + stateName, null);
// return null;
// }
}
private class CMVacMeasurement extends SimpleMeasurement<Double> {
private static final String CM32_QUERY = "MES R PM 1\r\n";
@ -88,19 +65,19 @@ public class CM32Device extends PortSensor<Double> {
if (answer.isEmpty()) {
this.progressUpdate("No signal");
updateState(CONNECTION_STATE, false);
updateState(CONNECTED_STATE, false);
return null;
} else if (answer.indexOf("PM1:mbar") < -1) {
this.progressUpdate("Wrong answer: " + answer);
updateState(CONNECTION_STATE, false);
updateState(CONNECTED_STATE, false);
return null;
} else if (answer.substring(14, 17).equals("OFF")) {
this.progressUpdate("Off");
updateState(CONNECTION_STATE, true);
updateState(CONNECTED_STATE, true);
return null;
} else {
this.progressUpdate("OK");
updateState(CONNECTION_STATE, true);
updateState(CONNECTED_STATE, true);
return Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23));
}
}

View File

@ -57,11 +57,11 @@ public class MKSBaratronDevice extends PortSensor<Double> {
String answer = getHandler().sendAndWait("AV" + getChannel() + "\r", timeout());
if (answer == null || answer.isEmpty()) {
// invalidateState("connection");
updateState(CONNECTION_STATE, false);
updateState(CONNECTED_STATE, false);
this.progressUpdate("No connection");
return null;
} else {
updateState(CONNECTION_STATE, true);
updateState(CONNECTED_STATE, true);
}
double res = Double.parseDouble(answer);
if (res <= 0) {

View File

@ -68,18 +68,11 @@ public class MKSVacDevice extends PortSensor<Double> {
@Override
protected Object computeState(String stateName) throws ControlException {
if (getHandler() == null) {
notifyError("No port connection", null);
return null;
}
switch (stateName) {
case CONNECTION_STATE:
return !talk("T?").isEmpty();
case "power":
return talk("FP?").equals("ON");
default:
notifyError("State not found: " + stateName, null);
return null;
return super.computeState(stateName);
}
}
@ -97,16 +90,18 @@ public class MKSVacDevice extends PortSensor<Double> {
@Override
public void shutdown() throws ControlException {
if (isConnected()) {
setPowerOn(false);
}
super.shutdown();
}
public boolean isPowerOn() {
private boolean isPowerOn() {
return getState("power").booleanValue();
}
public void setPowerOn(boolean powerOn) throws ControlException {
private void setPowerOn(boolean powerOn) throws ControlException {
if (powerOn != isPowerOn()) {
if (powerOn) {
// String ans = talkMKS(p1Port, "@253ENC!OFF;FF");
@ -155,7 +150,7 @@ public class MKSVacDevice extends PortSensor<Double> {
// if (getState("power").booleanValue()) {
String answer = talk("PR" + getChannel() + "?");
if (answer == null || answer.isEmpty()) {
invalidateState(CONNECTION_STATE);
updateState(CONNECTED_STATE, false);
this.progressUpdate("No connection");
return null;
}
@ -168,9 +163,6 @@ public class MKSVacDevice extends PortSensor<Double> {
this.progressUpdate("OK");
return res;
}
// } else {
// return null;
// }
}
}

View File

@ -70,7 +70,7 @@ public class MeradatVacDevice extends PortSensor<Double> {
if (answer.isEmpty()) {
this.progressUpdate("No signal");
updateState("connection", false);
updateState(CONNECTED_STATE, false);
return null;
} else {
Matcher match = response.matcher(answer);
@ -84,12 +84,12 @@ public class MeradatVacDevice extends PortSensor<Double> {
BigDecimal res = BigDecimal.valueOf(base * Math.pow(10, exp));
res = res.setScale(4, RoundingMode.CEILING);
this.progressUpdate("OK");
updateState("connection", true);
updateState(CONNECTED_STATE, true);
return res.doubleValue();
}
else {
this.progressUpdate("Wrong answer: " + answer);
updateState("connection", false);
updateState(CONNECTED_STATE, false);
return null;
}
}

View File

@ -39,15 +39,18 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import static hep.dataforge.control.devices.PortSensor.CONNECTED_STATE;
/**
* @author <a href="mailto:altavir@gmail.com">Alexander Nozik</a>
*/
@RoleDef(name = Roles.STORAGE_ROLE, objectType = PointListener.class, info = "Storage for acquired points")
@RoleDef(name = Roles.STORAGE_ROLE, objectType = StorageConnection.class, info = "Storage for acquired points")
@StateDef(name = "storing", writable = true, info = "Define if this device is currently writes to storage")
public class VacCollectorDevice extends Sensor<DataPoint> {
private Map<String, Sensor<Double>> sensorMap = new LinkedHashMap<>();
private int delay = 5000;
private StorageHelper helper = new StorageHelper(VacCollectorDevice.this, this::buildLoader);
public VacCollectorDevice() {
}
@ -78,11 +81,7 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
}
}
@Override
protected Object computeState(String stateName) throws ControlException {
//TODO add dot path notation for states
return Value.NULL;
}
@Override
protected Measurement<DataPoint> createMeasurement() {
@ -96,7 +95,7 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
}
public void setDelay(int delay) throws MeasurementException {
this.delay = 5000;
this.delay = delay;
if (isMeasuring()) {
getMeasurement().stop(false);
getMeasurement().start();
@ -111,6 +110,21 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
}
}
private PointLoader buildLoader(StorageConnection connection) {
TableFormatBuilder format = new TableFormatBuilder().setType("timestamp", ValueType.TIME);
getSensors().forEach((s) -> {
format.setType(s.getName(), ValueType.NUMBER);
});
return LoaderFactory.buildPointLoder(connection.getStorage(), "vactms", "", "timestamp", format.build());
}
@Override
public void onMeasurementResult(Measurement<DataPoint> measurement, DataPoint result, Instant time) {
super.onMeasurementResult(measurement, result, time);
helper.push(result);
}
public Collection<Sensor<Double>> getSensors() {
return sensorMap.values();
}
@ -120,21 +134,19 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
private final ValueCollector collector = new PointCollector(this::result, sensorMap.keySet());
private ScheduledExecutorService executor;
private ScheduledFuture<?> currentTask;
private StorageHelper helper;
@Override
public void start() {
helper = new StorageHelper(VacCollectorDevice.this, this::buildLoader);
executor = Executors
.newSingleThreadScheduledExecutor((Runnable r) -> new Thread(r, "VacuumMeasurement thread"));
currentTask = executor.scheduleWithFixedDelay(() -> {
sensorMap.values().forEach((sensor) -> {
try {
Object value;
if (sensor.optBooleanState("disabled").orElse(false)) {
value = null;
} else {
if (sensor.optBooleanState(CONNECTED_STATE).orElse(false)) {
value = sensor.read();
} else {
value = null;
}
collector.put(sensor.getName(), value);
} catch (Exception ex) {
@ -144,6 +156,7 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
}, 0, delay, TimeUnit.MILLISECONDS);
}
@Override
protected synchronized void result(DataPoint result, Instant time) {
super.result(result, time);
@ -152,15 +165,6 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
});
}
private PointLoader buildLoader(StorageConnection connection) {
TableFormatBuilder format = new TableFormatBuilder().setType("timestamp", ValueType.TIME);
getSensors().forEach((s) -> {
format.setType(s.getName(), ValueType.NUMBER);
});
return LoaderFactory.buildPointLoder(connection.getStorage(), "vactms", "", "timestamp", format.build());
}
private DataPoint terminator() {
MapPoint.Builder p = new MapPoint.Builder();
p.putValue("timestamp", DateTimeUtils.now());

View File

@ -32,6 +32,8 @@ import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ResourceBundle;
import static hep.dataforge.control.devices.PortSensor.CONNECTED_STATE;
/**
* @author <a href="mailto:altavir@gmail.com">Alexander Nozik</a>
*/
@ -40,14 +42,14 @@ public class VacuumeterView extends DeviceViewConnection<Sensor<Double>> impleme
private static final DecimalFormat FORMAT = new DecimalFormat("0.###E0");
private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ISO_LOCAL_TIME;
protected Node node;
Node node;
@FXML
private BorderPane root;
@FXML
protected Label deviceNameLabel;
Label deviceNameLabel;
@FXML
protected Label unitLabel;
Label unitLabel;
@FXML
private Label valueLabel;
@FXML
@ -86,9 +88,9 @@ public class VacuumeterView extends DeviceViewConnection<Sensor<Double>> impleme
Platform.runLater(() -> {
unitLabel.setText(getDevice().meta().getString("units", "mbar"));
deviceNameLabel.setText(getDevice().getName());
disableButton.setSelected(!getDevice().optBooleanState("disabled").orElse(false));
disableButton.setSelected(getDevice().optBooleanState(CONNECTED_STATE).orElse(false));
disableButton.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
getDevice().setState("disabled",!newValue);
getDevice().setState(CONNECTED_STATE, newValue);
if (!newValue) {
valueLabel.setText("---");
}
@ -133,7 +135,7 @@ public class VacuumeterView extends DeviceViewConnection<Sensor<Double>> impleme
}
public String getTitle() {
String getTitle() {
return getDevice().meta().getString("title", getDevice().getName());
}

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<config>
<storage path="D:/temp/test"/>
<device type="numass:vac">
<sensor name="P1" color="red" port="com::/dev/ttyUSB0" sensorType="mks"/>
<sensor name="P2" color="blue" port="tcp::192.168.111.32:4002" sensorType="CM32"/>
<sensor name="P3" color="green" port="tcp::192.168.111.32:4003" sensorType="CM32"/>
<!--<sensor name="Px" color="black" port="com::/dev/ttyUSB1" sensorType="meradat"/> -->
<sensor name="Px" color="black" port="tcp::192.168.111.33:4003" sensorType="meradat" address="1"/>
<sensor name="Baratron" color="cyan" port="tcp::192.168.111.33:4004" sensorType="baratron"/>
<!--<sensor name="collector" color="magenta" port="tcp::192.168.111.33:4003" sensorType="meradat" address="5"/>-->
<sensor name="collector" color="magenta" port="tcp::192.168.111.33:4003" sensorType="meradat" address="5"/>
</device>
</config>

View File

@ -1,22 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import org.controlsfx.control.*?>
<?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.ToggleSwitch?>
<AnchorPane styleClass="vacBox" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<?import java.net.URL?>
<AnchorPane styleClass="vacBox" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="@/styles/vacstyles.css" />
</stylesheets>
@ -26,7 +15,7 @@
<AnchorPane styleClass="namePane">
<children>
<Label id="name" fx:id="deviceNameLabel" alignment="CENTER" prefHeight="40.0" text="device Name" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="50.0" AnchorPane.topAnchor="0.0" />
<ToggleSwitch fx:id="disableButton" alignment="CENTER" layoutX="130.0" layoutY="10.0" prefWidth="40.0" selected="true" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0" />
<ToggleSwitch fx:id="disableButton" alignment="CENTER" layoutX="130.0" layoutY="10.0" prefWidth="40.0" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0" />
</children>
</AnchorPane>
<Separator />