[no commit message]
This commit is contained in:
parent
af7cda92bd
commit
ac7577a430
@ -6,16 +6,14 @@
|
||||
package inr.numass.readvac.devices;
|
||||
|
||||
import hep.dataforge.context.Context;
|
||||
import hep.dataforge.control.measurements.RegularMeasurement;
|
||||
import hep.dataforge.control.measurements.SingleMeasurementDevice;
|
||||
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 hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.values.Value;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -24,7 +22,7 @@ import java.time.temporal.ChronoUnit;
|
||||
@ValueDef(name = "port")
|
||||
@ValueDef(name = "delay")
|
||||
@ValueDef(name = "timeout")
|
||||
public class CM32Device extends SingleMeasurementDevice<RegularMeasurement<Double>> {
|
||||
public class CM32Device extends Sensor<Double> {
|
||||
|
||||
private PortHandler handler;
|
||||
|
||||
@ -47,7 +45,7 @@ public class CM32Device extends SingleMeasurementDevice<RegularMeasurement<Doubl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RegularMeasurement<Double> createMeasurement() {
|
||||
protected Measurement<Double> createMeasurement() {
|
||||
return new CMVacMeasurement();
|
||||
}
|
||||
|
||||
@ -83,7 +81,7 @@ public class CM32Device extends SingleMeasurementDevice<RegularMeasurement<Doubl
|
||||
return meta().getInt("timeout", 400);
|
||||
}
|
||||
|
||||
private class CMVacMeasurement extends RegularMeasurement<Double> {
|
||||
private class CMVacMeasurement extends SimpleMeasurement<Double> {
|
||||
|
||||
private static final String CM32_QUERY = "MES R PM 1\r\n";
|
||||
|
||||
@ -110,12 +108,6 @@ public class CM32Device extends SingleMeasurementDevice<RegularMeasurement<Doubl
|
||||
return Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Duration getDelay() {
|
||||
return Duration.of(meta().getInt("delay", 5000), ChronoUnit.MILLIS);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,16 +6,15 @@
|
||||
package inr.numass.readvac.devices;
|
||||
|
||||
import hep.dataforge.context.Context;
|
||||
import hep.dataforge.control.measurements.RegularMeasurement;
|
||||
import hep.dataforge.control.measurements.SingleMeasurementDevice;
|
||||
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 hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.values.Value;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
@ -30,7 +29,7 @@ import javafx.beans.property.adapter.JavaBeanBooleanPropertyBuilder;
|
||||
@ValueDef(name = "port")
|
||||
@ValueDef(name = "delay")
|
||||
@ValueDef(name = "timeout")
|
||||
public class MKSVacDevice extends SingleMeasurementDevice<RegularMeasurement<Double>> {
|
||||
public class MKSVacDevice extends Sensor<Double> {
|
||||
|
||||
// private static final String DELIMETER = ";FF";
|
||||
private PortHandler handler;
|
||||
@ -60,7 +59,7 @@ public class MKSVacDevice extends SingleMeasurementDevice<RegularMeasurement<Dou
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RegularMeasurement<Double> createMeasurement() {
|
||||
protected Measurement<Double> createMeasurement() {
|
||||
return new MKSVacMeasurement();
|
||||
}
|
||||
|
||||
@ -172,7 +171,7 @@ public class MKSVacDevice extends SingleMeasurementDevice<RegularMeasurement<Dou
|
||||
return handler;
|
||||
}
|
||||
|
||||
private class MKSVacMeasurement extends RegularMeasurement<Double> {
|
||||
private class MKSVacMeasurement extends SimpleMeasurement<Double> {
|
||||
|
||||
@Override
|
||||
protected Double doMeasurement() throws Exception {
|
||||
@ -196,16 +195,5 @@ public class MKSVacDevice extends SingleMeasurementDevice<RegularMeasurement<Dou
|
||||
private int getChannel() {
|
||||
return meta().getInt("channel", 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean stopOnError() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Duration getDelay() {
|
||||
return Duration.of(meta().getInt("delay", 5000), ChronoUnit.MILLIS);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.context.Context;
|
||||
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 hep.dataforge.meta.Meta;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
@ValueDef(name = "port")
|
||||
@ValueDef(name = "delay")
|
||||
@ValueDef(name = "timeout")
|
||||
public class VITVacDevice extends Sensor<Double> {
|
||||
|
||||
private PortHandler handler;
|
||||
|
||||
public VITVacDevice(String name, Context context, Meta meta) {
|
||||
super(name, context, meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the handler
|
||||
*/
|
||||
private PortHandler getHandler() throws ControlException {
|
||||
if (handler == null || !handler.isOpen()) {
|
||||
String port = meta().getString("port");
|
||||
getLogger().info("Connecting to port {}", port);
|
||||
handler = new ComPortHandler(port, 2400, 8, 1, 0);
|
||||
handler.setDelimeter("\r\n");
|
||||
handler.open();
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Measurement<Double> createMeasurement() {
|
||||
return new CMVacMeasurement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return meta().getString("type", "Vit vacuumeter");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object calculateState(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;
|
||||
// }
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return getState("connection").booleanValue();
|
||||
}
|
||||
|
||||
private int timeout() {
|
||||
return meta().getInt("timeout", 400);
|
||||
}
|
||||
|
||||
private class CMVacMeasurement extends SimpleMeasurement<Double> {
|
||||
|
||||
private static final String VIT_QUERY = ":010300000002FA\r\n";
|
||||
|
||||
@Override
|
||||
protected Double doMeasurement() throws Exception {
|
||||
|
||||
String answer = handler.sendAndWait(VIT_QUERY, timeout());
|
||||
|
||||
if (answer.isEmpty()) {
|
||||
this.progressUpdate("No signal");
|
||||
updateState("connection", false);
|
||||
return null;
|
||||
} else {
|
||||
Matcher match = Pattern.compile(":010304(\\w{4})(\\w{4})..\r\n").matcher(answer);
|
||||
|
||||
if (match.matches()) {
|
||||
double base = (double) (Integer.parseInt(match.group(1), 16)) / 10d;
|
||||
int exp = Integer.parseInt(match.group(2), 16);
|
||||
if (exp > 32766) {
|
||||
exp = exp - 65536;
|
||||
}
|
||||
BigDecimal res = BigDecimal.valueOf(base * Math.pow(10, exp));
|
||||
res = res.setScale(4, RoundingMode.CEILING);
|
||||
this.progressUpdate("OK");
|
||||
updateState("connection", true);
|
||||
return res.doubleValue();
|
||||
} else {
|
||||
this.progressUpdate("Wrong answer: " + answer);
|
||||
updateState("connection", false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.context.Context;
|
||||
import hep.dataforge.control.collectors.PointCollector;
|
||||
import hep.dataforge.control.collectors.ValueCollector;
|
||||
import hep.dataforge.control.measurements.AbstractMeasurement;
|
||||
import hep.dataforge.control.measurements.Measurement;
|
||||
import hep.dataforge.control.measurements.Sensor;
|
||||
import hep.dataforge.data.DataPoint;
|
||||
import hep.dataforge.exceptions.ControlException;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javafx.util.Pair;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik <altavir@gmail.com>
|
||||
*/
|
||||
public class VacCollectorDevice extends Sensor<DataPoint> {
|
||||
|
||||
private final Map<String, Sensor<Double>> sensorMap;
|
||||
|
||||
public VacCollectorDevice(String name, Context context, Meta meta, Sensor<Double>... sensors) {
|
||||
super(name, context, meta);
|
||||
sensorMap = new HashMap<>(sensors.length);
|
||||
for (Sensor<Double> sensor : sensors) {
|
||||
sensorMap.put(sensor.getName(), sensor);
|
||||
}
|
||||
//TODO add automatic construction from meta using deviceManager
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object calculateState(String stateName) throws ControlException {
|
||||
//TODO add dot path notation for states
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Measurement<DataPoint> createMeasurement() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return "Numass vacuum";
|
||||
}
|
||||
|
||||
private class VacuumMeasurement extends AbstractMeasurement<DataPoint> {
|
||||
|
||||
ValueCollector collector = new PointCollector(this::result, sensorMap.keySet());
|
||||
|
||||
@Override
|
||||
protected Pair<DataPoint, Instant> doGet() throws Exception {
|
||||
sensorMap.values().stream().parallel().forEach(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop(boolean force) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -16,24 +16,21 @@
|
||||
package hep.dataforge.plotfit;
|
||||
|
||||
import hep.dataforge.actions.OneToOneAction;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.context.Context;
|
||||
import hep.dataforge.data.DataPoint;
|
||||
import hep.dataforge.data.DataSet;
|
||||
import hep.dataforge.data.XYDataAdapter;
|
||||
import hep.dataforge.datafitter.FitState;
|
||||
import hep.dataforge.datafitter.models.XYModel;
|
||||
import hep.dataforge.description.NodeDef;
|
||||
import hep.dataforge.description.ValueDef;
|
||||
import hep.dataforge.description.TypedActionDef;
|
||||
import hep.dataforge.description.ValueDef;
|
||||
import hep.dataforge.exceptions.ContentException;
|
||||
import hep.dataforge.io.log.Logable;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.plots.PlotsPlugin;
|
||||
import hep.dataforge.plots.XYPlotFrame;
|
||||
import hep.dataforge.plots.data.PlottableData;
|
||||
import hep.dataforge.plots.data.PlottableFunction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
|
||||
/**
|
||||
@ -75,32 +72,32 @@ public class PlotFitResultAction extends OneToOneAction<FitState, FitState> {
|
||||
metaData.getNode("plot", null));
|
||||
//JFreeChartFrame.drawFrame(reader.getString("plotTitle", "Fit result plot for "+input.getName()), null);
|
||||
|
||||
double[] x = new double[data.size()];
|
||||
// double[] x = new double[data.size()];
|
||||
|
||||
// double[] y = new double[data.size()];
|
||||
double xMin = Double.POSITIVE_INFINITY;
|
||||
// double xMin = Double.POSITIVE_INFINITY;
|
||||
//
|
||||
// double xMax = Double.NEGATIVE_INFINITY;
|
||||
//
|
||||
// List<DataPoint> points = new ArrayList<>();
|
||||
//
|
||||
// for (int i = 0; i < data.size(); i++) {
|
||||
// x[i] = adapter.getX(data.get(i)).doubleValue();
|
||||
//// y[i] = adapter.getY(data.get(i));
|
||||
//
|
||||
// points.add(adapter.mapToDefault(data.get(i)));
|
||||
// if (x[i] < xMin) {
|
||||
// xMin = x[i];
|
||||
// }
|
||||
//
|
||||
// if (x[i] > xMax) {
|
||||
// xMax = x[i];
|
||||
// }
|
||||
// }
|
||||
|
||||
double xMax = Double.NEGATIVE_INFINITY;
|
||||
frame.add(new PlottableFunction("fit", null, function, data, adapter));//FIXME replace by helper
|
||||
|
||||
List<DataPoint> points = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
x[i] = adapter.getX(data.get(i)).doubleValue();
|
||||
// y[i] = adapter.getY(data.get(i));
|
||||
|
||||
points.add(adapter.mapToDefault(data.get(i)));
|
||||
if (x[i] < xMin) {
|
||||
xMin = x[i];
|
||||
}
|
||||
|
||||
if (x[i] > xMax) {
|
||||
xMax = x[i];
|
||||
}
|
||||
}
|
||||
|
||||
frame.add(new PlottableFunction("fit", null, function, points, "x"));
|
||||
|
||||
frame.add(PlottableData.plot("data", adapter, points));
|
||||
frame.add(PlottableData.plot("data", adapter, data));
|
||||
|
||||
return input;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user