Fixed devices library and vacuum measurements

This commit is contained in:
Alexander Nozik 2016-02-14 22:05:13 +03:00
parent b74775efc4
commit c1ed9a9f37
5 changed files with 29 additions and 10 deletions

View File

@ -22,6 +22,7 @@ import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
/**
@ -34,10 +35,11 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
/**
* Sensors in reversed order
*
* @param name
* @param context
* @param meta
* @param sensors
* @param sensors
*/
public VacCollectorDevice(String name, Context context, Meta meta, Sensor... sensors) {
super(name, context, meta);
@ -64,19 +66,21 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
public String type() {
return "Numass vacuum";
}
public Collection<Sensor> getSensors(){
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 ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
private ScheduledExecutorService executor;
private ScheduledFuture<?> currentTask;
@Override
public void start() {
executor = Executors
.newSingleThreadScheduledExecutor((Runnable r) -> new Thread(r, "VacuumMeasurement thread"));
currentTask = executor.scheduleWithFixedDelay(() -> {
sensorMap.entrySet().stream().parallel().forEach((entry) -> {
try {
@ -98,12 +102,14 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
public boolean stop(boolean force) {
boolean isRunning = currentTask != null;
if (isRunning) {
getLogger().debug("Stoping vacuum collector measurement");
currentTask.cancel(force);
executor.shutdown();
currentTask = null;
onFinish();
}
return isRunning;
}
}
}

View File

@ -46,5 +46,5 @@ public class PoweredVacuumeterView extends VacuumeterView {
getDevice().setState("power", newValue);
});
}
}

View File

@ -10,6 +10,7 @@ import hep.dataforge.control.devices.Device;
import hep.dataforge.control.devices.DeviceListener;
import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.MeasurementListener;
import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.data.DataPoint;
import hep.dataforge.exceptions.ControlException;
import hep.dataforge.exceptions.MeasurementException;
@ -139,7 +140,10 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
public void stopMeasurement() {
try {
getDevice().stopMeasurement(true);
} catch (MeasurementException ex) {
for (Sensor sensor : getDevice().getSensors()) {
sensor.shutdown();
}
} catch (ControlException ex) {
throw new RuntimeException(ex);
}
}

View File

@ -24,6 +24,7 @@ import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import org.controlsfx.control.StatusBar;
/**
@ -52,6 +53,9 @@ public class VacuumeterView extends DeviceViewController implements MeasurementL
@SuppressWarnings("unchecked")
public void accept(Device device, String measurementName, Measurement measurement) {
measurement.addListener(this);
if (device.meta().hasValue("color")) {
valueLabel.setTextFill(Color.valueOf(device.meta().getString("color")));
}
}
@Override

View File

@ -9,6 +9,7 @@ import hep.dataforge.context.GlobalContext;
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;
import inr.numass.readvac.fx.VacCollectorController;
import java.time.Duration;
@ -37,10 +38,15 @@ public class TestVac extends Application {
} else {
return null;
}
}).addState("power").build();
})
.addState("power")
.setMeta(new MetaBuilder("device")
.setValue("color", "magenta")
.setValue("thickness", 3))
.build();
VacCollectorDevice collector = new VacCollectorDevice("collector",
GlobalContext.instance(), null, poweredSensor, sensor3, sensor2, sensor1);
GlobalContext.instance(), null, sensor1, sensor2, sensor3, poweredSensor);
collector.init();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VacCollector.fxml"));
@ -66,7 +72,6 @@ public class TestVac extends Application {
controller.getDevice().shutdown();
}
super.stop();
System.exit(0);
}
/**