Updating magnet controls
This commit is contained in:
parent
b9a822ed14
commit
b070156c51
@ -14,7 +14,7 @@ allprojects{
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url "https://jitpack.io" }
|
||||
//maven { url "https://jitpack.io" }
|
||||
maven { url "http://dl.bintray.com/kotlin/ktor" }
|
||||
maven { url "https://dl.bintray.com/kotlin/kotlinx" }
|
||||
}
|
||||
|
@ -8,9 +8,7 @@ if (!hasProperty('mainClass')) {
|
||||
mainClassName = mainClass
|
||||
|
||||
dependencies {
|
||||
compile 'ch.qos.logback:logback-classic:1.1.0+'
|
||||
compile 'org.scream3r:jssc:2.8.0'
|
||||
compile "hep.dataforge:dataforge-control" //project(':dataforge-control')
|
||||
compile project(':numass-control')
|
||||
}
|
||||
|
||||
task talkToServer(type: JavaExec) {
|
||||
|
@ -15,28 +15,41 @@
|
||||
*/
|
||||
package inr.numass.control.magnet;
|
||||
|
||||
import hep.dataforge.context.Context;
|
||||
import hep.dataforge.control.devices.AbstractDevice;
|
||||
import hep.dataforge.control.devices.StateDef;
|
||||
import hep.dataforge.control.ports.GenericPortController;
|
||||
import hep.dataforge.control.ports.Port;
|
||||
import hep.dataforge.control.ports.PortFactory;
|
||||
import hep.dataforge.control.ports.PortTimeoutException;
|
||||
import hep.dataforge.description.ValueDef;
|
||||
import hep.dataforge.exceptions.ControlException;
|
||||
import hep.dataforge.exceptions.PortException;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.utils.DateTimeUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static hep.dataforge.values.ValueType.*;
|
||||
|
||||
/**
|
||||
* @author Polina
|
||||
*/
|
||||
public class MagnetController implements Port.PortController {
|
||||
@ValueDef(name = "timeout", type = {NUMBER}, def = "400", info = "A timeout for port response")
|
||||
@StateDef(value = @ValueDef(name = "output", type = BOOLEAN, info = "Weather output on or off"), writable = true)
|
||||
@StateDef(value = @ValueDef(name = "current", type = NUMBER, info = "Current current"))
|
||||
@StateDef(value = @ValueDef(name = "voltage", type = NUMBER, info = "Current voltage"))
|
||||
@StateDef(value = @ValueDef(name = "targetCurrent", type = NUMBER, info = "Target current"), writable = true)
|
||||
@StateDef(value = @ValueDef(name = "targetVoltage", type = NUMBER, info = "Target voltage"), writable = true)
|
||||
@StateDef(value = @ValueDef(name = "lastUpdate", type = TIME, info = "Time of the last update"), writable = true)
|
||||
public class LambdaMagnet extends AbstractDevice {
|
||||
|
||||
private static final DecimalFormat LAMBDAformat = new DecimalFormat("###.##");
|
||||
private static final DecimalFormat LAMBDA_FORMAT = new DecimalFormat("###.##");
|
||||
public static double CURRENT_PRECISION = 0.05;
|
||||
// public static double CURRENT_STEP = 0.05;
|
||||
public static int DEFAULT_DELAY = 1;
|
||||
@ -45,50 +58,101 @@ public class MagnetController implements Port.PortController {
|
||||
public static double MIN_UP_STEP_SIZE = 0.005;
|
||||
public static double MIN_DOWN_STEP_SIZE = 0.05;
|
||||
public static double MAX_SPEED = 5d; // 5 A per minute
|
||||
|
||||
private boolean closePortOnShutDown = false;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final Port port;
|
||||
private final GenericPortController controller = new GenericPortController(this);
|
||||
|
||||
private final int address;
|
||||
private final ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(1);
|
||||
|
||||
protected MagnetStateListener listener;
|
||||
private volatile double current = 0;
|
||||
private Duration timeout = Duration.ofMillis(200);
|
||||
private Future monitorTask;
|
||||
private Future updateTask;
|
||||
private Instant lastUpdate = null;
|
||||
// private volatile double current = 0;
|
||||
private final Duration timeout;
|
||||
// private Future monitorTask;
|
||||
// private Future updateTask;
|
||||
// private Instant lastUpdate = null;
|
||||
|
||||
private double speed = MAX_SPEED;
|
||||
|
||||
private final GenericPortController controller;
|
||||
|
||||
|
||||
/**
|
||||
* This method creates an element of class MegnetController with exact
|
||||
* parameters. If you have two parameters for your method - the next
|
||||
* constructor will be used.
|
||||
* A setup for single magnet controller
|
||||
*
|
||||
* @param name
|
||||
* @param port number of COM-port on your computer that you want to use
|
||||
* @param address number of TDK - Lambda
|
||||
* @param timeout waiting time for response
|
||||
* @param context
|
||||
* @param meta
|
||||
* @throws ControlException
|
||||
*/
|
||||
public MagnetController(String name, Port port, int address, int timeout) {
|
||||
this.name = name;
|
||||
this.port = port;
|
||||
this.port.setDelimiter("\r");//PENDING меняем состояние внешнего объекта?
|
||||
this.address = address;
|
||||
this.timeout = Duration.ofMillis(timeout);
|
||||
public LambdaMagnet(Context context, Meta meta) throws ControlException {
|
||||
this(context, meta, new GenericPortController(context, PortFactory.getPort(meta.getString("port"))));
|
||||
closePortOnShutDown = true;
|
||||
}
|
||||
|
||||
public MagnetController(Port port, int address, int timeout) {
|
||||
this(null, port, address, timeout);
|
||||
|
||||
/**
|
||||
* Initialize magnet device with given port controller
|
||||
*
|
||||
* @param context
|
||||
* @param meta
|
||||
* @param controller
|
||||
*/
|
||||
public LambdaMagnet(Context context, Meta meta, GenericPortController controller) {
|
||||
super(context, meta);
|
||||
this.controller = controller;
|
||||
name = meta.getString("name", "LAMBDA");
|
||||
address = meta.getInt("address", 1);
|
||||
timeout = meta.optString("timeout").map(Duration::parse).orElse(Duration.ofMillis(200));
|
||||
}
|
||||
|
||||
public MagnetController(Port port, int address) {
|
||||
this(null, port, address);
|
||||
// /**
|
||||
// * This method creates an element of class MegnetController with exact
|
||||
// * parameters. If you have two parameters for your method - the next
|
||||
// * constructor will be used.
|
||||
// *
|
||||
// * @param name
|
||||
// * @param port number of COM-port on your computer that you want to use
|
||||
// * @param address number of TDK - Lambda
|
||||
// * @param timeout waiting time for response
|
||||
// */
|
||||
// public LambdaMagnet(String name, Port port, int address, int timeout) {
|
||||
// this.name = name;
|
||||
// this.port = port;
|
||||
// this.port.setDelimiter("\r");//PENDING меняем состояние внешнего объекта?
|
||||
// this.address = address;
|
||||
// this.timeout = Duration.ofMillis(timeout);
|
||||
// }
|
||||
//
|
||||
// public LambdaMagnet(Port port, int address, int timeout) {
|
||||
// this(null, port, address, timeout);
|
||||
// }
|
||||
//
|
||||
// public LambdaMagnet(Port port, int address) {
|
||||
// this(null, port, address);
|
||||
// }
|
||||
//
|
||||
// public LambdaMagnet(String name, Port port, int address) {
|
||||
// this(name, port, address, 300);
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public void init() throws ControlException {
|
||||
super.init();
|
||||
controller.open();
|
||||
}
|
||||
|
||||
public MagnetController(String name, Port port, int address) {
|
||||
this(name, port, address, 300);
|
||||
@Override
|
||||
public void shutdown() throws ControlException {
|
||||
super.shutdown();
|
||||
try {
|
||||
controller.close();
|
||||
if (closePortOnShutDown) {
|
||||
controller.getPort().close();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new ControlException("Failed to close the port", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,24 +162,32 @@ public class MagnetController implements Port.PortController {
|
||||
* @return string
|
||||
*/
|
||||
private static String d2s(double d) {
|
||||
return LAMBDAformat.format(d);
|
||||
return LAMBDA_FORMAT.format(d);
|
||||
}
|
||||
|
||||
public void setListener(MagnetStateListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public double getMeasuredI() {
|
||||
return current;
|
||||
}
|
||||
// public double getMeasuredI() {
|
||||
// return current;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void acceptPhrase(String message) {
|
||||
// @Override
|
||||
// public void acceptPhrase(String message) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void reportError(String errorMessage, Throwable error) {
|
||||
// if (this.listener != null) {
|
||||
// listener.error(getName(), errorMessage, error);
|
||||
// } else {
|
||||
// LoggerFactory.getLogger(getClass()).error(errorMessage, error);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void portError(String errorMessage, Throwable error) {
|
||||
private void reportError(String errorMessage, Throwable error) {
|
||||
if (this.listener != null) {
|
||||
listener.error(getName(), errorMessage, error);
|
||||
} else {
|
||||
@ -125,32 +197,32 @@ public class MagnetController implements Port.PortController {
|
||||
|
||||
private String talk(String request) throws PortException {
|
||||
try {
|
||||
port.send(controller,request + "\r");
|
||||
controller.send(request + "\r");
|
||||
return controller.waitFor(timeout).trim();
|
||||
} catch (PortTimeoutException tex) {
|
||||
//Single retry on timeout
|
||||
LoggerFactory.getLogger(getClass()).warn("A timeout exception for request '" + request + "'. Making another atempt.");
|
||||
port.send(controller,request + "\r");
|
||||
controller.send(request + "\r");
|
||||
return controller.waitFor(timeout).trim();
|
||||
}
|
||||
}
|
||||
|
||||
private String getState(String name) throws PortException {
|
||||
private String getParameter(String name) throws PortException {
|
||||
String res = talk(name + "?");
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean setState(String name, String state) throws PortException {
|
||||
private boolean setParameter(String name, String state) throws PortException {
|
||||
String res = talk(name + " " + state);
|
||||
return "OK".equals(res);
|
||||
}
|
||||
|
||||
private boolean setState(String name, int state) throws PortException {
|
||||
private boolean setParameter(String name, int state) throws PortException {
|
||||
String res = talk(name + " " + state);
|
||||
return "OK".equals(res);
|
||||
}
|
||||
|
||||
private boolean setState(String name, double state) throws PortException {
|
||||
private boolean setParameter(String name, double state) throws PortException {
|
||||
String res = talk(name + " " + d2s(state));
|
||||
return "OK".equals(res);
|
||||
}
|
||||
@ -172,19 +244,19 @@ public class MagnetController implements Port.PortController {
|
||||
}
|
||||
throw new PortException("Can't set address");
|
||||
}
|
||||
return s2d(getState("MC"));
|
||||
return s2d(getParameter("MC"));
|
||||
}
|
||||
|
||||
protected void setCurrent(double current) throws PortException {
|
||||
if (!setState("PC", current)) {
|
||||
portError("Can't set the current", null);
|
||||
if (!setParameter("PC", current)) {
|
||||
reportError("Can't set the current", null);
|
||||
} else {
|
||||
lastUpdate = DateTimeUtils.now();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setADR() throws PortException {
|
||||
if (setState("ADR", getAddress())) {
|
||||
if (setParameter("ADR", getAddress())) {
|
||||
if (listener != null) {
|
||||
listener.addressChanged(getName(), address);
|
||||
}
|
||||
@ -200,32 +272,26 @@ public class MagnetController implements Port.PortController {
|
||||
* @return status of magnet
|
||||
*/
|
||||
private MagnetStatus getStatus() throws PortException {
|
||||
try {
|
||||
port.holdBy(controller);
|
||||
|
||||
if (!setADR()) {
|
||||
return MagnetStatus.off();
|
||||
}
|
||||
|
||||
boolean out;
|
||||
|
||||
out = "ON".equals(talk("OUT?"));
|
||||
|
||||
double measuredCurrent = s2d(getState("MC"));
|
||||
this.current = measuredCurrent;
|
||||
double setCurrent = s2d(getState("PC"));
|
||||
double measuredVoltage = s2d(getState("MV"));
|
||||
double setVoltage = s2d(getState("PV"));
|
||||
|
||||
MagnetStatus monitor = new MagnetStatus(out, measuredCurrent, setCurrent, measuredVoltage, setVoltage);
|
||||
|
||||
if (listener != null) {
|
||||
listener.acceptStatus(getName(), monitor);
|
||||
}
|
||||
return monitor;
|
||||
} finally {
|
||||
port.releaseBy(controller);
|
||||
if (!setADR()) {
|
||||
return MagnetStatus.off();
|
||||
}
|
||||
|
||||
boolean out;
|
||||
|
||||
out = "ON".equals(talk("OUT?"));
|
||||
|
||||
double measuredCurrent = s2d(getParameter("MC"));
|
||||
this.current = measuredCurrent;
|
||||
double setCurrent = s2d(getParameter("PC"));
|
||||
double measuredVoltage = s2d(getParameter("MV"));
|
||||
double setVoltage = s2d(getParameter("PV"));
|
||||
|
||||
MagnetStatus monitor = new MagnetStatus(out, measuredCurrent, setCurrent, measuredVoltage, setVoltage);
|
||||
|
||||
if (listener != null) {
|
||||
listener.acceptStatus(getName(), monitor);
|
||||
}
|
||||
return monitor;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -257,7 +323,6 @@ public class MagnetController implements Port.PortController {
|
||||
stopUpdateTask();
|
||||
Runnable call = () -> {
|
||||
try {
|
||||
port.holdBy(controller);
|
||||
double measuredI = getCurrent();
|
||||
this.current = measuredI;
|
||||
|
||||
@ -278,10 +343,8 @@ public class MagnetController implements Port.PortController {
|
||||
}
|
||||
|
||||
} catch (PortException ex) {
|
||||
portError("Error in update task", ex);
|
||||
reportError("Error in update task", ex);
|
||||
stopUpdateTask();
|
||||
} finally {
|
||||
port.releaseBy(controller);
|
||||
}
|
||||
};
|
||||
|
||||
@ -292,26 +355,21 @@ public class MagnetController implements Port.PortController {
|
||||
}
|
||||
|
||||
public void setOutputMode(boolean out) throws PortException {
|
||||
try {
|
||||
port.holdBy(controller);
|
||||
if (!setADR()) {
|
||||
throw new RuntimeException();
|
||||
if (!setADR()) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
int outState;
|
||||
if (out) {
|
||||
outState = 1;
|
||||
} else {
|
||||
outState = 0;
|
||||
}
|
||||
if (!setParameter("OUT", outState)) {
|
||||
if (listener != null) {
|
||||
listener.error(getName(), "Can't set output mode", null);
|
||||
}
|
||||
int outState;
|
||||
if (out) {
|
||||
outState = 1;
|
||||
} else {
|
||||
outState = 0;
|
||||
}
|
||||
if (!setState("OUT", outState)) {
|
||||
if (listener != null) {
|
||||
listener.error(getName(), "Can't set output mode", null);
|
||||
}
|
||||
} else if (listener != null) {
|
||||
listener.outputModeChanged(getName(), out);
|
||||
}
|
||||
} finally {
|
||||
port.releaseBy(controller);
|
||||
} else if (listener != null) {
|
||||
listener.outputModeChanged(getName(), out);
|
||||
}
|
||||
}
|
||||
|
||||
@ -385,7 +443,7 @@ public class MagnetController implements Port.PortController {
|
||||
try {
|
||||
getStatus();
|
||||
} catch (PortException ex) {
|
||||
portError("Port connection exception during status measurement", ex);
|
||||
reportError("Port connection exception during status measurement", ex);
|
||||
stopMonitorTask();
|
||||
}
|
||||
};
|
||||
@ -400,17 +458,12 @@ public class MagnetController implements Port.PortController {
|
||||
|
||||
public String request(String message) {
|
||||
try {
|
||||
port.holdBy(controller);
|
||||
try {
|
||||
if (!setADR()) {
|
||||
throw new Error();
|
||||
}
|
||||
return talk(message);
|
||||
} finally {
|
||||
port.releaseBy(controller);
|
||||
if (!setADR()) {
|
||||
throw new RuntimeException("F")
|
||||
}
|
||||
return talk(message);
|
||||
} catch (PortException ex) {
|
||||
portError("Can not send message to the port", ex);
|
||||
reportError("Can not send message to the port", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
@ -28,16 +28,16 @@ import java.util.function.Predicate;
|
||||
*
|
||||
* @author Polina
|
||||
*/
|
||||
public class SafeMagnetController extends MagnetController {
|
||||
public class SafeLambdaMagnet extends LambdaMagnet {
|
||||
|
||||
private final Set<SafeMagnetCondition> safeConditions = new HashSet<>();
|
||||
|
||||
public SafeMagnetController(String name, Port port, int address, int timeout, SafeMagnetCondition... safeConditions) {
|
||||
public SafeLambdaMagnet(String name, Port port, int address, int timeout, SafeMagnetCondition... safeConditions) {
|
||||
super(name, port, address, timeout);
|
||||
this.safeConditions.addAll(Arrays.asList(safeConditions));
|
||||
}
|
||||
|
||||
public SafeMagnetController(String name, Port port, int address, SafeMagnetCondition... safeConditions) {
|
||||
public SafeLambdaMagnet(String name, Port port, int address, SafeMagnetCondition... safeConditions) {
|
||||
super(name, port, address);
|
||||
this.safeConditions.addAll(Arrays.asList(safeConditions));
|
||||
}
|
||||
@ -62,7 +62,7 @@ public class SafeMagnetController extends MagnetController {
|
||||
* @param controller
|
||||
* @param tolerance
|
||||
*/
|
||||
public void bindTo(SafeMagnetController controller, double tolerance){
|
||||
public void bindTo(SafeLambdaMagnet controller, double tolerance){
|
||||
this.addSafeCondition((I)->Math.abs(controller.getMeasuredI() - I) <= tolerance, false);
|
||||
controller.addSafeCondition((I)->Math.abs(this.getMeasuredI() - I) <= tolerance, false);
|
||||
}
|
@ -38,7 +38,7 @@ public class SetCurrent {
|
||||
|
||||
Port handler = new ComPort(comName);
|
||||
|
||||
MagnetController controller = new MagnetController(handler, lambdaaddress);
|
||||
LambdaMagnet controller = new LambdaMagnet(handler, lambdaaddress);
|
||||
|
||||
controller.startUpdateTask(current, 500);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class Talk {
|
||||
handler = PortFactory.getPort(portName);
|
||||
handler.setPhraseCondition((String str) -> str.endsWith("\r"));
|
||||
|
||||
// MagnetController controller = new MagnetController(handler, 1);
|
||||
// LambdaMagnet controller = new LambdaMagnet(handler, 1);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
System.out.printf("INPUT > ");
|
||||
|
@ -35,16 +35,16 @@ public class TestController {
|
||||
// rootLogger.setLevel(Level.INFO);
|
||||
|
||||
Port handler;
|
||||
MagnetController firstController;
|
||||
MagnetController secondController;
|
||||
LambdaMagnet firstController;
|
||||
LambdaMagnet secondController;
|
||||
|
||||
// String comName = "COM12";
|
||||
// handler = new ComPort(comName);
|
||||
handler = new VirtualLambdaPort("COM12", 1, 2, 3, 4);
|
||||
|
||||
firstController = new MagnetController(handler, 1);
|
||||
// secondController = new MagnetController(handler, 4);
|
||||
secondController = new SafeMagnetController("TEST", handler, 4, (int address, double current) -> current < 1.0);
|
||||
firstController = new LambdaMagnet(handler, 1);
|
||||
// secondController = new LambdaMagnet(handler, 4);
|
||||
secondController = new SafeLambdaMagnet("TEST", handler, 4, (int address, double current) -> current < 1.0);
|
||||
|
||||
MagnetStateListener listener = new MagnetStateListener() {
|
||||
|
||||
|
@ -39,17 +39,17 @@ public class TestSynch {
|
||||
rootLogger.setLevel(Level.INFO);
|
||||
|
||||
Port handler;
|
||||
MagnetController firstController;
|
||||
MagnetController secondController;
|
||||
LambdaMagnet firstController;
|
||||
LambdaMagnet secondController;
|
||||
|
||||
// String comName = "COM12";
|
||||
// handler = new ComPort(comName);
|
||||
handler = new VirtualLambdaPort("COM12", 1, 2, 3, 4);
|
||||
|
||||
firstController = new MagnetController(handler, 1);
|
||||
// secondController = new MagnetController(handler, 2);
|
||||
secondController = new SafeMagnetController("TEST", handler, 2,
|
||||
new SafeMagnetController.SafeMagnetCondition() {
|
||||
firstController = new LambdaMagnet(handler, 1);
|
||||
// secondController = new LambdaMagnet(handler, 2);
|
||||
secondController = new SafeLambdaMagnet("TEST", handler, 2,
|
||||
new SafeLambdaMagnet.SafeMagnetCondition() {
|
||||
|
||||
// @Override
|
||||
// public boolean isBloking() {
|
||||
|
@ -21,8 +21,8 @@ import ch.qos.logback.core.FileAppender;
|
||||
import hep.dataforge.control.ports.Port;
|
||||
import hep.dataforge.control.ports.PortFactory;
|
||||
import hep.dataforge.exceptions.ControlException;
|
||||
import inr.numass.control.magnet.MagnetController;
|
||||
import inr.numass.control.magnet.SafeMagnetController;
|
||||
import inr.numass.control.magnet.LambdaMagnet;
|
||||
import inr.numass.control.magnet.SafeLambdaMagnet;
|
||||
import inr.numass.control.magnet.VirtualLambdaPort;
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
@ -42,11 +42,11 @@ import java.util.Locale;
|
||||
public class MagnetControllerApp extends Application {
|
||||
|
||||
Port handler;
|
||||
SafeMagnetController sourceController;
|
||||
SafeMagnetController pinchController;
|
||||
SafeMagnetController conusController;
|
||||
SafeMagnetController detectorController;
|
||||
List<SafeMagnetController> controllers = new ArrayList<>();
|
||||
SafeLambdaMagnet sourceController;
|
||||
SafeLambdaMagnet pinchController;
|
||||
SafeLambdaMagnet conusController;
|
||||
SafeLambdaMagnet detectorController;
|
||||
List<SafeLambdaMagnet> controllers = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException, ControlException {
|
||||
@ -76,10 +76,10 @@ public class MagnetControllerApp extends Application {
|
||||
//TODO add meta reader here
|
||||
}
|
||||
|
||||
sourceController = new SafeMagnetController("SOURCE", handler, 1);
|
||||
pinchController = new SafeMagnetController("PINCH", handler, 2);
|
||||
conusController = new SafeMagnetController("CONUS", handler, 3);
|
||||
detectorController = new SafeMagnetController("DETECTOR", handler, 4);
|
||||
sourceController = new SafeLambdaMagnet("SOURCE", handler, 1);
|
||||
pinchController = new SafeLambdaMagnet("PINCH", handler, 2);
|
||||
conusController = new SafeLambdaMagnet("CONUS", handler, 3);
|
||||
detectorController = new SafeLambdaMagnet("DETECTOR", handler, 4);
|
||||
|
||||
conusController.bindTo(pinchController, 30.0);
|
||||
|
||||
@ -95,7 +95,7 @@ public class MagnetControllerApp extends Application {
|
||||
VBox vbox = new VBox(5);
|
||||
double height = 0;
|
||||
double width = 0;
|
||||
for (MagnetController controller : controllers) {
|
||||
for (LambdaMagnet controller : controllers) {
|
||||
MagnetControllerComponent comp = MagnetControllerComponent.build(controller);
|
||||
width = Math.max(width, comp.getPrefWidth());
|
||||
height += comp.getPrefHeight()+5;
|
||||
@ -117,7 +117,7 @@ public class MagnetControllerApp extends Application {
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
super.stop(); //To change body of generated methods, choose Tools | Templates.
|
||||
for (MagnetController magnet : controllers) {
|
||||
for (LambdaMagnet magnet : controllers) {
|
||||
magnet.stopMonitorTask();
|
||||
magnet.stopUpdateTask();
|
||||
}
|
||||
|
@ -16,27 +16,24 @@
|
||||
package inr.numass.control.magnet.fx;
|
||||
|
||||
import hep.dataforge.exceptions.PortException;
|
||||
import inr.numass.control.magnet.MagnetController;
|
||||
import inr.numass.control.magnet.LambdaMagnet;
|
||||
import inr.numass.control.magnet.MagnetStateListener;
|
||||
import inr.numass.control.magnet.MagnetStatus;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* FXML Controller class
|
||||
*
|
||||
@ -44,14 +41,14 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class MagnetControllerComponent extends AnchorPane implements Initializable, MagnetStateListener {
|
||||
|
||||
private MagnetController magnetController;
|
||||
private LambdaMagnet lambdaMagnet;
|
||||
private Logger logger;
|
||||
|
||||
private boolean showConfirmation = true;
|
||||
|
||||
public static MagnetControllerComponent build(MagnetController magnetController) {
|
||||
public static MagnetControllerComponent build(LambdaMagnet lambdaMagnet) {
|
||||
MagnetControllerComponent component = new MagnetControllerComponent();
|
||||
FXMLLoader loader = new FXMLLoader(magnetController.getClass().getResource("/fxml/SingleMagnet.fxml"));
|
||||
FXMLLoader loader = new FXMLLoader(lambdaMagnet.getClass().getResource("/fxml/SingleMagnet.fxml"));
|
||||
|
||||
loader.setRoot(component);
|
||||
loader.setController(component);
|
||||
@ -62,7 +59,7 @@ public class MagnetControllerComponent extends AnchorPane implements Initializab
|
||||
LoggerFactory.getLogger("FX").error("Error during fxml initialization", ex);
|
||||
throw new Error(ex);
|
||||
}
|
||||
component.setMagnetController(magnetController);
|
||||
component.setLambdaMagnet(lambdaMagnet);
|
||||
return component;
|
||||
}
|
||||
|
||||
@ -83,7 +80,7 @@ public class MagnetControllerComponent extends AnchorPane implements Initializab
|
||||
@FXML
|
||||
private TextField magnetSpeedField;
|
||||
|
||||
// public MagnetControllerComponent(MagnetController magnetController) {
|
||||
// public MagnetControllerComponent(LambdaMagnet lambdaMagnet) {
|
||||
// FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/SingleMagnet.fxml"));
|
||||
//
|
||||
// loader.setRoot(this);
|
||||
@ -94,7 +91,7 @@ public class MagnetControllerComponent extends AnchorPane implements Initializab
|
||||
// } catch (IOException ex) {
|
||||
// throw new RuntimeException(ex);
|
||||
// }
|
||||
// setMagnetController(magnetController);
|
||||
// setLambdaMagnet(lambdaMagnet);
|
||||
// }
|
||||
/**
|
||||
* Initializes the controller class.
|
||||
@ -127,7 +124,7 @@ public class MagnetControllerComponent extends AnchorPane implements Initializab
|
||||
try {
|
||||
setOutput(setButton.isSelected());
|
||||
} catch (PortException ex) {
|
||||
error(this.magnetController.getName(), null, ex);
|
||||
error(this.lambdaMagnet.getName(), null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,7 +153,7 @@ public class MagnetControllerComponent extends AnchorPane implements Initializab
|
||||
startCurrentChange();
|
||||
}
|
||||
} else {
|
||||
getMagnetController().stopUpdateTask();
|
||||
getLambdaMagnet().stopUpdateTask();
|
||||
targetIField.setDisable(false);
|
||||
magnetSpeedField.setDisable(false);
|
||||
}
|
||||
@ -165,10 +162,10 @@ public class MagnetControllerComponent extends AnchorPane implements Initializab
|
||||
private void startCurrentChange() throws PortException {
|
||||
double speed = Double.parseDouble(magnetSpeedField.getText());
|
||||
if (speed > 0 && speed <= 7) {
|
||||
magnetController.setSpeed(speed);
|
||||
lambdaMagnet.setSpeed(speed);
|
||||
magnetSpeedField.setDisable(true);
|
||||
getMagnetController().setOutputMode(true);
|
||||
getMagnetController().startUpdateTask(getTargetI());
|
||||
getLambdaMagnet().setOutputMode(true);
|
||||
getLambdaMagnet().startUpdateTask(getTargetI());
|
||||
} else {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setContentText(null);
|
||||
@ -176,7 +173,7 @@ public class MagnetControllerComponent extends AnchorPane implements Initializab
|
||||
alert.setTitle("Ошибка!");
|
||||
alert.show();
|
||||
setButton.setSelected(false);
|
||||
magnetSpeedField.setText(Double.toString(magnetController.getSpeed()));
|
||||
magnetSpeedField.setText(Double.toString(lambdaMagnet.getSpeed()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -184,9 +181,9 @@ public class MagnetControllerComponent extends AnchorPane implements Initializab
|
||||
@FXML
|
||||
private void onMonitorToggle(ActionEvent event) {
|
||||
if (monitorButton.isSelected()) {
|
||||
getMagnetController().startMonitorTask();
|
||||
getLambdaMagnet().startMonitorTask();
|
||||
} else {
|
||||
getMagnetController().stopMonitorTask();
|
||||
getLambdaMagnet().stopMonitorTask();
|
||||
this.labelU.setText("----");
|
||||
}
|
||||
}
|
||||
@ -202,25 +199,25 @@ public class MagnetControllerComponent extends AnchorPane implements Initializab
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the magnetController
|
||||
* @return the lambdaMagnet
|
||||
*/
|
||||
public MagnetController getMagnetController() {
|
||||
if (magnetController == null) {
|
||||
public LambdaMagnet getLambdaMagnet() {
|
||||
if (lambdaMagnet == null) {
|
||||
throw new RuntimeException("Magnet controller not defined");
|
||||
}
|
||||
return magnetController;
|
||||
return lambdaMagnet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param magnetController the magnetController to set
|
||||
* @param lambdaMagnet the lambdaMagnet to set
|
||||
*/
|
||||
private void setMagnetController(MagnetController magnetController) {
|
||||
this.magnetController = magnetController;
|
||||
logger = LoggerFactory.getLogger("lambda." + magnetController.getName());
|
||||
magnetController.setListener(this);
|
||||
magnetName.setText(magnetController.getName());
|
||||
private void setLambdaMagnet(LambdaMagnet lambdaMagnet) {
|
||||
this.lambdaMagnet = lambdaMagnet;
|
||||
logger = LoggerFactory.getLogger("lambda." + lambdaMagnet.getName());
|
||||
lambdaMagnet.setListener(this);
|
||||
magnetName.setText(lambdaMagnet.getName());
|
||||
|
||||
magnetSpeedField.setText(Double.toString(this.magnetController.getSpeed()));
|
||||
magnetSpeedField.setText(Double.toString(this.lambdaMagnet.getSpeed()));
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
package inr.numass.control.magnet
|
||||
|
||||
import hep.dataforge.control.ports.Port
|
||||
|
||||
class LambdaPortController(private val port: Port) : Port.PortController {
|
||||
|
||||
private var address: Int = -1;
|
||||
|
||||
init {
|
||||
port.holdBy(this)
|
||||
}
|
||||
|
||||
override fun acceptPhrase(message: String?) {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun portError(errorMessage: String?, error: Throwable?) {
|
||||
super.portError(errorMessage, error)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user