[no commit message]
This commit is contained in:
parent
ee669b0968
commit
f9e63d9e2c
@ -46,7 +46,7 @@ public class Talk {
|
||||
portName = args[0];
|
||||
}
|
||||
PortHandler handler;
|
||||
handler = PortFactory.buildPort(portName);
|
||||
handler = PortFactory.getdPort(portName);
|
||||
handler.setPhraseCondition((String str) -> str.endsWith("\r"));
|
||||
|
||||
// MagnetController controller = new MagnetController(handler, 1);
|
||||
|
@ -33,21 +33,27 @@ public class VirtualLambdaPort extends VirtualPort {
|
||||
|
||||
private volatile int currentAddress = -1;
|
||||
private Map<Integer, VirtualMagnetStatus> magnets = new HashMap<>();
|
||||
private final String virtualPortName;
|
||||
|
||||
public VirtualLambdaPort(String portName, Map<Integer, Double> magnets) {
|
||||
super(portName);
|
||||
this.virtualPortName = portName;
|
||||
magnets.entrySet().stream().forEach((entry) -> {
|
||||
this.magnets.put(entry.getKey(), new VirtualMagnetStatus(entry.getValue()));
|
||||
});
|
||||
}
|
||||
|
||||
public VirtualLambdaPort(String portName, int... magnets) {
|
||||
super(portName);
|
||||
this.virtualPortName = portName;
|
||||
for (int magnet : magnets) {
|
||||
this.magnets.put(magnet, new VirtualMagnetStatus(0.01));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPortId() {
|
||||
return virtualPortName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void evaluateRequest(String request) {
|
||||
String comand;
|
||||
|
@ -71,7 +71,7 @@ public class MagnetControllerApp extends Application {
|
||||
if(portName.equals("virtual")){
|
||||
handler = new VirtualLambdaPort("COM12", 1, 2, 3, 4);
|
||||
} else {
|
||||
handler = PortFactory.buildPort(portName);
|
||||
handler = PortFactory.getdPort(portName);
|
||||
//TODO add meta reader here
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
apply plugin: 'application'
|
||||
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
|
||||
if (!hasProperty('mainClass')) {
|
||||
ext.mainClass = 'inr.numass.control.msp.fx.MspApp'
|
||||
|
@ -71,7 +71,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
|
||||
String ip = meta().getString("connection.ip", "127.0.0.1");
|
||||
int port = meta().getInt("connection.port", 10014);
|
||||
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.holdBy(this);
|
||||
setConnected(true);
|
||||
@ -125,22 +125,20 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyState(String stateName, Value stateValue) throws ControlException {
|
||||
switch (stateName) {
|
||||
case "connected":
|
||||
return setConnected(stateValue.booleanValue());
|
||||
case "filamentOn":
|
||||
return setFileamentOn(stateValue.booleanValue());
|
||||
public void command(String commandName, Value argument) throws ControlException {
|
||||
switch(commandName){
|
||||
case "connect":
|
||||
setConnected(argument.booleanValue());
|
||||
case "setFilamentOn":
|
||||
setFileamentOn(argument.booleanValue());
|
||||
default:
|
||||
return super.applyState(stateName, stateValue);
|
||||
super.command(commandName, argument);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Startup MSP: get available sensors, select sensor and control.
|
||||
*
|
||||
* @param measurement
|
||||
* @throws hep.dataforge.exceptions.PortException
|
||||
*/
|
||||
public boolean setConnected(boolean connected) throws ControlException {
|
||||
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
|
||||
* with command name)
|
||||
* Send specific command and wait for its results (the result must begin
|
||||
with command name)
|
||||
*
|
||||
* @param commandName
|
||||
* @param paremeters
|
||||
|
@ -1,6 +1,6 @@
|
||||
apply plugin: 'application'
|
||||
|
||||
version = "0.4.0-SNAPSHOT"
|
||||
version = "0.4.0"
|
||||
|
||||
if (!hasProperty('mainClass')) {
|
||||
ext.mainClass = 'inr.numass.readvac.Main'
|
||||
@ -9,10 +9,7 @@ mainClassName = mainClass
|
||||
|
||||
|
||||
dependencies {
|
||||
compile 'ch.qos.logback:logback-classic:1.1.0+'
|
||||
compile 'org.scream3r:jssc:2.8.0'
|
||||
compile 'commons-cli:commons-cli:1.3'
|
||||
compile project(':numass-storage:numass-client')
|
||||
compile project(':dataforge-plots')
|
||||
compile project(':dataforge-storage')
|
||||
compile project(':dataforge-control')
|
||||
}
|
@ -6,12 +6,15 @@
|
||||
package inr.numass.readvac.app;
|
||||
|
||||
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.MKSBaratronDevice;
|
||||
import inr.numass.readvac.devices.MKSVacDevice;
|
||||
import inr.numass.readvac.devices.VITVacDevice;
|
||||
import inr.numass.readvac.devices.VacCollectorDevice;
|
||||
import inr.numass.readvac.fx.VacCollectorController;
|
||||
import java.io.File;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
@ -27,21 +30,37 @@ public class ReadVac extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
Sensor<Double> p1 = new MKSVacDevice("com::/dev/ttyUSB0");
|
||||
p1.setName("P1");
|
||||
String configFileName = getParameters().getNamed().get("config");
|
||||
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);
|
||||
Sensor<Double> p2 = new CM32Device("tcp::192.168.111.32:4002");
|
||||
p2.setName("P2");
|
||||
Sensor<Double> p3 = new CM32Device("tcp::192.168.111.32:4003");
|
||||
p3.setName("P3");
|
||||
Sensor<Double> px = new VITVacDevice("com::/dev/ttyUSB1");
|
||||
px.setName("Px");
|
||||
Sensor<Double> baratron = new MKSBaratronDevice("tcp::192.168.111.33:4004");
|
||||
baratron.setName("Baratron");
|
||||
Sensor<Double> p2 = new CM32Device(config.getString("p2.port","tcp::192.168.111.32:4002"));
|
||||
p1.configure(config.getNode("p2",Meta.empty()));
|
||||
p2.setName(config.getString("p2.name","P2"));
|
||||
Sensor<Double> p3 = new CM32Device(config.getString("p3.port","tcp::192.168.111.32:4003"));
|
||||
p1.configure(config.getNode("p3",Meta.empty()));
|
||||
p3.setName(config.getString("p3.name","P3"));
|
||||
Sensor<Double> px = new VITVacDevice(config.getString("px.port","com::/dev/ttyUSB1"));
|
||||
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();
|
||||
collector.setSensors(p1, p2, p3, px, baratron);
|
||||
// collector.setSensors(baratron);
|
||||
collector.init();
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml"));
|
||||
|
@ -5,8 +5,8 @@
|
||||
*/
|
||||
package inr.numass.readvac.devices;
|
||||
|
||||
import hep.dataforge.control.devices.PortSensor;
|
||||
import hep.dataforge.control.measurements.Measurement;
|
||||
import hep.dataforge.control.measurements.Sensor;
|
||||
import hep.dataforge.control.measurements.SimpleMeasurement;
|
||||
import hep.dataforge.control.ports.ComPortHandler;
|
||||
import hep.dataforge.control.ports.PortHandler;
|
||||
@ -20,7 +20,7 @@ import hep.dataforge.exceptions.ControlException;
|
||||
@ValueDef(name = "port")
|
||||
@ValueDef(name = "delay")
|
||||
@ValueDef(name = "timeout")
|
||||
public class CM32Device extends NumassVacDevice {
|
||||
public class CM32Device extends PortSensor<Double> {
|
||||
|
||||
public CM32Device(String portName) {
|
||||
super(portName);
|
||||
@ -75,19 +75,19 @@ public class CM32Device extends NumassVacDevice {
|
||||
|
||||
if (answer.isEmpty()) {
|
||||
this.onProgressUpdate("No signal");
|
||||
updateState("connection", false);
|
||||
updateState(CONNECTION_STATE, false);
|
||||
return null;
|
||||
} else if (answer.indexOf("PM1:mbar") < -1) {
|
||||
this.onProgressUpdate("Wrong answer: " + answer);
|
||||
updateState("connection", false);
|
||||
updateState(CONNECTION_STATE, false);
|
||||
return null;
|
||||
} else if (answer.substring(14, 17).equals("OFF")) {
|
||||
this.onProgressUpdate("Off");
|
||||
updateState("connection", true);
|
||||
updateState(CONNECTION_STATE, true);
|
||||
return null;
|
||||
} else {
|
||||
this.onProgressUpdate("OK");
|
||||
updateState("connection", true);
|
||||
updateState(CONNECTION_STATE, true);
|
||||
return Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23));
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package inr.numass.readvac.devices;
|
||||
|
||||
import hep.dataforge.control.devices.PortSensor;
|
||||
import hep.dataforge.control.measurements.Measurement;
|
||||
import hep.dataforge.control.measurements.Sensor;
|
||||
import hep.dataforge.control.measurements.SimpleMeasurement;
|
||||
@ -19,12 +20,8 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
@ValueDef(name = "address")
|
||||
@ValueDef(name = "channel")
|
||||
@ValueDef(name = "port")
|
||||
@ValueDef(name = "delay")
|
||||
@ValueDef(name = "timeout")
|
||||
public class MKSBaratronDevice extends NumassVacDevice {
|
||||
public class MKSBaratronDevice extends PortSensor<Double> {
|
||||
|
||||
public MKSBaratronDevice(String portName) {
|
||||
super(portName);
|
||||
|
@ -5,9 +5,9 @@
|
||||
*/
|
||||
package inr.numass.readvac.devices;
|
||||
|
||||
import hep.dataforge.control.devices.PortSensor;
|
||||
import hep.dataforge.control.measurements.Measurement;
|
||||
import hep.dataforge.control.measurements.SimpleMeasurement;
|
||||
import hep.dataforge.control.ports.ComPortHandler;
|
||||
import hep.dataforge.control.ports.PortHandler;
|
||||
import hep.dataforge.description.ValueDef;
|
||||
import hep.dataforge.exceptions.ControlException;
|
||||
@ -21,12 +21,9 @@ import javafx.beans.property.adapter.JavaBeanBooleanPropertyBuilder;
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
@ValueDef(name = "address")
|
||||
@ValueDef(name = "channel")
|
||||
@ValueDef(name = "port")
|
||||
@ValueDef(name = "delay")
|
||||
@ValueDef(name = "timeout")
|
||||
public class MKSVacDevice extends NumassVacDevice {
|
||||
@ValueDef(name = "address", def = "253")
|
||||
@ValueDef(name = "channel", def = "5")
|
||||
public class MKSVacDevice extends PortSensor<Double> {
|
||||
|
||||
public MKSVacDevice(String portName) {
|
||||
super(portName);
|
||||
@ -78,14 +75,12 @@ public class MKSVacDevice extends NumassVacDevice {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyState(String stateName, Value stateValue) throws ControlException {
|
||||
switch (stateName) {
|
||||
case "power":
|
||||
boolean powerOn = stateValue.booleanValue();
|
||||
public void command(String commandName, Value argument) throws ControlException {
|
||||
if (commandName.equals("setPower")) {
|
||||
boolean powerOn = argument.booleanValue();
|
||||
setPowerOn(powerOn);
|
||||
return powerOn == isPowerOn();
|
||||
default:
|
||||
return super.applyState(stateName, stateValue);
|
||||
} else {
|
||||
super.command(commandName, argument);
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,14 +97,14 @@ public class MKSVacDevice extends NumassVacDevice {
|
||||
// }
|
||||
String ans = talk("FP!ON");
|
||||
if (ans.equals("ON")) {
|
||||
setState("power", true);
|
||||
updateState("power", true);
|
||||
} else {
|
||||
this.notifyError("Failed to set power state", null);
|
||||
}
|
||||
} else {
|
||||
String ans = talk("FP!OFF");
|
||||
if (ans.equals("OFF")) {
|
||||
setState("power", false);
|
||||
updateState("power", false);
|
||||
} else {
|
||||
this.notifyError("Failed to set power state", null);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -5,12 +5,10 @@
|
||||
*/
|
||||
package inr.numass.readvac.devices;
|
||||
|
||||
import hep.dataforge.control.devices.PortSensor;
|
||||
import hep.dataforge.control.measurements.Measurement;
|
||||
import hep.dataforge.control.measurements.Sensor;
|
||||
import hep.dataforge.control.measurements.SimpleMeasurement;
|
||||
import hep.dataforge.control.ports.ComPortHandler;
|
||||
import hep.dataforge.control.ports.PortHandler;
|
||||
import hep.dataforge.description.ValueDef;
|
||||
import hep.dataforge.exceptions.ControlException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@ -21,10 +19,7 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
@ValueDef(name = "port")
|
||||
@ValueDef(name = "delay")
|
||||
@ValueDef(name = "timeout")
|
||||
public class VITVacDevice extends NumassVacDevice {
|
||||
public class VITVacDevice extends PortSensor<Double> {
|
||||
|
||||
public VITVacDevice(String portName) {
|
||||
super(portName);
|
||||
|
@ -7,13 +7,17 @@ package inr.numass.readvac.devices;
|
||||
|
||||
import hep.dataforge.control.collectors.PointCollector;
|
||||
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.Measurement;
|
||||
import hep.dataforge.control.measurements.Sensor;
|
||||
import hep.dataforge.points.DataPoint;
|
||||
import hep.dataforge.exceptions.ControlException;
|
||||
import hep.dataforge.exceptions.MeasurementException;
|
||||
import hep.dataforge.points.PointListener;
|
||||
import hep.dataforge.values.Value;
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -27,6 +31,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*
|
||||
* @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> {
|
||||
|
||||
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
|
||||
protected Object calculateState(String stateName) throws ControlException {
|
||||
//TODO add dot path notation for states
|
||||
@ -71,15 +83,13 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Collection<Sensor> getSensors() {
|
||||
return sensorMap.values();
|
||||
}
|
||||
|
||||
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 ScheduledFuture<?> currentTask;
|
||||
|
||||
@ -100,6 +110,14 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
|
||||
}, 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
|
||||
public boolean stop(boolean force) {
|
||||
boolean isRunning = currentTask != null;
|
||||
|
@ -5,9 +5,13 @@
|
||||
*/
|
||||
package inr.numass.readvac.fx;
|
||||
|
||||
import hep.dataforge.exceptions.ControlException;
|
||||
import hep.dataforge.values.Value;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
@ -43,7 +47,11 @@ public class PoweredVacuumeterView extends VacuumeterView {
|
||||
unitLabel.setText(getDevice().meta().getString("units", "mbar"));
|
||||
deviceNameLabel.setText(getDevice().getName());
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package inr.numass.readvac.fx;
|
||||
|
||||
import hep.dataforge.control.connections.Connection;
|
||||
import hep.dataforge.control.connections.Roles;
|
||||
import hep.dataforge.control.devices.Device;
|
||||
import hep.dataforge.control.devices.DeviceListener;
|
||||
@ -14,6 +15,7 @@ import hep.dataforge.control.measurements.Sensor;
|
||||
import hep.dataforge.points.DataPoint;
|
||||
import hep.dataforge.exceptions.ControlException;
|
||||
import hep.dataforge.exceptions.MeasurementException;
|
||||
import hep.dataforge.exceptions.StorageException;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.meta.MetaBuilder;
|
||||
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.fx.PlotContainer;
|
||||
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.ValueType;
|
||||
import inr.numass.readvac.devices.VacCollectorDevice;
|
||||
import java.net.URL;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.stream.Collectors;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
@ -41,6 +54,7 @@ import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.util.Duration;
|
||||
import org.controlsfx.control.Notifications;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
@ -50,9 +64,15 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
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 int[] intervals = {1000, 5000, 10000, 30000, 60000};
|
||||
|
||||
private LoaderConnection storageConnection;
|
||||
|
||||
private VacCollectorDevice device;
|
||||
private final List<VacuumeterView> views = new ArrayList<>();
|
||||
private PlotContainer plotContainer;
|
||||
@ -68,6 +88,10 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
|
||||
private ChoiceBox<String> intervalSelector;
|
||||
@FXML
|
||||
private ToggleButton startStopButton;
|
||||
@FXML
|
||||
private ToggleButton storeButton;
|
||||
@FXML
|
||||
private ToggleButton logButton;
|
||||
|
||||
/**
|
||||
* Initializes the controller class.
|
||||
@ -112,7 +136,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
|
||||
if (plottables != null) {
|
||||
plottables.put(result);
|
||||
}
|
||||
Platform.runLater(() -> timeLabel.setText(time.toString()));
|
||||
Platform.runLater(() -> timeLabel.setText(TIME_FORMAT.format(LocalDateTime.ofInstant(time, ZoneId.systemDefault()))));
|
||||
}
|
||||
|
||||
private void setupView() {
|
||||
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
@ -33,6 +36,7 @@ import javafx.scene.paint.Color;
|
||||
public class VacuumeterView extends DeviceViewController implements MeasurementListener<Double>, Initializable, Named, Annotated {
|
||||
|
||||
private static final DecimalFormat FORMAT = new DecimalFormat("0.##E0");
|
||||
private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ISO_LOCAL_TIME;
|
||||
|
||||
protected Node node;
|
||||
|
||||
@ -115,7 +119,7 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
|
||||
String resString = FORMAT.format(result);
|
||||
Platform.runLater(() -> {
|
||||
valueLabel.setText(resString);
|
||||
setStatus("OK: " + time.toString());
|
||||
setStatus("OK: " + TIME_FORMAT.format(LocalDateTime.ofInstant(time, ZoneId.systemDefault())));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
package inr.numass.readvac.test;
|
||||
|
||||
import hep.dataforge.control.measurements.Sensor;
|
||||
import hep.dataforge.control.virtual.SensorFactory;
|
||||
import hep.dataforge.control.virtual.Virtual;
|
||||
import hep.dataforge.meta.MetaBuilder;
|
||||
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> 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> 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();
|
||||
collector.setSensors(sensor1, sensor2, sensor3, poweredSensor);
|
||||
collector.setSensors(sensor1, sensor2, sensor3);
|
||||
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"));
|
||||
loader.load();
|
||||
controller = loader.getController();
|
||||
@ -64,7 +68,6 @@ public class TestVac extends Application {
|
||||
primaryStage.setTitle("Vacuum measurement test");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
controller.startMeasurement();
|
||||
} catch (Exception ex) {
|
||||
throw new Error(ex);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
<?import javafx.scene.control.ToolBar?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
@ -29,16 +30,20 @@
|
||||
<ToolBar>
|
||||
<items>
|
||||
<ToggleButton fx:id="startStopButton" mnemonicParsing="false" onAction="#onStartStopToggle" text="Measure" />
|
||||
<ToggleButton fx:id="storeButton" mnemonicParsing="false" onAction="#onStoreToggle" text="Store" />
|
||||
<Separator orientation="VERTICAL" />
|
||||
<Label text="Interval: " />
|
||||
<ChoiceBox fx:id="intervalSelector" prefWidth="150.0" />
|
||||
<Separator orientation="VERTICAL" />
|
||||
<Pane maxWidth="1.7976931348623157E308" />
|
||||
<Separator orientation="VERTICAL" />
|
||||
<ToggleButton fx:id="logButton" mnemonicParsing="false" onAction="#onLogToggle" text="Log" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
<AnchorPane fx:id="plotHolder" VBox.vgrow="ALWAYS" />
|
||||
<HBox styleClass="beveled">
|
||||
<children>
|
||||
<Label alignment="CENTER_RIGHT" text="Time: ">
|
||||
<Label alignment="CENTER_RIGHT" text="Last update: ">
|
||||
<font>
|
||||
<Font size="24.0" />
|
||||
</font>
|
||||
|
@ -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>
|
@ -40,6 +40,9 @@ import org.apache.commons.cli.ParseException;
|
||||
import org.slf4j.Logger;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -64,7 +64,7 @@ import hep.dataforge.points.PointAdapter;
|
||||
public class NumassPlugin extends BasicPlugin {
|
||||
|
||||
@Override
|
||||
public void apply(Context context) {
|
||||
public void attach(Context context) {
|
||||
FitManager fm = context.provide("fitting", FitPlugin.class).getFitManager();
|
||||
ModelManager mm = fm.getModelManager();
|
||||
loadModels(mm);
|
||||
@ -85,7 +85,7 @@ public class NumassPlugin extends BasicPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clean(Context context) {
|
||||
public void detach(Context context) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,12 @@ import java.io.FileNotFoundException;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -20,11 +20,11 @@ import hep.dataforge.io.MetaStreamWriter
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.storage.commons.JSONMetaWriter
|
||||
|
||||
import hep.dataforge.storage.commons.StoragePlugin
|
||||
import hep.dataforge.storage.commons.StorageManager
|
||||
import inr.numass.client.NumassClient
|
||||
|
||||
|
||||
new StoragePlugin().startGlobal();
|
||||
new StorageManager().startGlobal();
|
||||
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@ import hep.dataforge.io.envelopes.Envelope
|
||||
import hep.dataforge.io.envelopes.EnvelopeBuilder
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.storage.commons.JSONMetaWriter
|
||||
import hep.dataforge.storage.commons.StoragePlugin
|
||||
import hep.dataforge.storage.commons.StorageManager
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer
|
||||
import inr.numass.client.NumassClient
|
||||
@ -20,7 +20,7 @@ import java.nio.MappedByteBuffer
|
||||
import java.nio.channels.FileChannel
|
||||
|
||||
|
||||
new StoragePlugin().startGlobal();
|
||||
new StorageManager().startGlobal();
|
||||
|
||||
new NumassClient("127.0.0.1",8335).withCloseable{
|
||||
|
||||
|
@ -20,11 +20,11 @@ import hep.dataforge.io.MetaStreamWriter
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.storage.commons.JSONMetaWriter
|
||||
|
||||
import hep.dataforge.storage.commons.StoragePlugin
|
||||
import hep.dataforge.storage.commons.StorageManager
|
||||
import inr.numass.client.NumassClient
|
||||
|
||||
|
||||
new StoragePlugin().startGlobal();
|
||||
new StorageManager().startGlobal();
|
||||
|
||||
|
||||
|
||||
|
@ -13,20 +13,17 @@ import hep.dataforge.io.envelopes.EnvelopeBuilder
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.MetaBuilder
|
||||
import hep.dataforge.storage.commons.JSONMetaWriter
|
||||
import hep.dataforge.storage.commons.StoragePlugin
|
||||
import hep.dataforge.storage.commons.StorageManager
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer
|
||||
import inr.numass.client.NumassClient
|
||||
import java.nio.MappedByteBuffer
|
||||
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.data.DataPoint
|
||||
|
||||
|
||||
new StoragePlugin().startGlobal();
|
||||
|
||||
new StorageManager().startGlobal();
|
||||
|
||||
new NumassClient("127.0.0.1",8335).withCloseable{
|
||||
|
||||
|
@ -13,20 +13,18 @@ import hep.dataforge.io.envelopes.EnvelopeBuilder
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.MetaBuilder
|
||||
import hep.dataforge.storage.commons.JSONMetaWriter
|
||||
import hep.dataforge.storage.commons.StoragePlugin
|
||||
import hep.dataforge.storage.commons.StorageManager
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer
|
||||
import inr.numass.client.NumassClient
|
||||
import java.nio.MappedByteBuffer
|
||||
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.data.DataPoint
|
||||
import hep.dataforge.points.MapPoint
|
||||
|
||||
|
||||
new StoragePlugin().startGlobal();
|
||||
new StorageManager().startGlobal();
|
||||
|
||||
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"]
|
||||
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,7 +91,6 @@ public class NumassClient extends MessageFactory implements Closeable {
|
||||
}
|
||||
|
||||
public Meta getCurrentRun() {
|
||||
|
||||
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) {
|
||||
EnvelopeBuilder env = requestActionBase("numass.state", "set");
|
||||
for (Map.Entry<String, Value> state : stateMap.entrySet()) {
|
||||
stateMap.entrySet().stream().forEach((state) -> {
|
||||
env.putMetaNode(new MetaBuilder("state")
|
||||
.setValue("name", state.getKey())
|
||||
.setValue("value", state.getValue())
|
||||
.build());
|
||||
}
|
||||
});
|
||||
return sendAndRecieve(env.build()).meta();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user