Numass vacuum measurements in progress

This commit is contained in:
darksnake 2016-04-11 16:33:44 +03:00
parent f1eb4eba02
commit ee669b0968
7 changed files with 187 additions and 140 deletions

View File

@ -0,0 +1,76 @@
/*
* 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.app;
import hep.dataforge.control.measurements.Sensor;
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 javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
*
* @author Alexander Nozik
*/
public class ReadVac extends Application {
VacCollectorController controller;
@Override
public void start(Stage primaryStage) throws Exception {
Sensor<Double> p1 = new MKSVacDevice("com::/dev/ttyUSB0");
p1.setName("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");
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"));
loader.load();
controller = loader.getController();
controller.setDevice(collector);
Scene scene = new Scene(loader.getRoot(), 800, 600);
primaryStage.setTitle("Numass vacuum measurements");
primaryStage.setScene(scene);
primaryStage.show();
controller.startMeasurement();
}
@Override
public void stop() throws Exception {
if (controller != null) {
controller.stopMeasurement();
controller.getDevice().shutdown();
}
super.stop();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}

View File

@ -20,30 +20,18 @@ 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 Sensor<Double> { public class CM32Device extends NumassVacDevice {
private PortHandler handler; public CM32Device(String portName) {
super(portName);
// public CM32Device(String name, Context context, Meta meta) {
// super(name, context, meta);
// }
public void setHandler(PortHandler handler){
this.handler = handler;
} }
/** @Override
* @return the handler protected PortHandler buildHandler(String portName) throws ControlException {
*/ String port = meta().getString("port", portName);
private PortHandler getHandler() throws ControlException { PortHandler newHandler = new ComPortHandler(port, 2400, 8, 1, 0);
if (handler == null || !handler.isOpen()) { newHandler.setDelimeter("T--");
String port = meta().getString("port"); return newHandler;
getLogger().info("Connecting to port {}", port);
handler = new ComPortHandler(port, 2400, 8, 1, 0);
handler.setDelimeter("T--");
handler.open();
}
return handler;
} }
@Override @Override
@ -75,13 +63,6 @@ public class CM32Device extends Sensor<Double> {
// } // }
} }
public boolean isConnected() {
return getState("connection").booleanValue();
}
private int timeout() {
return meta().getInt("timeout", 400);
}
private class CMVacMeasurement extends SimpleMeasurement<Double> { private class CMVacMeasurement extends SimpleMeasurement<Double> {
@ -90,7 +71,7 @@ public class CM32Device extends Sensor<Double> {
@Override @Override
protected synchronized Double doMeasure() throws Exception { protected synchronized Double doMeasure() throws Exception {
String answer = handler.sendAndWait(CM32_QUERY, timeout()); String answer = getHandler().sendAndWait(CM32_QUERY, timeout());
if (answer.isEmpty()) { if (answer.isEmpty()) {
this.onProgressUpdate("No signal"); this.onProgressUpdate("No signal");

View File

@ -24,16 +24,14 @@ import java.util.regex.Pattern;
@ValueDef(name = "port") @ValueDef(name = "port")
@ValueDef(name = "delay") @ValueDef(name = "delay")
@ValueDef(name = "timeout") @ValueDef(name = "timeout")
public class MKSBaratronDevice extends Sensor<Double> { public class MKSBaratronDevice extends NumassVacDevice {
private PortHandler handler; public MKSBaratronDevice(String portName) {
super(portName);
public void setHandler(PortHandler handler) {
this.handler = handler;
} }
private String talk(String request) throws ControlException { private String talk(String request) throws ControlException {
String answer = getHandler().sendAndWait(String.format("@%s%s\r", getDeviceAddress(), request), timeout()); String answer = getHandler().sendAndWait(String.format("%s\r", request), timeout());
Matcher match = Pattern.compile("(.*)\r").matcher(answer); Matcher match = Pattern.compile("(.*)\r").matcher(answer);
if (match.matches()) { if (match.matches()) {
@ -43,42 +41,20 @@ public class MKSBaratronDevice extends Sensor<Double> {
} }
} }
private String getDeviceAddress() {
//PENDING cache this?
return meta().getString("address", "253");
}
private int timeout() {
return meta().getInt("timeout", 400);
}
@Override @Override
protected Measurement<Double> createMeasurement() { protected Measurement<Double> createMeasurement() {
return new BaratronMeasurement(); return new BaratronMeasurement();
} }
public boolean isConnected() {
return getState("connection").booleanValue();
}
@Override @Override
public String type() { public String type() {
return meta().getString("type", "MKS baratron"); return meta().getString("type", "MKS baratron");
} }
/** @Override
* @return the handler protected PortHandler buildHandler(String portName) throws ControlException {
*/ PortHandler handler = super.buildHandler(portName);
private PortHandler getHandler() throws ControlException {
if (handler == null || !handler.isOpen()) {
String port = meta().getString("port");
getLogger().info("Connecting to port {}", port);
// handler = PortFactory.buildPort(port);
handler = new ComPortHandler(port);
handler.setDelimeter("\r"); handler.setDelimeter("\r");
handler.open();
}
return handler; return handler;
} }

View File

@ -6,7 +6,6 @@
package inr.numass.readvac.devices; package inr.numass.readvac.devices;
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;
@ -27,12 +26,10 @@ import javafx.beans.property.adapter.JavaBeanBooleanPropertyBuilder;
@ValueDef(name = "port") @ValueDef(name = "port")
@ValueDef(name = "delay") @ValueDef(name = "delay")
@ValueDef(name = "timeout") @ValueDef(name = "timeout")
public class MKSVacDevice extends Sensor<Double> { public class MKSVacDevice extends NumassVacDevice {
private PortHandler handler; public MKSVacDevice(String portName) {
super(portName);
public void setHandler(PortHandler handler) {
this.handler = handler;
} }
private String talk(String requestContent) throws ControlException { private String talk(String requestContent) throws ControlException {
@ -46,15 +43,18 @@ public class MKSVacDevice extends Sensor<Double> {
} }
} }
@Override
protected PortHandler buildHandler(String portName) throws ControlException {
PortHandler handler = super.buildHandler(portName);
handler.setDelimeter(";FF");
return handler;
}
private String getDeviceAddress() { private String getDeviceAddress() {
//PENDING cache this? //PENDING cache this?
return meta().getString("address", "253"); return meta().getString("address", "253");
} }
private int timeout() {
return meta().getInt("timeout", 400);
}
@Override @Override
protected Measurement<Double> createMeasurement() { protected Measurement<Double> createMeasurement() {
return new MKSVacMeasurement(); return new MKSVacMeasurement();
@ -89,28 +89,6 @@ public class MKSVacDevice extends Sensor<Double> {
} }
} }
// private Double readPressure(int channel) {
// try {
// String answer = talk("PR" + channel + "?");
// if (answer == null || answer.isEmpty()) {
// invalidateState("connection");
// return null;
// }
// double res = Double.parseDouble(answer);
// if (res <= 0) {
// return null;
// } else {
// return res;
// }
// } catch (ControlException ex) {
// invalidateState("connection");
// return null;
// }
// }
public boolean isConnected() {
return getState("connection").booleanValue();
}
public boolean isPowerOn() { public boolean isPowerOn() {
return getState("power").booleanValue(); return getState("power").booleanValue();
} }
@ -153,21 +131,6 @@ public class MKSVacDevice extends Sensor<Double> {
return meta().getString("type", "MKS vacuumeter"); return meta().getString("type", "MKS vacuumeter");
} }
/**
* @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 = PortFactory.buildPort(port);
handler = new ComPortHandler(port);
handler.setDelimeter(";FF");
handler.open();
}
return handler;
}
private int getChannel() { private int getChannel() {
return meta().getInt("channel", 5); return meta().getInt("channel", 5);
} }

View File

@ -0,0 +1,71 @@
/*
* 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

@ -24,30 +24,17 @@ import java.util.regex.Pattern;
@ValueDef(name = "port") @ValueDef(name = "port")
@ValueDef(name = "delay") @ValueDef(name = "delay")
@ValueDef(name = "timeout") @ValueDef(name = "timeout")
public class VITVacDevice extends Sensor<Double> { public class VITVacDevice extends NumassVacDevice {
private PortHandler handler; public VITVacDevice(String portName) {
super(portName);
// public VITVacDevice(String name, Context context, Meta meta) {
// super(name, context, meta);
// }
public void setHandler(PortHandler handler) {
this.handler = handler;
} }
/** @Override
* @return the handler protected PortHandler buildHandler(String portName) throws ControlException {
*/ PortHandler newHandler = super.buildHandler(portName);
private PortHandler getHandler() throws ControlException { newHandler.setDelimeter("\r\n");
if (handler == null || !handler.isOpen()) { return newHandler;
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 @Override
@ -79,13 +66,6 @@ public class VITVacDevice extends Sensor<Double> {
// } // }
} }
public boolean isConnected() {
return getState("connection").booleanValue();
}
private int timeout() {
return meta().getInt("timeout", 400);
}
private class CMVacMeasurement extends SimpleMeasurement<Double> { private class CMVacMeasurement extends SimpleMeasurement<Double> {
@ -94,7 +74,7 @@ public class VITVacDevice extends Sensor<Double> {
@Override @Override
protected synchronized Double doMeasure() throws Exception { protected synchronized Double doMeasure() throws Exception {
String answer = handler.sendAndWait(VIT_QUERY, timeout()); String answer = getHandler().sendAndWait(VIT_QUERY, timeout());
if (answer.isEmpty()) { if (answer.isEmpty()) {
this.onProgressUpdate("No signal"); this.onProgressUpdate("No signal");

View File

@ -145,7 +145,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
this.device = device; this.device = device;
device.getSensors().stream().map((sensor) -> { device.getSensors().stream().map((sensor) -> {
VacuumeterView controller; VacuumeterView controller;
if (sensor.hasState("power")) { if (sensor.meta().getBoolean("powerButton", false)) {
controller = new PoweredVacuumeterView(); controller = new PoweredVacuumeterView();
} else { } else {
controller = new VacuumeterView(); controller = new VacuumeterView();