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