[no commit message]

This commit is contained in:
Alexander Nozik 2016-04-12 22:38:43 +03:00
parent ee669b0968
commit f9e63d9e2c
28 changed files with 262 additions and 193 deletions

View File

@ -46,7 +46,7 @@ public class Talk {
portName = args[0]; portName = args[0];
} }
PortHandler handler; PortHandler handler;
handler = PortFactory.buildPort(portName); handler = PortFactory.getdPort(portName);
handler.setPhraseCondition((String str) -> str.endsWith("\r")); handler.setPhraseCondition((String str) -> str.endsWith("\r"));
// MagnetController controller = new MagnetController(handler, 1); // MagnetController controller = new MagnetController(handler, 1);

View File

@ -33,21 +33,27 @@ public class VirtualLambdaPort extends VirtualPort {
private volatile int currentAddress = -1; private volatile int currentAddress = -1;
private Map<Integer, VirtualMagnetStatus> magnets = new HashMap<>(); private Map<Integer, VirtualMagnetStatus> magnets = new HashMap<>();
private final String virtualPortName;
public VirtualLambdaPort(String portName, Map<Integer, Double> magnets) { public VirtualLambdaPort(String portName, Map<Integer, Double> magnets) {
super(portName); this.virtualPortName = portName;
magnets.entrySet().stream().forEach((entry) -> { magnets.entrySet().stream().forEach((entry) -> {
this.magnets.put(entry.getKey(), new VirtualMagnetStatus(entry.getValue())); this.magnets.put(entry.getKey(), new VirtualMagnetStatus(entry.getValue()));
}); });
} }
public VirtualLambdaPort(String portName, int... magnets) { public VirtualLambdaPort(String portName, int... magnets) {
super(portName); this.virtualPortName = portName;
for (int magnet : magnets) { for (int magnet : magnets) {
this.magnets.put(magnet, new VirtualMagnetStatus(0.01)); this.magnets.put(magnet, new VirtualMagnetStatus(0.01));
} }
} }
@Override
public String getPortId() {
return virtualPortName;
}
@Override @Override
protected void evaluateRequest(String request) { protected void evaluateRequest(String request) {
String comand; String comand;

View File

@ -71,7 +71,7 @@ public class MagnetControllerApp extends Application {
if(portName.equals("virtual")){ if(portName.equals("virtual")){
handler = new VirtualLambdaPort("COM12", 1, 2, 3, 4); handler = new VirtualLambdaPort("COM12", 1, 2, 3, 4);
} else { } else {
handler = PortFactory.buildPort(portName); handler = PortFactory.getdPort(portName);
//TODO add meta reader here //TODO add meta reader here
} }

View File

@ -1,6 +1,6 @@
apply plugin: 'application' apply plugin: 'application'
version = "0.2.2" version = "0.2.3"
if (!hasProperty('mainClass')) { if (!hasProperty('mainClass')) {
ext.mainClass = 'inr.numass.control.msp.fx.MspApp' ext.mainClass = 'inr.numass.control.msp.fx.MspApp'

View File

@ -71,7 +71,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
String ip = meta().getString("connection.ip", "127.0.0.1"); String ip = meta().getString("connection.ip", "127.0.0.1");
int port = meta().getInt("connection.port", 10014); int port = meta().getInt("connection.port", 10014);
getLogger().info("Connection to MKS mass-spectrometer on {}:{}...", ip, port); getLogger().info("Connection to MKS mass-spectrometer on {}:{}...", ip, port);
handler = new TcpPortHandler(ip, port, "msp"); handler = new TcpPortHandler(ip, port);
handler.setDelimeter("\r\r"); handler.setDelimeter("\r\r");
handler.holdBy(this); handler.holdBy(this);
setConnected(true); setConnected(true);
@ -125,22 +125,20 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
} }
@Override @Override
protected boolean applyState(String stateName, Value stateValue) throws ControlException { public void command(String commandName, Value argument) throws ControlException {
switch (stateName) { switch(commandName){
case "connected": case "connect":
return setConnected(stateValue.booleanValue()); setConnected(argument.booleanValue());
case "filamentOn": case "setFilamentOn":
return setFileamentOn(stateValue.booleanValue()); setFileamentOn(argument.booleanValue());
default: default:
return super.applyState(stateName, stateValue); super.command(commandName, argument);
} }
} }
/** /**
* Startup MSP: get available sensors, select sensor and control. * Startup MSP: get available sensors, select sensor and control.
* *
* @param measurement
* @throws hep.dataforge.exceptions.PortException
*/ */
public boolean setConnected(boolean connected) throws ControlException { public boolean setConnected(boolean connected) throws ControlException {
String sensorName; String sensorName;
@ -217,8 +215,8 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
} }
/** /**
* Send specific command and wait for its results (the onResult must begin * Send specific command and wait for its results (the result must begin
* with command name) with command name)
* *
* @param commandName * @param commandName
* @param paremeters * @param paremeters

View File

@ -1,6 +1,6 @@
apply plugin: 'application' apply plugin: 'application'
version = "0.4.0-SNAPSHOT" version = "0.4.0"
if (!hasProperty('mainClass')) { if (!hasProperty('mainClass')) {
ext.mainClass = 'inr.numass.readvac.Main' ext.mainClass = 'inr.numass.readvac.Main'
@ -9,10 +9,7 @@ mainClassName = mainClass
dependencies { dependencies {
compile 'ch.qos.logback:logback-classic:1.1.0+' compile project(':numass-storage:numass-client')
compile 'org.scream3r:jssc:2.8.0'
compile 'commons-cli:commons-cli:1.3'
compile project(':dataforge-plots') compile project(':dataforge-plots')
compile project(':dataforge-storage')
compile project(':dataforge-control') compile project(':dataforge-control')
} }

View File

@ -6,12 +6,15 @@
package inr.numass.readvac.app; package inr.numass.readvac.app;
import hep.dataforge.control.measurements.Sensor; import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.Meta;
import inr.numass.readvac.devices.CM32Device; import inr.numass.readvac.devices.CM32Device;
import inr.numass.readvac.devices.MKSBaratronDevice; import inr.numass.readvac.devices.MKSBaratronDevice;
import inr.numass.readvac.devices.MKSVacDevice; import inr.numass.readvac.devices.MKSVacDevice;
import inr.numass.readvac.devices.VITVacDevice; import inr.numass.readvac.devices.VITVacDevice;
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.File;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
@ -27,23 +30,39 @@ public class ReadVac extends Application {
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
Sensor<Double> p1 = new MKSVacDevice("com::/dev/ttyUSB0"); String configFileName = getParameters().getNamed().get("config");
p1.setName("P1"); if (configFileName == null) {
configFileName = "vac-config.xml";
}
File configFile = new File(configFileName);
Meta config;
if (configFile.exists()) {
config = MetaFileReader.read(configFile).build();
} else {
config = Meta.empty();
}
Sensor<Double> p1 = new MKSVacDevice(config.getString("p1.port","com::/dev/ttyUSB0"));
p1.configure(config.getNode("p1",Meta.empty()));
p1.setName(config.getString("p1.name","P1"));
p1.getConfig().putValue("powerButton", true); p1.getConfig().putValue("powerButton", true);
Sensor<Double> p2 = new CM32Device("tcp::192.168.111.32:4002"); Sensor<Double> p2 = new CM32Device(config.getString("p2.port","tcp::192.168.111.32:4002"));
p2.setName("P2"); p1.configure(config.getNode("p2",Meta.empty()));
Sensor<Double> p3 = new CM32Device("tcp::192.168.111.32:4003"); p2.setName(config.getString("p2.name","P2"));
p3.setName("P3"); Sensor<Double> p3 = new CM32Device(config.getString("p3.port","tcp::192.168.111.32:4003"));
Sensor<Double> px = new VITVacDevice("com::/dev/ttyUSB1"); p1.configure(config.getNode("p3",Meta.empty()));
px.setName("Px"); p3.setName(config.getString("p3.name","P3"));
Sensor<Double> baratron = new MKSBaratronDevice("tcp::192.168.111.33:4004"); Sensor<Double> px = new VITVacDevice(config.getString("px.port","com::/dev/ttyUSB1"));
baratron.setName("Baratron"); p1.configure(config.getNode("px",Meta.empty()));
px.setName(config.getString("px.name","Px"));
Sensor<Double> baratron = new MKSBaratronDevice(config.getString("baratron.port","tcp::192.168.111.33:4004"));
baratron.setName(config.getString("baratron.name","Baratron"));
p1.configure(config.getNode("baratron",Meta.empty()));
VacCollectorDevice collector = new VacCollectorDevice(); VacCollectorDevice collector = new VacCollectorDevice();
collector.setSensors(p1, p2, p3, px, baratron); collector.setSensors(p1, p2, p3, px, baratron);
// collector.setSensors(baratron);
collector.init(); collector.init();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml"));
loader.load(); loader.load();
controller = loader.getController(); controller = loader.getController();

View File

@ -5,8 +5,8 @@
*/ */
package inr.numass.readvac.devices; package inr.numass.readvac.devices;
import hep.dataforge.control.devices.PortSensor;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.measurements.SimpleMeasurement; import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.ports.ComPortHandler; import hep.dataforge.control.ports.ComPortHandler;
import hep.dataforge.control.ports.PortHandler; import hep.dataforge.control.ports.PortHandler;
@ -20,7 +20,7 @@ import hep.dataforge.exceptions.ControlException;
@ValueDef(name = "port") @ValueDef(name = "port")
@ValueDef(name = "delay") @ValueDef(name = "delay")
@ValueDef(name = "timeout") @ValueDef(name = "timeout")
public class CM32Device extends NumassVacDevice { public class CM32Device extends PortSensor<Double> {
public CM32Device(String portName) { public CM32Device(String portName) {
super(portName); super(portName);
@ -75,19 +75,19 @@ public class CM32Device extends NumassVacDevice {
if (answer.isEmpty()) { if (answer.isEmpty()) {
this.onProgressUpdate("No signal"); this.onProgressUpdate("No signal");
updateState("connection", false); updateState(CONNECTION_STATE, false);
return null; return null;
} else if (answer.indexOf("PM1:mbar") < -1) { } else if (answer.indexOf("PM1:mbar") < -1) {
this.onProgressUpdate("Wrong answer: " + answer); this.onProgressUpdate("Wrong answer: " + answer);
updateState("connection", false); updateState(CONNECTION_STATE, false);
return null; return null;
} else if (answer.substring(14, 17).equals("OFF")) { } else if (answer.substring(14, 17).equals("OFF")) {
this.onProgressUpdate("Off"); this.onProgressUpdate("Off");
updateState("connection", true); updateState(CONNECTION_STATE, true);
return null; return null;
} else { } else {
this.onProgressUpdate("OK"); this.onProgressUpdate("OK");
updateState("connection", true); updateState(CONNECTION_STATE, true);
return Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23)); return Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23));
} }
} }

View File

@ -5,6 +5,7 @@
*/ */
package inr.numass.readvac.devices; package inr.numass.readvac.devices;
import hep.dataforge.control.devices.PortSensor;
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.measurements.SimpleMeasurement; import hep.dataforge.control.measurements.SimpleMeasurement;
@ -19,12 +20,8 @@ import java.util.regex.Pattern;
* *
* @author Alexander Nozik * @author Alexander Nozik
*/ */
@ValueDef(name = "address")
@ValueDef(name = "channel") @ValueDef(name = "channel")
@ValueDef(name = "port") public class MKSBaratronDevice extends PortSensor<Double> {
@ValueDef(name = "delay")
@ValueDef(name = "timeout")
public class MKSBaratronDevice extends NumassVacDevice {
public MKSBaratronDevice(String portName) { public MKSBaratronDevice(String portName) {
super(portName); super(portName);

View File

@ -5,9 +5,9 @@
*/ */
package inr.numass.readvac.devices; package inr.numass.readvac.devices;
import hep.dataforge.control.devices.PortSensor;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.SimpleMeasurement; import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.ports.ComPortHandler;
import hep.dataforge.control.ports.PortHandler; import hep.dataforge.control.ports.PortHandler;
import hep.dataforge.description.ValueDef; import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ControlException; import hep.dataforge.exceptions.ControlException;
@ -21,12 +21,9 @@ import javafx.beans.property.adapter.JavaBeanBooleanPropertyBuilder;
* *
* @author Alexander Nozik * @author Alexander Nozik
*/ */
@ValueDef(name = "address") @ValueDef(name = "address", def = "253")
@ValueDef(name = "channel") @ValueDef(name = "channel", def = "5")
@ValueDef(name = "port") public class MKSVacDevice extends PortSensor<Double> {
@ValueDef(name = "delay")
@ValueDef(name = "timeout")
public class MKSVacDevice extends NumassVacDevice {
public MKSVacDevice(String portName) { public MKSVacDevice(String portName) {
super(portName); super(portName);
@ -78,14 +75,12 @@ public class MKSVacDevice extends NumassVacDevice {
} }
@Override @Override
protected boolean applyState(String stateName, Value stateValue) throws ControlException { public void command(String commandName, Value argument) throws ControlException {
switch (stateName) { if (commandName.equals("setPower")) {
case "power": boolean powerOn = argument.booleanValue();
boolean powerOn = stateValue.booleanValue(); setPowerOn(powerOn);
setPowerOn(powerOn); } else {
return powerOn == isPowerOn(); super.command(commandName, argument);
default:
return super.applyState(stateName, stateValue);
} }
} }
@ -102,14 +97,14 @@ public class MKSVacDevice extends NumassVacDevice {
// } // }
String ans = talk("FP!ON"); String ans = talk("FP!ON");
if (ans.equals("ON")) { if (ans.equals("ON")) {
setState("power", true); updateState("power", true);
} else { } else {
this.notifyError("Failed to set power state", null); this.notifyError("Failed to set power state", null);
} }
} else { } else {
String ans = talk("FP!OFF"); String ans = talk("FP!OFF");
if (ans.equals("OFF")) { if (ans.equals("OFF")) {
setState("power", false); updateState("power", false);
} else { } else {
this.notifyError("Failed to set power state", null); this.notifyError("Failed to set power state", null);
} }

View File

@ -1,71 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.readvac.devices;
import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.ports.PortFactory;
import hep.dataforge.control.ports.PortHandler;
import hep.dataforge.exceptions.ControlException;
/**
*
* @author darksnake
*/
public abstract class NumassVacDevice extends Sensor<Double> {
private PortHandler handler;
private final String portName;
public NumassVacDevice(String portName) {
this.portName = portName;
}
protected final void setHandler(PortHandler handler) {
this.handler = handler;
}
public boolean isConnected() {
return getState("connection").booleanValue();
}
protected int timeout() {
return meta().getInt("timeout", 400);
}
protected PortHandler buildHandler(String portName) throws ControlException {
getLogger().info("Connecting to port {}", portName);
return PortFactory.buildPort(portName);
}
@Override
public void shutdown() throws ControlException {
super.shutdown();
try {
handler.close();
} catch (Exception ex) {
throw new ControlException(ex);
}
}
/**
* @return the handler
* @throws hep.dataforge.exceptions.ControlException
*/
protected PortHandler getHandler() throws ControlException {
if (handler == null) {
String port = meta().getString("port", portName);
this.handler = buildHandler(port);
}
if (!handler.isOpen()) {
handler.open();
}
return handler;
}
}

View File

@ -5,12 +5,10 @@
*/ */
package inr.numass.readvac.devices; package inr.numass.readvac.devices;
import hep.dataforge.control.devices.PortSensor;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.control.measurements.SimpleMeasurement; import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.ports.ComPortHandler;
import hep.dataforge.control.ports.PortHandler; import hep.dataforge.control.ports.PortHandler;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.ControlException; import hep.dataforge.exceptions.ControlException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
@ -21,10 +19,7 @@ import java.util.regex.Pattern;
* *
* @author Alexander Nozik * @author Alexander Nozik
*/ */
@ValueDef(name = "port") public class VITVacDevice extends PortSensor<Double> {
@ValueDef(name = "delay")
@ValueDef(name = "timeout")
public class VITVacDevice extends NumassVacDevice {
public VITVacDevice(String portName) { public VITVacDevice(String portName) {
super(portName); super(portName);

View File

@ -7,13 +7,17 @@ package inr.numass.readvac.devices;
import hep.dataforge.control.collectors.PointCollector; import hep.dataforge.control.collectors.PointCollector;
import hep.dataforge.control.collectors.ValueCollector; import hep.dataforge.control.collectors.ValueCollector;
import hep.dataforge.control.connections.Roles;
import hep.dataforge.control.devices.annotations.RoleDef;
import hep.dataforge.control.measurements.AbstractMeasurement; import hep.dataforge.control.measurements.AbstractMeasurement;
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.points.DataPoint; import hep.dataforge.points.DataPoint;
import hep.dataforge.exceptions.ControlException; import hep.dataforge.exceptions.ControlException;
import hep.dataforge.exceptions.MeasurementException; import hep.dataforge.exceptions.MeasurementException;
import hep.dataforge.points.PointListener;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import java.time.Instant;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -27,6 +31,7 @@ import java.util.concurrent.TimeUnit;
* *
* @author Alexander Nozik <altavir@gmail.com> * @author Alexander Nozik <altavir@gmail.com>
*/ */
@RoleDef(name = Roles.STORAGE_ROLE, objectType = PointListener.class, info = "Storage for acquired points")
public class VacCollectorDevice extends Sensor<DataPoint> { public class VacCollectorDevice extends Sensor<DataPoint> {
private Map<String, Sensor> sensorMap = new HashMap<>(); private Map<String, Sensor> sensorMap = new HashMap<>();
@ -38,6 +43,13 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
} }
} }
public void setSensors(Iterable<Sensor> sensors) {
sensorMap = new LinkedHashMap<>();
for (Sensor sensor : sensors) {
sensorMap.put(sensor.getName(), sensor);
}
}
@Override @Override
protected Object calculateState(String stateName) throws ControlException { protected Object calculateState(String stateName) throws ControlException {
//TODO add dot path notation for states //TODO add dot path notation for states
@ -68,10 +80,8 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
super.shutdown(); super.shutdown();
for (Sensor sensor : getSensors()) { for (Sensor sensor : getSensors()) {
sensor.shutdown(); sensor.shutdown();
} }
} }
public Collection<Sensor> getSensors() { public Collection<Sensor> getSensors() {
return sensorMap.values(); return sensorMap.values();
@ -79,7 +89,7 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
private class VacuumMeasurement extends AbstractMeasurement<DataPoint> { private class VacuumMeasurement extends AbstractMeasurement<DataPoint> {
private final ValueCollector collector = new PointCollector(this::onResult, sensorMap.keySet()); private final ValueCollector collector = new PointCollector(this::result, sensorMap.keySet());
private ScheduledExecutorService executor; private ScheduledExecutorService executor;
private ScheduledFuture<?> currentTask; private ScheduledFuture<?> currentTask;
@ -100,6 +110,14 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
}, 0, meta().getInt("delay", 5000), TimeUnit.MILLISECONDS); }, 0, meta().getInt("delay", 5000), TimeUnit.MILLISECONDS);
} }
@Override
protected synchronized void result(DataPoint result, Instant time) {
super.result(result, time);
forEachTypedConnection(Roles.STORAGE_ROLE, PointListener.class, (PointListener listener) -> {
listener.accept(result);
});
}
@Override @Override
public boolean stop(boolean force) { public boolean stop(boolean force) {
boolean isRunning = currentTask != null; boolean isRunning = currentTask != null;

View File

@ -5,9 +5,13 @@
*/ */
package inr.numass.readvac.fx; package inr.numass.readvac.fx;
import hep.dataforge.exceptions.ControlException;
import hep.dataforge.values.Value;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
@ -43,7 +47,11 @@ public class PoweredVacuumeterView extends VacuumeterView {
unitLabel.setText(getDevice().meta().getString("units", "mbar")); unitLabel.setText(getDevice().meta().getString("units", "mbar"));
deviceNameLabel.setText(getDevice().getName()); deviceNameLabel.setText(getDevice().getName());
powerSwitch.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { powerSwitch.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
getDevice().setState("power", newValue); try {
getDevice().command("setPower", Value.of(newValue));
} catch (ControlException ex) {
Logger.getLogger(PoweredVacuumeterView.class.getName()).log(Level.SEVERE, null, ex);
}
}); });
} }

View File

@ -5,6 +5,7 @@
*/ */
package inr.numass.readvac.fx; package inr.numass.readvac.fx;
import hep.dataforge.control.connections.Connection;
import hep.dataforge.control.connections.Roles; import hep.dataforge.control.connections.Roles;
import hep.dataforge.control.devices.Device; import hep.dataforge.control.devices.Device;
import hep.dataforge.control.devices.DeviceListener; import hep.dataforge.control.devices.DeviceListener;
@ -14,6 +15,7 @@ import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.points.DataPoint; import hep.dataforge.points.DataPoint;
import hep.dataforge.exceptions.ControlException; import hep.dataforge.exceptions.ControlException;
import hep.dataforge.exceptions.MeasurementException; import hep.dataforge.exceptions.MeasurementException;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder; import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.plots.PlotFrame; import hep.dataforge.plots.PlotFrame;
@ -21,13 +23,24 @@ import hep.dataforge.plots.data.DynamicPlottable;
import hep.dataforge.plots.data.DynamicPlottableSet; import hep.dataforge.plots.data.DynamicPlottableSet;
import hep.dataforge.plots.fx.PlotContainer; import hep.dataforge.plots.fx.PlotContainer;
import hep.dataforge.plots.jfreechart.JFreeChartFrame; import hep.dataforge.plots.jfreechart.JFreeChartFrame;
import hep.dataforge.points.FormatBuilder;
import hep.dataforge.points.PointListener;
import hep.dataforge.storage.api.PointLoader;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.commons.LoaderFactory;
import hep.dataforge.storage.commons.StorageManager;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import hep.dataforge.values.ValueType;
import inr.numass.readvac.devices.VacCollectorDevice; import inr.numass.readvac.devices.VacCollectorDevice;
import java.net.URL; import java.net.URL;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.stream.Collectors;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
@ -41,6 +54,7 @@ import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.util.Duration; import javafx.util.Duration;
import org.controlsfx.control.Notifications; import org.controlsfx.control.Notifications;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
@ -50,9 +64,15 @@ import org.slf4j.LoggerFactory;
*/ */
public class VacCollectorController implements Initializable, DeviceListener, MeasurementListener<DataPoint> { public class VacCollectorController implements Initializable, DeviceListener, MeasurementListener<DataPoint> {
private final Logger logger = LoggerFactory.getLogger("ValCollector");
private final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
private final String[] intervalNames = {"1 sec", "5 sec", "10 sec", "30 sec", "1 min"}; private final String[] intervalNames = {"1 sec", "5 sec", "10 sec", "30 sec", "1 min"};
private final int[] intervals = {1000, 5000, 10000, 30000, 60000}; private final int[] intervals = {1000, 5000, 10000, 30000, 60000};
private LoaderConnection storageConnection;
private VacCollectorDevice device; private VacCollectorDevice device;
private final List<VacuumeterView> views = new ArrayList<>(); private final List<VacuumeterView> views = new ArrayList<>();
private PlotContainer plotContainer; private PlotContainer plotContainer;
@ -68,6 +88,10 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
private ChoiceBox<String> intervalSelector; private ChoiceBox<String> intervalSelector;
@FXML @FXML
private ToggleButton startStopButton; private ToggleButton startStopButton;
@FXML
private ToggleButton storeButton;
@FXML
private ToggleButton logButton;
/** /**
* Initializes the controller class. * Initializes the controller class.
@ -112,7 +136,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
if (plottables != null) { if (plottables != null) {
plottables.put(result); plottables.put(result);
} }
Platform.runLater(() -> timeLabel.setText(time.toString())); Platform.runLater(() -> timeLabel.setText(TIME_FORMAT.format(LocalDateTime.ofInstant(time, ZoneId.systemDefault()))));
} }
private void setupView() { private void setupView() {
@ -168,7 +192,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
getDevice().stopMeasurement(false); getDevice().stopMeasurement(false);
for (Sensor sensor : getDevice().getSensors()) { for (Sensor sensor : getDevice().getSensors()) {
sensor.stopMeasurement(false); sensor.stopMeasurement(false);
} }
} catch (ControlException ex) { } catch (ControlException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -185,4 +209,63 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
} }
} }
@FXML
private void onStoreToggle(ActionEvent event) {
if (storeButton.isSelected()) {
try {
Meta storageConfig = device.meta().getNode("storage");
Storage storage = StorageManager.buildFrom(device.getContext())
.buildStorage(storageConfig);
storageConnection = new LoaderConnection(storage, device.meta().getString("storage.shelf", ""));
device.connect(storageConnection, Roles.STORAGE_ROLE);
} catch (Exception ex) {
logger.error("Failed to start data storing", ex);
storeButton.setSelected(false);
}
} else if (storageConnection != null) {
device.disconnect(storageConnection);
}
}
@FXML
private void onLogToggle(ActionEvent event) {
}
private class LoaderConnection implements PointListener, Connection<Device> {
private final PointLoader loader;
public LoaderConnection(Storage storage, String shelfName) throws StorageException {
this.loader = LoaderFactory.buildPointLoder(storage, "vactms", shelfName, "timestamp",
new FormatBuilder(device.getSensors().stream().map(sensor -> sensor.getName()).collect(Collectors.toList()))
.setFormat("timestamp", ValueType.TIME)
.build());
}
@Override
public void accept(DataPoint point) {
try {
loader.push(point);
} catch (StorageException ex) {
logger.error("Error while pushing data", ex);
}
}
@Override
public boolean isOpen() {
return loader.isOpen();
}
@Override
public void open(Device object) throws Exception {
loader.open();
}
@Override
public void close() throws Exception {
loader.close();
}
}
} }

View File

@ -17,6 +17,9 @@ import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.fxml.FXML; import javafx.fxml.FXML;
@ -33,6 +36,7 @@ import javafx.scene.paint.Color;
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");
private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ISO_LOCAL_TIME;
protected Node node; protected Node node;
@ -115,7 +119,7 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
String resString = FORMAT.format(result); String resString = FORMAT.format(result);
Platform.runLater(() -> { Platform.runLater(() -> {
valueLabel.setText(resString); valueLabel.setText(resString);
setStatus("OK: " + time.toString()); setStatus("OK: " + TIME_FORMAT.format(LocalDateTime.ofInstant(time, ZoneId.systemDefault())));
}); });
} }

View File

@ -6,7 +6,6 @@
package inr.numass.readvac.test; package inr.numass.readvac.test;
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.meta.MetaBuilder; import hep.dataforge.meta.MetaBuilder;
import inr.numass.readvac.devices.VacCollectorDevice; import inr.numass.readvac.devices.VacCollectorDevice;
@ -31,29 +30,34 @@ 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 {
// throw new RuntimeException("not connected");
// try {
// Thread.sleep(2000);
// } catch (InterruptedException ex) {
// LoggerFactory.getLogger(getClass()).info("Sleep interrupted on demo device");
// }
return null;
}
})
.addState("power")
.setMeta(new MetaBuilder("device")
.setValue("color", "magenta")
.setValue("thickness", 3))
.build();
// Sensor<Double> poweredSensor = new VirtualSensorFactory<Double>(
// "vac4",
// (sensor) -> {
// if (sensor.getState("power").booleanValue()) {
// return 1e-6;
// } else {
// return null;
// }
// })
// .addState("power")
// .setMeta(new MetaBuilder("device")
// .setValue("color", "magenta")
// .setValue("thickness", 3)
// .setValue("powerButton", true))
// .addCommand("setPower", new BiConsumer<Sensor<Double>, Value>() {
// @Override
// public void accept(Sensor<Double> sensor, Value power) {
//
// }
// })
// .build();
VacCollectorDevice collector = new VacCollectorDevice(); VacCollectorDevice collector = new VacCollectorDevice();
collector.setSensors(sensor1, sensor2, sensor3, poweredSensor); collector.setSensors(sensor1, sensor2, sensor3);
collector.init(); collector.init();
collector.getConfig().putNode(new MetaBuilder("storage").putValue("path", "D:\\temp\\test").putValue("monitor", false));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml"));
loader.load(); loader.load();
controller = loader.getController(); controller = loader.getController();
@ -64,7 +68,6 @@ public class TestVac extends Application {
primaryStage.setTitle("Vacuum measurement test"); primaryStage.setTitle("Vacuum measurement test");
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.show(); primaryStage.show();
controller.startMeasurement();
} catch (Exception ex) { } catch (Exception ex) {
throw new Error(ex); throw new Error(ex);
} }

View File

@ -9,6 +9,7 @@
<?import javafx.scene.control.ToolBar?> <?import javafx.scene.control.ToolBar?>
<?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?>
@ -29,16 +30,20 @@
<ToolBar> <ToolBar>
<items> <items>
<ToggleButton fx:id="startStopButton" mnemonicParsing="false" onAction="#onStartStopToggle" text="Measure" /> <ToggleButton fx:id="startStopButton" mnemonicParsing="false" onAction="#onStartStopToggle" text="Measure" />
<ToggleButton fx:id="storeButton" mnemonicParsing="false" onAction="#onStoreToggle" text="Store" />
<Separator orientation="VERTICAL" /> <Separator orientation="VERTICAL" />
<Label text="Interval: " /> <Label text="Interval: " />
<ChoiceBox fx:id="intervalSelector" prefWidth="150.0" /> <ChoiceBox fx:id="intervalSelector" prefWidth="150.0" />
<Separator orientation="VERTICAL" /> <Separator orientation="VERTICAL" />
<Pane maxWidth="1.7976931348623157E308" />
<Separator orientation="VERTICAL" />
<ToggleButton fx:id="logButton" mnemonicParsing="false" onAction="#onLogToggle" text="Log" />
</items> </items>
</ToolBar> </ToolBar>
<AnchorPane fx:id="plotHolder" VBox.vgrow="ALWAYS" /> <AnchorPane fx:id="plotHolder" VBox.vgrow="ALWAYS" />
<HBox styleClass="beveled"> <HBox styleClass="beveled">
<children> <children>
<Label alignment="CENTER_RIGHT" text="Time: "> <Label alignment="CENTER_RIGHT" text="Last update: ">
<font> <font>
<Font size="24.0" /> <Font size="24.0" />
</font> </font>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<numass-vac>
<p1 name="P1" color="red" port="com::/dev/ttyUSB0"/>
<p2 name="P2" color="blue" port="tcp::192.168.111.32:4002"/>
<p3 name="P3" color="green" port="tcp::192.168.111.32:4003"/>
<px name="Px" color="black" port="com::/dev/ttyUSB1"/>
<baratron name="Baratron" color="cyan" port="tcp::192.168.111.33:4004"/>
</numass-vac>

View File

@ -40,6 +40,9 @@ import org.apache.commons.cli.ParseException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static java.util.Locale.setDefault; import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
/** /**
* *

View File

@ -64,7 +64,7 @@ import hep.dataforge.points.PointAdapter;
public class NumassPlugin extends BasicPlugin { public class NumassPlugin extends BasicPlugin {
@Override @Override
public void apply(Context context) { public void attach(Context context) {
FitManager fm = context.provide("fitting", FitPlugin.class).getFitManager(); FitManager fm = context.provide("fitting", FitPlugin.class).getFitManager();
ModelManager mm = fm.getModelManager(); ModelManager mm = fm.getModelManager();
loadModels(mm); loadModels(mm);
@ -85,7 +85,7 @@ public class NumassPlugin extends BasicPlugin {
} }
@Override @Override
public void clean(Context context) { public void detach(Context context) {
} }

View File

@ -25,6 +25,12 @@ import java.io.FileNotFoundException;
import java.util.Locale; import java.util.Locale;
import static java.util.Locale.setDefault; import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault; import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
import static java.util.Locale.setDefault;
/** /**
* *

View File

@ -20,11 +20,11 @@ import hep.dataforge.io.MetaStreamWriter
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.storage.commons.JSONMetaWriter import hep.dataforge.storage.commons.JSONMetaWriter
import hep.dataforge.storage.commons.StoragePlugin import hep.dataforge.storage.commons.StorageManager
import inr.numass.client.NumassClient import inr.numass.client.NumassClient
new StoragePlugin().startGlobal(); new StorageManager().startGlobal();

View File

@ -12,7 +12,7 @@ import hep.dataforge.io.envelopes.Envelope
import hep.dataforge.io.envelopes.EnvelopeBuilder import hep.dataforge.io.envelopes.EnvelopeBuilder
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.storage.commons.JSONMetaWriter import hep.dataforge.storage.commons.JSONMetaWriter
import hep.dataforge.storage.commons.StoragePlugin import hep.dataforge.storage.commons.StorageManager
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.ByteBuffer import java.nio.ByteBuffer
import inr.numass.client.NumassClient import inr.numass.client.NumassClient
@ -20,7 +20,7 @@ import java.nio.MappedByteBuffer
import java.nio.channels.FileChannel import java.nio.channels.FileChannel
new StoragePlugin().startGlobal(); new StorageManager().startGlobal();
new NumassClient("127.0.0.1",8335).withCloseable{ new NumassClient("127.0.0.1",8335).withCloseable{

View File

@ -20,11 +20,11 @@ import hep.dataforge.io.MetaStreamWriter
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.storage.commons.JSONMetaWriter import hep.dataforge.storage.commons.JSONMetaWriter
import hep.dataforge.storage.commons.StoragePlugin import hep.dataforge.storage.commons.StorageManager
import inr.numass.client.NumassClient import inr.numass.client.NumassClient
new StoragePlugin().startGlobal(); new StorageManager().startGlobal();

View File

@ -13,20 +13,17 @@ import hep.dataforge.io.envelopes.EnvelopeBuilder
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaBuilder
import hep.dataforge.storage.commons.JSONMetaWriter import hep.dataforge.storage.commons.JSONMetaWriter
import hep.dataforge.storage.commons.StoragePlugin import hep.dataforge.storage.commons.StorageManager
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.ByteBuffer import java.nio.ByteBuffer
import inr.numass.client.NumassClient import inr.numass.client.NumassClient
import java.nio.MappedByteBuffer import java.nio.MappedByteBuffer
import java.nio.channels.FileChannel import java.nio.channels.FileChannel
import hep.dataforge.data.MapDataPoint
import hep.dataforge.storage.commons.LoaderFactory
import hep.dataforge.data.DataFormat
import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaBuilder
import hep.dataforge.data.DataPoint
new StoragePlugin().startGlobal();
new StorageManager().startGlobal();
new NumassClient("127.0.0.1",8335).withCloseable{ new NumassClient("127.0.0.1",8335).withCloseable{

View File

@ -13,20 +13,18 @@ import hep.dataforge.io.envelopes.EnvelopeBuilder
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaBuilder
import hep.dataforge.storage.commons.JSONMetaWriter import hep.dataforge.storage.commons.JSONMetaWriter
import hep.dataforge.storage.commons.StoragePlugin import hep.dataforge.storage.commons.StorageManager
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.ByteBuffer import java.nio.ByteBuffer
import inr.numass.client.NumassClient import inr.numass.client.NumassClient
import java.nio.MappedByteBuffer import java.nio.MappedByteBuffer
import java.nio.channels.FileChannel import java.nio.channels.FileChannel
import hep.dataforge.data.MapDataPoint
import hep.dataforge.storage.commons.LoaderFactory import hep.dataforge.storage.commons.LoaderFactory
import hep.dataforge.data.DataFormat
import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaBuilder
import hep.dataforge.data.DataPoint import hep.dataforge.points.MapPoint
new StoragePlugin().startGlobal(); new StorageManager().startGlobal();
new NumassClient("127.0.0.1",8335).withCloseable{ new NumassClient("127.0.0.1",8335).withCloseable{
@ -46,8 +44,9 @@ new NumassClient("127.0.0.1",8335).withCloseable{
String[] names = ["a","b","c"] String[] names = ["a","b","c"]
for(int i = 0; i<5; i++){ for(int i = 0; i<5; i++){
data.putNode(DataPoint.toMeta(new MapDataPoint(names,i, 2*i,3*i))); data.putNode(DataPoint.toMeta(new MapPoint(names,i, 2*i,3*i)));
} }

View File

@ -91,7 +91,6 @@ public class NumassClient extends MessageFactory implements Closeable {
} }
public Meta getCurrentRun() { public Meta getCurrentRun() {
return sendAndRecieve(requestActionBase("numass.run", "get").build()).meta(); return sendAndRecieve(requestActionBase("numass.run", "get").build()).meta();
} }
@ -194,12 +193,12 @@ public class NumassClient extends MessageFactory implements Closeable {
*/ */
public Meta setState(Map<String, Value> stateMap) { public Meta setState(Map<String, Value> stateMap) {
EnvelopeBuilder env = requestActionBase("numass.state", "set"); EnvelopeBuilder env = requestActionBase("numass.state", "set");
for (Map.Entry<String, Value> state : stateMap.entrySet()) { stateMap.entrySet().stream().forEach((state) -> {
env.putMetaNode(new MetaBuilder("state") env.putMetaNode(new MetaBuilder("state")
.setValue("name", state.getKey()) .setValue("name", state.getKey())
.setValue("value", state.getValue()) .setValue("value", state.getValue())
.build()); .build());
} });
return sendAndRecieve(env.build()).meta(); return sendAndRecieve(env.build()).meta();
} }