Some fixes to numass devices
This commit is contained in:
parent
8ecdd75066
commit
0ab153a30e
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
public interface MagnetStateListener {
|
||||
|
||||
void acceptStatus(String name, MagnetStatus state);
|
||||
|
||||
void acceptNextI(String name, double nextI);
|
||||
|
||||
void acceptMeasuredI(String name, double measuredI);
|
||||
|
||||
default void displayState(String state){
|
||||
|
||||
}
|
||||
|
||||
default void error(String name, String errorMessage, Throwable throwable){
|
||||
throw new RuntimeException(errorMessage, throwable);
|
||||
}
|
||||
|
||||
default void monitorTaskStateChanged(String name, boolean monitorTaskRunning) {
|
||||
|
||||
}
|
||||
|
||||
default void updateTaskStateChanged(String name, boolean updateTaskRunning) {
|
||||
|
||||
}
|
||||
|
||||
default void outputModeChanged(String name, boolean out) {
|
||||
|
||||
}
|
||||
|
||||
default void addressChanged(String name, int address) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Polina
|
||||
*/
|
||||
public class MagnetStatus {
|
||||
|
||||
private boolean on;
|
||||
private final boolean out;
|
||||
private final double measuredCurrent;
|
||||
private final double setCurrent;
|
||||
private final double measuredVoltage;
|
||||
private final double setVoltage;
|
||||
|
||||
public MagnetStatus(boolean isOut, double measuredCurrent, double setCurrent, double measuredVoltage, double setVoltage) {
|
||||
this.on = true;
|
||||
this.out = isOut;
|
||||
this.measuredCurrent = measuredCurrent;
|
||||
this.setCurrent = setCurrent;
|
||||
this.measuredVoltage = measuredVoltage;
|
||||
this.setVoltage = setVoltage;
|
||||
}
|
||||
|
||||
public static MagnetStatus off() {
|
||||
MagnetStatus res = new MagnetStatus(false, 0, 0, 0, 0);
|
||||
res.on = false;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isOn
|
||||
*/
|
||||
public boolean isOn() {
|
||||
return on;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isOut
|
||||
*/
|
||||
public boolean isOutputOn() {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the measuredCurrent
|
||||
*/
|
||||
public double getMeasuredCurrent() {
|
||||
return measuredCurrent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the setCurrent
|
||||
*/
|
||||
public double getSetCurrent() {
|
||||
return setCurrent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the measuredVoltage
|
||||
*/
|
||||
public double getMeasuredVoltage() {
|
||||
return measuredVoltage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the setVoltage
|
||||
*/
|
||||
public double getSetVoltage() {
|
||||
return setVoltage;
|
||||
}
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import hep.dataforge.control.ports.GenericPortController;
|
||||
import hep.dataforge.control.ports.Port;
|
||||
import hep.dataforge.control.ports.PortFactory;
|
||||
import hep.dataforge.exceptions.PortException;
|
||||
import hep.dataforge.utils.DateTimeUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
public class Talk {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
Locale.setDefault(Locale.US);
|
||||
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
|
||||
rootLogger.setLevel(Level.INFO);
|
||||
|
||||
String portName = "/dev/ttyr00";
|
||||
|
||||
if (args.length > 0) {
|
||||
portName = args[0];
|
||||
}
|
||||
Port handler;
|
||||
handler = PortFactory.getPort(portName);
|
||||
handler.setPhraseCondition((String str) -> str.endsWith("\r"));
|
||||
|
||||
// LambdaMagnet controller = new LambdaMagnet(handler, 1);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
System.out.printf("INPUT > ");
|
||||
String nextString = reader.readLine();
|
||||
|
||||
while (!"exit".equals(nextString)) {
|
||||
try {
|
||||
Instant start = DateTimeUtils.now();
|
||||
String answer = GenericPortController.sendAndWait(handler, nextString + "\r", Duration.ofSeconds(1));
|
||||
//String answer = controller.request(nextString);
|
||||
System.out.printf("ANSWER (latency = %s): %s;%n", Duration.between(start, DateTimeUtils.now()), answer.trim());
|
||||
} catch (PortException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
System.out.printf("INPUT > ");
|
||||
nextString = reader.readLine();
|
||||
}
|
||||
|
||||
handler.close();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet;
|
||||
|
||||
import hep.dataforge.control.ports.Port;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
public class TestController {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
Locale.setDefault(Locale.US);// чтобы отделение десятичных знаков было точкой
|
||||
// ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
|
||||
// rootLogger.setLevel(Level.INFO);
|
||||
|
||||
Port handler;
|
||||
LambdaMagnet firstController;
|
||||
LambdaMagnet secondController;
|
||||
|
||||
// String comName = "COM12";
|
||||
// handler = new ComPort(comName);
|
||||
handler = new VirtualLambdaPort("COM12", 1, 2, 3, 4);
|
||||
|
||||
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() {
|
||||
|
||||
@Override
|
||||
public void acceptStatus(String name, MagnetStatus state) {
|
||||
System.out.printf("%s (%s): Im = %f, Um = %f, Is = %f, Us = %f;%n",
|
||||
name,
|
||||
state.isOutputOn(),
|
||||
state.getMeasuredCurrent(),
|
||||
state.getMeasuredVoltage(),
|
||||
state.getSetCurrent(),
|
||||
state.getSetVoltage()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptNextI(String name, double nextI) {
|
||||
System.out.printf("%s: nextI = %f;%n", name, nextI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptMeasuredI(String name, double measuredI) {
|
||||
System.out.printf("%s: measuredI = %f;%n", name, measuredI);
|
||||
}
|
||||
};
|
||||
|
||||
firstController.setListener(listener);
|
||||
secondController.setListener(listener);
|
||||
|
||||
try {
|
||||
firstController.startMonitorTask(2000);
|
||||
secondController.startMonitorTask(2000);
|
||||
secondController.setOutputMode(true);
|
||||
secondController.startUpdateTask(2.0, 1000);
|
||||
System.in.read();
|
||||
firstController.stopMonitorTask();
|
||||
secondController.stopMonitorTask();
|
||||
secondController.stopUpdateTask();
|
||||
secondController.setOutputMode(false);
|
||||
} finally {
|
||||
// handler.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import hep.dataforge.control.ports.Port;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
public class TestSynch {
|
||||
|
||||
private static double firstCurrent = 0;
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
Locale.setDefault(Locale.US);// чтобы отделение десятичных знаков было точкой
|
||||
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
|
||||
rootLogger.setLevel(Level.INFO);
|
||||
|
||||
Port handler;
|
||||
LambdaMagnet firstController;
|
||||
LambdaMagnet secondController;
|
||||
|
||||
// String comName = "COM12";
|
||||
// handler = new ComPort(comName);
|
||||
handler = new VirtualLambdaPort("COM12", 1, 2, 3, 4);
|
||||
|
||||
firstController = new LambdaMagnet(handler, 1);
|
||||
// secondController = new LambdaMagnet(handler, 2);
|
||||
secondController = new SafeLambdaMagnet("TEST", handler, 2,
|
||||
new SafeLambdaMagnet.SafeMagnetCondition() {
|
||||
|
||||
// @Override
|
||||
// public boolean isBlocking() {
|
||||
// return false;
|
||||
// }
|
||||
@Override
|
||||
public void onFail() {
|
||||
java.awt.Toolkit.getDefaultToolkit().beep();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSafe(int address, double current) {
|
||||
return Math.abs(current - firstCurrent) <= 0.2;
|
||||
}
|
||||
});
|
||||
|
||||
MagnetStateListener listener = new MagnetStateListener() {
|
||||
|
||||
@Override
|
||||
public void acceptStatus(String name, MagnetStatus state) {
|
||||
System.out.printf("%s (%s): Im = %f, Um = %f, Is = %f, Us = %f;%n",
|
||||
name,
|
||||
state.isOutputOn(),
|
||||
state.getMeasuredCurrent(),
|
||||
state.getMeasuredVoltage(),
|
||||
state.getSetCurrent(),
|
||||
state.getSetVoltage()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptNextI(String name, double nextI) {
|
||||
System.out.printf("%s: nextI = %f;%n", name, nextI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptMeasuredI(String name, double measuredI) {
|
||||
System.out.printf("%s: measuredI = %f;%n", name, measuredI);
|
||||
}
|
||||
};
|
||||
|
||||
firstController.setListener(listener);
|
||||
secondController.setListener(listener);
|
||||
|
||||
try {
|
||||
firstController.startMonitorTask(2000);
|
||||
secondController.startMonitorTask(2000);
|
||||
secondController.setOutputMode(true);
|
||||
firstController.setOutputMode(true);
|
||||
firstController.startUpdateTask(1.0, 10);
|
||||
secondController.startUpdateTask(2.0, 10);
|
||||
System.in.read();
|
||||
firstController.stopMonitorTask();
|
||||
secondController.stopMonitorTask();
|
||||
secondController.stopUpdateTask();
|
||||
firstController.stopUpdateTask();
|
||||
secondController.setOutputMode(false);
|
||||
firstController.setOutputMode(false);
|
||||
System.exit(0);
|
||||
} finally {
|
||||
// handler.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet.fx;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
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.LambdaMagnet;
|
||||
import inr.numass.control.magnet.SafeLambdaMagnet;
|
||||
import inr.numass.control.magnet.VirtualLambdaPort;
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
public class MagnetControllerApp extends Application {
|
||||
|
||||
Port handler;
|
||||
SafeLambdaMagnet sourceController;
|
||||
SafeLambdaMagnet pinchController;
|
||||
SafeLambdaMagnet conusController;
|
||||
SafeLambdaMagnet detectorController;
|
||||
List<SafeLambdaMagnet> controllers = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException, ControlException {
|
||||
Locale.setDefault(Locale.US);// чтобы отделение десятичных знаков было точкой
|
||||
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
|
||||
|
||||
String logLevel = getParameters().getNamed().getOrDefault("logLevel","INFO");
|
||||
|
||||
rootLogger.setLevel(Level.valueOf(logLevel));
|
||||
|
||||
String logFile = getParameters().getNamed().get("logFile");
|
||||
|
||||
if(logFile!=null){
|
||||
FileAppender<ILoggingEvent> appender = new FileAppender<>();
|
||||
appender.setFile(logFile);
|
||||
appender.setContext(rootLogger.getLoggerContext());
|
||||
appender.start();
|
||||
rootLogger.addAppender(appender);
|
||||
}
|
||||
|
||||
String portName = getParameters().getNamed().getOrDefault("port","virtual");
|
||||
|
||||
if(portName.equals("virtual")){
|
||||
handler = new VirtualLambdaPort("COM12", 1, 2, 3, 4);
|
||||
} else {
|
||||
handler = PortFactory.getPort(portName);
|
||||
//TODO add meta reader here
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
controllers.add(sourceController);
|
||||
sourceController.setSpeed(4d);
|
||||
controllers.add(pinchController);
|
||||
controllers.add(conusController);
|
||||
controllers.add(detectorController);
|
||||
|
||||
|
||||
boolean showConfirmation = Boolean.parseBoolean(getParameters().getNamed().getOrDefault("confirmOut","false"));
|
||||
|
||||
VBox vbox = new VBox(5);
|
||||
double height = 0;
|
||||
double width = 0;
|
||||
for (LambdaMagnet controller : controllers) {
|
||||
MagnetControllerComponent comp = MagnetControllerComponent.build(controller);
|
||||
width = Math.max(width, comp.getPrefWidth());
|
||||
height += comp.getPrefHeight()+5;
|
||||
if(!showConfirmation){
|
||||
comp.setShowConfirmation(showConfirmation);
|
||||
}
|
||||
vbox.getChildren().add(comp);
|
||||
}
|
||||
|
||||
Scene scene = new Scene(vbox, width, height);
|
||||
|
||||
|
||||
stage.setTitle("Numass magnet view");
|
||||
stage.setScene(scene);
|
||||
stage.setResizable(false);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
super.stop(); //To change body of generated methods, choose Tools | Templates.
|
||||
for (LambdaMagnet magnet : controllers) {
|
||||
magnet.stopMonitorTask();
|
||||
magnet.stopUpdateTask();
|
||||
}
|
||||
if(handler.isOpen()){
|
||||
handler.close();
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
}
|
@ -1,297 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet.fx;
|
||||
|
||||
import hep.dataforge.exceptions.PortException;
|
||||
import inr.numass.control.magnet.LambdaMagnet;
|
||||
import inr.numass.control.magnet.MagnetStateListener;
|
||||
import inr.numass.control.magnet.MagnetStatus;
|
||||
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.*;
|
||||
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
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
public class MagnetControllerComponent extends AnchorPane implements Initializable, MagnetStateListener {
|
||||
|
||||
private LambdaMagnet lambdaMagnet;
|
||||
private Logger logger;
|
||||
|
||||
private boolean showConfirmation = true;
|
||||
|
||||
public static MagnetControllerComponent build(LambdaMagnet lambdaMagnet) {
|
||||
MagnetControllerComponent component = new MagnetControllerComponent();
|
||||
FXMLLoader loader = new FXMLLoader(lambdaMagnet.getClass().getResource("/fxml/SingleMagnet.fxml"));
|
||||
|
||||
loader.setRoot(component);
|
||||
loader.setController(component);
|
||||
|
||||
try {
|
||||
loader.load();
|
||||
} catch (Exception ex) {
|
||||
LoggerFactory.getLogger("FX").error("Error during fxml initialization", ex);
|
||||
throw new Error(ex);
|
||||
}
|
||||
component.setLambdaMagnet(lambdaMagnet);
|
||||
return component;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private Label labelI;
|
||||
@FXML
|
||||
private Label labelU;
|
||||
@FXML
|
||||
private TextField targetIField;
|
||||
@FXML
|
||||
private Label magnetName;
|
||||
@FXML
|
||||
private ToggleButton monitorButton;
|
||||
@FXML
|
||||
private Label statusLabel;
|
||||
@FXML
|
||||
private ToggleButton setButton;
|
||||
@FXML
|
||||
private TextField magnetSpeedField;
|
||||
|
||||
// public MagnetControllerComponent(LambdaMagnet lambdaMagnet) {
|
||||
// FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/SingleMagnet.fxml"));
|
||||
//
|
||||
// loader.setRoot(this);
|
||||
// loader.setController(this);
|
||||
//
|
||||
// try {
|
||||
// loader.load();
|
||||
// } catch (IOException ex) {
|
||||
// throw new RuntimeException(ex);
|
||||
// }
|
||||
// setLambdaMagnet(lambdaMagnet);
|
||||
// }
|
||||
/**
|
||||
* Initializes the controller class.
|
||||
*
|
||||
* @param url
|
||||
* @param rb
|
||||
*/
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
|
||||
targetIField.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
|
||||
if (!newValue.matches("\\d*(\\.)?\\d*")) {
|
||||
targetIField.setText(oldValue);
|
||||
}
|
||||
});
|
||||
|
||||
magnetSpeedField.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
|
||||
if (!newValue.matches("\\d*(\\.)?\\d*")) {
|
||||
magnetSpeedField.setText(oldValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setShowConfirmation(boolean showConfirmation) {
|
||||
this.showConfirmation = showConfirmation;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onOutToggle(ActionEvent event) {
|
||||
try {
|
||||
setOutput(setButton.isSelected());
|
||||
} catch (PortException ex) {
|
||||
error(this.lambdaMagnet.getName(), null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private double getTargetI() {
|
||||
return Double.parseDouble(targetIField.getText());
|
||||
}
|
||||
|
||||
private void setOutput(boolean outputOn) throws PortException {
|
||||
if (outputOn) {
|
||||
if (showConfirmation) {
|
||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||
alert.setContentText("Изменение токов в сверхпроводящих магнитах можно производить только при выключенном напряжении на спектрометре."
|
||||
+ "\nВы уверены что напряжение выключено?");
|
||||
alert.setHeaderText("Проверьте напряжение на спектрометре!");
|
||||
alert.setHeight(150);
|
||||
alert.setTitle("Внимание!");
|
||||
alert.getButtonTypes().clear();
|
||||
alert.getButtonTypes().addAll(ButtonType.YES, ButtonType.CANCEL);
|
||||
|
||||
if (alert.showAndWait().orElse(ButtonType.CANCEL).equals(ButtonType.YES)) {
|
||||
startCurrentChange();
|
||||
} else {
|
||||
setButton.setSelected(false);
|
||||
}
|
||||
} else {
|
||||
startCurrentChange();
|
||||
}
|
||||
} else {
|
||||
getLambdaMagnet().stopUpdateTask();
|
||||
targetIField.setDisable(false);
|
||||
magnetSpeedField.setDisable(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void startCurrentChange() throws PortException {
|
||||
double speed = Double.parseDouble(magnetSpeedField.getText());
|
||||
if (speed > 0 && speed <= 7) {
|
||||
lambdaMagnet.setSpeed(speed);
|
||||
magnetSpeedField.setDisable(true);
|
||||
getLambdaMagnet().setOutputMode(true);
|
||||
getLambdaMagnet().startUpdateTask(getTargetI());
|
||||
} else {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setContentText(null);
|
||||
alert.setHeaderText("Недопустимое значение скорости изменения тока");
|
||||
alert.setTitle("Ошибка!");
|
||||
alert.show();
|
||||
setButton.setSelected(false);
|
||||
magnetSpeedField.setText(Double.toString(lambdaMagnet.getSpeed()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onMonitorToggle(ActionEvent event) {
|
||||
if (monitorButton.isSelected()) {
|
||||
getLambdaMagnet().startMonitorTask();
|
||||
} else {
|
||||
getLambdaMagnet().stopMonitorTask();
|
||||
this.labelU.setText("----");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String name, String errorMessage, Throwable throwable) {
|
||||
Platform.runLater(() -> {
|
||||
this.statusLabel.setText("ERROR");
|
||||
this.statusLabel.setTextFill(Color.RED);
|
||||
});
|
||||
this.logger.error("ERROR: {}", errorMessage, throwable);
|
||||
// MagnetStateListener.super.error(address, errorMessage, throwable); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lambdaMagnet
|
||||
*/
|
||||
public LambdaMagnet getLambdaMagnet() {
|
||||
if (lambdaMagnet == null) {
|
||||
throw new RuntimeException("Magnet controller not defined");
|
||||
}
|
||||
return lambdaMagnet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lambdaMagnet the lambdaMagnet to set
|
||||
*/
|
||||
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.lambdaMagnet.getSpeed()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptStatus(String name, MagnetStatus state) {
|
||||
Platform.runLater(() -> {
|
||||
this.labelI.setText(Double.toString(state.getMeasuredCurrent()));
|
||||
this.labelU.setText(Double.toString(state.getMeasuredVoltage()));
|
||||
outputModeChanged(name, state.isOutputOn());
|
||||
|
||||
getLogger().info(String.format("%s (%s): Im = %f, Um = %f, Is = %f, Us = %f;",
|
||||
name,
|
||||
state.isOutputOn(),
|
||||
state.getMeasuredCurrent(),
|
||||
state.getMeasuredVoltage(),
|
||||
state.getSetCurrent(),
|
||||
state.getSetVoltage()
|
||||
));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptNextI(String name, double nextI) {
|
||||
getLogger().debug("{}: nextI = {};", name, nextI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptMeasuredI(String name, double measuredI) {
|
||||
getLogger().debug("{}: measuredI = {};", name, measuredI);
|
||||
Platform.runLater(() -> {
|
||||
this.labelI.setText(Double.toString(measuredI));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void outputModeChanged(String name, boolean out) {
|
||||
Platform.runLater(() -> {
|
||||
if (out) {
|
||||
this.statusLabel.setText("OK");
|
||||
this.statusLabel.setTextFill(Color.BLUE);
|
||||
} else {
|
||||
this.statusLabel.setText("OFF");
|
||||
this.statusLabel.setTextFill(Color.BLACK);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTaskStateChanged(String name, boolean updateTaskRunning) {
|
||||
this.setButton.setSelected(updateTaskRunning);
|
||||
targetIField.setDisable(updateTaskRunning);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void monitorTaskStateChanged(String name, boolean monitorTaskRunning) {
|
||||
this.monitorButton.setScaleShape(monitorTaskRunning);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the logger
|
||||
*/
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param logger the logger to set
|
||||
// */
|
||||
// public void setLogger(PrintStream logger) {
|
||||
// this.logger = logger;
|
||||
// }
|
||||
@Override
|
||||
public void displayState(String state) {
|
||||
Platform.runLater(() -> this.statusLabel.setText(state));
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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.control.magnet.fx;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author darksnake
|
||||
*/
|
||||
public class TestApp {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
MagnetControllerApp.main(new String[]{"--port=192.168.111.31:4001"});
|
||||
//MagnetControllerApp.main(new String[]{"--port=192.168.111.31:4001", "--logLevel=DEBUG"});
|
||||
}
|
||||
|
||||
}
|
@ -5,6 +5,7 @@ import hep.dataforge.control.devices.AbstractDevice
|
||||
import hep.dataforge.control.devices.Device
|
||||
import hep.dataforge.control.devices.DeviceHub
|
||||
import hep.dataforge.control.devices.StateDef
|
||||
import hep.dataforge.control.ports.Port
|
||||
import hep.dataforge.control.ports.PortFactory
|
||||
import hep.dataforge.description.ValueDef
|
||||
import hep.dataforge.kodex.useEachMeta
|
||||
@ -20,7 +21,7 @@ class LambdaHub(context: Context, meta: Meta) : DeviceHub, AbstractDevice(contex
|
||||
|
||||
private val magnets = ArrayList<LambdaMagnet>();
|
||||
|
||||
private val port = PortFactory.getPort(meta.getString("port"))
|
||||
private val port: Port = buildPort()
|
||||
private val controller = LambdaPortController(context, port)
|
||||
|
||||
init {
|
||||
@ -29,6 +30,16 @@ class LambdaHub(context: Context, meta: Meta) : DeviceHub, AbstractDevice(contex
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildPort(): Port{
|
||||
val portName = meta.getString("port");
|
||||
return if(portName.startsWith("virtual")){
|
||||
VirtualLambdaPort(meta)
|
||||
} else{
|
||||
PortFactory.getPort(portName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun init() {
|
||||
super.init()
|
||||
controller.open()
|
||||
|
@ -54,7 +54,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
|
||||
|
||||
private var closePortOnShutDown = false
|
||||
|
||||
private val name: String? = meta.getString("name", "LAMBDA")
|
||||
private val name: String = meta.getString("name", "LAMBDA")
|
||||
/**
|
||||
* @return the address
|
||||
*/
|
||||
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
interface MagnetStateListener {
|
||||
|
||||
fun acceptStatus(name: String, state: MagnetStatus)
|
||||
|
||||
fun acceptNextI(name: String, nextI: Double)
|
||||
|
||||
fun acceptMeasuredI(name: String, measuredI: Double)
|
||||
|
||||
open fun displayState(state: String) {
|
||||
|
||||
}
|
||||
|
||||
open fun error(name: String, errorMessage: String, throwable: Throwable?) {
|
||||
throw RuntimeException(errorMessage, throwable)
|
||||
}
|
||||
|
||||
open fun monitorTaskStateChanged(name: String, monitorTaskRunning: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
open fun updateTaskStateChanged(name: String, updateTaskRunning: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
open fun outputModeChanged(name: String, out: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
fun addressChanged(name: String, address: Int) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Polina
|
||||
*/
|
||||
class MagnetStatus(
|
||||
/**
|
||||
* @return the isOut
|
||||
*/
|
||||
val isOutputOn: Boolean,
|
||||
/**
|
||||
* @return the measuredCurrent
|
||||
*/
|
||||
val measuredCurrent: Double,
|
||||
/**
|
||||
* @return the setCurrent
|
||||
*/
|
||||
val setCurrent: Double,
|
||||
/**
|
||||
* @return the measuredVoltage
|
||||
*/
|
||||
val measuredVoltage: Double,
|
||||
/**
|
||||
* @return the setVoltage
|
||||
*/
|
||||
val setVoltage: Double) {
|
||||
|
||||
/**
|
||||
* @return the isOn
|
||||
*/
|
||||
var isOn: Boolean = false
|
||||
private set
|
||||
|
||||
init {
|
||||
this.isOn = true
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun off(): MagnetStatus {
|
||||
val res = MagnetStatus(false, 0.0, 0.0, 0.0, 0.0)
|
||||
res.isOn = false
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -13,34 +13,35 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet;
|
||||
package inr.numass.control.magnet
|
||||
|
||||
import hep.dataforge.control.ports.ComPort;
|
||||
import hep.dataforge.control.ports.Port;
|
||||
import jssc.SerialPortException;
|
||||
import hep.dataforge.control.ports.ComPort
|
||||
import jssc.SerialPortException
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
public class SetCurrent {
|
||||
object SetCurrent {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) throws SerialPortException {
|
||||
if (args.length < 3) {
|
||||
throw new IllegalArgumentException("Wrong number of parameters");
|
||||
@Throws(SerialPortException::class)
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
if (args.size < 3) {
|
||||
throw IllegalArgumentException("Wrong number of parameters")
|
||||
}
|
||||
String comName = args[0];
|
||||
int lambdaaddress = Integer.valueOf(args[1]);
|
||||
double current = Double.valueOf(args[2]);
|
||||
val comName = args[0]
|
||||
val lambdaaddress = Integer.valueOf(args[1])!!
|
||||
val current = java.lang.Double.valueOf(args[2])
|
||||
|
||||
Port handler = new ComPort(comName);
|
||||
val handler = ComPort(comName)
|
||||
|
||||
LambdaMagnet controller = new LambdaMagnet(handler, lambdaaddress);
|
||||
val controller = LambdaMagnet(handler, lambdaaddress)
|
||||
|
||||
controller.startUpdateTask(current, 500);
|
||||
controller.startUpdateTask(current, 500)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet
|
||||
|
||||
import hep.dataforge.control.ports.Port
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
object TestController {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Throws(Exception::class)
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
Locale.setDefault(Locale.US)// чтобы отделение десятичных знаков было точкой
|
||||
// ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
|
||||
// rootLogger.setLevel(Level.INFO);
|
||||
|
||||
val handler: Port
|
||||
val firstController: LambdaMagnet
|
||||
val secondController: LambdaMagnet
|
||||
|
||||
// String comName = "COM12";
|
||||
// handler = new ComPort(comName);
|
||||
handler = VirtualLambdaPort("COM12", 1, 2, 3, 4)
|
||||
|
||||
firstController = LambdaMagnet(handler, 1)
|
||||
// secondController = new LambdaMagnet(handler, 4);
|
||||
secondController = SafeLambdaMagnet("TEST", handler, 4, { address: Int, current: Double -> current < 1.0 })
|
||||
|
||||
val listener = object : MagnetStateListener {
|
||||
|
||||
override fun acceptStatus(name: String, state: MagnetStatus) {
|
||||
System.out.printf("%s (%s): Im = %f, Um = %f, Is = %f, Us = %f;%n",
|
||||
name,
|
||||
state.isOutputOn,
|
||||
state.measuredCurrent,
|
||||
state.measuredVoltage,
|
||||
state.setCurrent,
|
||||
state.setVoltage
|
||||
)
|
||||
}
|
||||
|
||||
override fun acceptNextI(name: String, nextI: Double) {
|
||||
System.out.printf("%s: nextI = %f;%n", name, nextI)
|
||||
}
|
||||
|
||||
override fun acceptMeasuredI(name: String, measuredI: Double) {
|
||||
System.out.printf("%s: measuredI = %f;%n", name, measuredI)
|
||||
}
|
||||
}
|
||||
|
||||
firstController.listener = listener
|
||||
secondController.listener = listener
|
||||
|
||||
try {
|
||||
firstController.startMonitorTask(2000)
|
||||
secondController.startMonitorTask(2000)
|
||||
secondController.setOutputMode(true)
|
||||
secondController.startUpdateTask(2.0, 1000)
|
||||
System.`in`.read()
|
||||
firstController.stopMonitorTask()
|
||||
secondController.stopMonitorTask()
|
||||
secondController.stopUpdateTask()
|
||||
secondController.setOutputMode(false)
|
||||
} finally {
|
||||
// handler.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet
|
||||
|
||||
import ch.qos.logback.classic.Level
|
||||
import hep.dataforge.control.ports.Port
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
object TestSynch {
|
||||
|
||||
private val firstCurrent = 0.0
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Throws(Exception::class)
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
Locale.setDefault(Locale.US)// чтобы отделение десятичных знаков было точкой
|
||||
val rootLogger = LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger
|
||||
rootLogger.level = Level.INFO
|
||||
|
||||
val handler: Port
|
||||
val firstController: LambdaMagnet
|
||||
val secondController: LambdaMagnet
|
||||
|
||||
// String comName = "COM12";
|
||||
// handler = new ComPort(comName);
|
||||
handler = VirtualLambdaPort("COM12", 1, 2, 3, 4)
|
||||
|
||||
firstController = LambdaMagnet(handler, 1)
|
||||
// secondController = new LambdaMagnet(handler, 2);
|
||||
secondController = SafeLambdaMagnet("TEST", handler, 2,
|
||||
object : SafeLambdaMagnet.SafeMagnetCondition {
|
||||
|
||||
// @Override
|
||||
// public boolean isBlocking() {
|
||||
// return false;
|
||||
// }
|
||||
override fun onFail() {
|
||||
java.awt.Toolkit.getDefaultToolkit().beep()
|
||||
|
||||
}
|
||||
|
||||
override fun isSafe(address: Int, current: Double): Boolean {
|
||||
return Math.abs(current - firstCurrent) <= 0.2
|
||||
}
|
||||
})
|
||||
|
||||
val listener = object : MagnetStateListener {
|
||||
|
||||
override fun acceptStatus(name: String, state: MagnetStatus) {
|
||||
System.out.printf("%s (%s): Im = %f, Um = %f, Is = %f, Us = %f;%n",
|
||||
name,
|
||||
state.isOutputOn,
|
||||
state.measuredCurrent,
|
||||
state.measuredVoltage,
|
||||
state.setCurrent,
|
||||
state.setVoltage
|
||||
)
|
||||
}
|
||||
|
||||
override fun acceptNextI(name: String, nextI: Double) {
|
||||
System.out.printf("%s: nextI = %f;%n", name, nextI)
|
||||
}
|
||||
|
||||
override fun acceptMeasuredI(name: String, measuredI: Double) {
|
||||
System.out.printf("%s: measuredI = %f;%n", name, measuredI)
|
||||
}
|
||||
}
|
||||
|
||||
firstController.listener = listener
|
||||
secondController.listener = listener
|
||||
|
||||
try {
|
||||
firstController.startMonitorTask(2000)
|
||||
secondController.startMonitorTask(2000)
|
||||
secondController.setOutputMode(true)
|
||||
firstController.setOutputMode(true)
|
||||
firstController.startUpdateTask(1.0, 10)
|
||||
secondController.startUpdateTask(2.0, 10)
|
||||
System.`in`.read()
|
||||
firstController.stopMonitorTask()
|
||||
secondController.stopMonitorTask()
|
||||
secondController.stopUpdateTask()
|
||||
firstController.stopUpdateTask()
|
||||
secondController.setOutputMode(false)
|
||||
firstController.setOutputMode(false)
|
||||
System.exit(0)
|
||||
} finally {
|
||||
// handler.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet.fx
|
||||
|
||||
import ch.qos.logback.classic.Level
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent
|
||||
import ch.qos.logback.core.FileAppender
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.exceptions.ControlException
|
||||
import hep.dataforge.io.MetaFileReader
|
||||
import inr.numass.control.magnet.LambdaHub
|
||||
import javafx.application.Application
|
||||
import javafx.scene.Scene
|
||||
import javafx.scene.layout.VBox
|
||||
import javafx.stage.Stage
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
class MagnetControllerApp : Application() {
|
||||
|
||||
// internal var handler: Port
|
||||
// internal var sourceController: SafeLambdaMagnet
|
||||
// internal var pinchController: SafeLambdaMagnet
|
||||
// internal var conusController: SafeLambdaMagnet
|
||||
// internal var detectorController: SafeLambdaMagnet
|
||||
// internal var controllers: MutableList<SafeLambdaMagnet> = ArrayList()
|
||||
|
||||
private lateinit var device: LambdaHub
|
||||
val context = Global.instance()
|
||||
|
||||
@Throws(IOException::class, ControlException::class)
|
||||
override fun start(stage: Stage) {
|
||||
Locale.setDefault(Locale.US)// чтобы отделение десятичных знаков было точкой
|
||||
val rootLogger = LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger
|
||||
|
||||
val logLevel = (parameters.named as java.util.Map<String, String>).getOrDefault("logLevel", "INFO")
|
||||
|
||||
rootLogger.level = Level.valueOf(logLevel)
|
||||
|
||||
val logFile = parameters.named["logFile"]
|
||||
|
||||
if (logFile != null) {
|
||||
val appender = FileAppender<ILoggingEvent>()
|
||||
appender.file = logFile
|
||||
appender.context = rootLogger.loggerContext
|
||||
appender.start()
|
||||
rootLogger.addAppender(appender)
|
||||
}
|
||||
|
||||
|
||||
|
||||
val config = MetaFileReader.instance().read(context,)
|
||||
|
||||
device =
|
||||
|
||||
// val portName = (parameters.named as java.util.Map<String, String>).getOrDefault("port", "virtual")
|
||||
//
|
||||
// if (portName == "virtual") {
|
||||
// handler = VirtualLambdaPort("COM12", 1, 2, 3, 4)
|
||||
// } else {
|
||||
// handler = PortFactory.getPort(portName)
|
||||
// //TODO add meta reader here
|
||||
// }
|
||||
//
|
||||
// sourceController = SafeLambdaMagnet("SOURCE", handler, 1)
|
||||
// pinchController = SafeLambdaMagnet("PINCH", handler, 2)
|
||||
// conusController = SafeLambdaMagnet("CONUS", handler, 3)
|
||||
// detectorController = SafeLambdaMagnet("DETECTOR", handler, 4)
|
||||
//
|
||||
// conusController.bindTo(pinchController, 30.0)
|
||||
//
|
||||
// controllers.add(sourceController)
|
||||
// sourceController.speed = 4.0
|
||||
// controllers.add(pinchController)
|
||||
// controllers.add(conusController)
|
||||
// controllers.add(detectorController)
|
||||
|
||||
|
||||
val showConfirmation = java.lang.Boolean.parseBoolean((parameters.named as java.util.Map<String, String>).getOrDefault("confirmOut", "false"))
|
||||
|
||||
val vbox = VBox(5.0)
|
||||
var height = 0.0
|
||||
var width = 0.0
|
||||
for (controller in controllers) {
|
||||
val comp = MagnetControllerComponent.build(controller)
|
||||
width = Math.max(width, comp.prefWidth)
|
||||
height += comp.prefHeight + 5
|
||||
if (!showConfirmation) {
|
||||
comp.setShowConfirmation(showConfirmation)
|
||||
}
|
||||
vbox.children.add(comp)
|
||||
}
|
||||
|
||||
val scene = Scene(vbox, width, height)
|
||||
|
||||
|
||||
stage.title = "Numass magnet view"
|
||||
stage.scene = scene
|
||||
stage.isResizable = false
|
||||
stage.show()
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
override fun stop() {
|
||||
super.stop() //To change body of generated methods, choose Tools | Templates.
|
||||
for (magnet in controllers) {
|
||||
magnet.stopMonitorTask()
|
||||
magnet.stopUpdateTask()
|
||||
}
|
||||
if (handler.isOpen) {
|
||||
handler.close()
|
||||
}
|
||||
System.exit(0)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
Application.launch(*args)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.control.magnet.fx
|
||||
|
||||
import hep.dataforge.exceptions.PortException
|
||||
import inr.numass.control.magnet.LambdaMagnet
|
||||
import inr.numass.control.magnet.MagnetStateListener
|
||||
import inr.numass.control.magnet.MagnetStatus
|
||||
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.*
|
||||
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.*
|
||||
|
||||
/**
|
||||
* FXML Controller class
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
class MagnetControllerComponent : AnchorPane(), Initializable, MagnetStateListener {
|
||||
|
||||
private var lambdaMagnet: LambdaMagnet? = null
|
||||
/**
|
||||
* @return the logger
|
||||
*/
|
||||
var logger: Logger? = null
|
||||
private set
|
||||
|
||||
private var showConfirmation = true
|
||||
|
||||
@FXML
|
||||
private val labelI: Label? = null
|
||||
@FXML
|
||||
private val labelU: Label? = null
|
||||
@FXML
|
||||
private val targetIField: TextField? = null
|
||||
@FXML
|
||||
private val magnetName: Label? = null
|
||||
@FXML
|
||||
private val monitorButton: ToggleButton? = null
|
||||
@FXML
|
||||
private val statusLabel: Label? = null
|
||||
@FXML
|
||||
private val setButton: ToggleButton? = null
|
||||
@FXML
|
||||
private val magnetSpeedField: TextField? = null
|
||||
|
||||
private val targetI: Double
|
||||
get() = java.lang.Double.parseDouble(targetIField!!.text)
|
||||
|
||||
// public MagnetControllerComponent(LambdaMagnet lambdaMagnet) {
|
||||
// FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/SingleMagnet.fxml"));
|
||||
//
|
||||
// loader.setRoot(this);
|
||||
// loader.setController(this);
|
||||
//
|
||||
// try {
|
||||
// loader.load();
|
||||
// } catch (IOException ex) {
|
||||
// throw new RuntimeException(ex);
|
||||
// }
|
||||
// setLambdaMagnet(lambdaMagnet);
|
||||
// }
|
||||
/**
|
||||
* Initializes the controller class.
|
||||
*
|
||||
* @param url
|
||||
* @param rb
|
||||
*/
|
||||
override fun initialize(url: URL, rb: ResourceBundle) {
|
||||
|
||||
targetIField!!.textProperty().addListener { observable: ObservableValue<out String>, oldValue: String, newValue: String ->
|
||||
if (!newValue.matches("\\d*(\\.)?\\d*".toRegex())) {
|
||||
targetIField.text = oldValue
|
||||
}
|
||||
}
|
||||
|
||||
magnetSpeedField!!.textProperty().addListener { observable: ObservableValue<out String>, oldValue: String, newValue: String ->
|
||||
if (!newValue.matches("\\d*(\\.)?\\d*".toRegex())) {
|
||||
magnetSpeedField.text = oldValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setShowConfirmation(showConfirmation: Boolean) {
|
||||
this.showConfirmation = showConfirmation
|
||||
}
|
||||
|
||||
@FXML
|
||||
private fun onOutToggle(event: ActionEvent) {
|
||||
try {
|
||||
setOutput(setButton!!.isSelected)
|
||||
} catch (ex: PortException) {
|
||||
error(this.lambdaMagnet!!.name, null, ex)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Throws(PortException::class)
|
||||
private fun setOutput(outputOn: Boolean) {
|
||||
if (outputOn) {
|
||||
if (showConfirmation) {
|
||||
val alert = Alert(Alert.AlertType.WARNING)
|
||||
alert.contentText = "Изменение токов в сверхпроводящих магнитах можно производить только при выключенном напряжении на спектрометре." + "\nВы уверены что напряжение выключено?"
|
||||
alert.headerText = "Проверьте напряжение на спектрометре!"
|
||||
alert.height = 150.0
|
||||
alert.title = "Внимание!"
|
||||
alert.buttonTypes.clear()
|
||||
alert.buttonTypes.addAll(ButtonType.YES, ButtonType.CANCEL)
|
||||
|
||||
if (alert.showAndWait().orElse(ButtonType.CANCEL) == ButtonType.YES) {
|
||||
startCurrentChange()
|
||||
} else {
|
||||
setButton!!.isSelected = false
|
||||
}
|
||||
} else {
|
||||
startCurrentChange()
|
||||
}
|
||||
} else {
|
||||
getLambdaMagnet().stopUpdateTask()
|
||||
targetIField!!.isDisable = false
|
||||
magnetSpeedField!!.isDisable = false
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(PortException::class)
|
||||
private fun startCurrentChange() {
|
||||
val speed = java.lang.Double.parseDouble(magnetSpeedField!!.text)
|
||||
if (speed > 0 && speed <= 7) {
|
||||
lambdaMagnet!!.speed = speed
|
||||
magnetSpeedField.isDisable = true
|
||||
getLambdaMagnet().setOutputMode(true)
|
||||
getLambdaMagnet().startUpdateTask(targetI)
|
||||
} else {
|
||||
val alert = Alert(Alert.AlertType.ERROR)
|
||||
alert.contentText = null
|
||||
alert.headerText = "Недопустимое значение скорости изменения тока"
|
||||
alert.title = "Ошибка!"
|
||||
alert.show()
|
||||
setButton!!.isSelected = false
|
||||
magnetSpeedField.text = java.lang.Double.toString(lambdaMagnet!!.speed)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
private fun onMonitorToggle(event: ActionEvent) {
|
||||
if (monitorButton!!.isSelected) {
|
||||
getLambdaMagnet().startMonitorTask()
|
||||
} else {
|
||||
getLambdaMagnet().stopMonitorTask()
|
||||
this.labelU!!.text = "----"
|
||||
}
|
||||
}
|
||||
|
||||
override fun error(name: String, errorMessage: String?, throwable: Throwable) {
|
||||
Platform.runLater {
|
||||
this.statusLabel!!.text = "ERROR"
|
||||
this.statusLabel.textFill = Color.RED
|
||||
}
|
||||
this.logger!!.error("ERROR: {}", errorMessage, throwable)
|
||||
// MagnetStateListener.super.error(address, errorMessage, throwable); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lambdaMagnet
|
||||
*/
|
||||
fun getLambdaMagnet(): LambdaMagnet {
|
||||
if (lambdaMagnet == null) {
|
||||
throw RuntimeException("Magnet controller not defined")
|
||||
}
|
||||
return lambdaMagnet
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lambdaMagnet the lambdaMagnet to set
|
||||
*/
|
||||
private fun setLambdaMagnet(lambdaMagnet: LambdaMagnet) {
|
||||
this.lambdaMagnet = lambdaMagnet
|
||||
logger = LoggerFactory.getLogger("lambda." + lambdaMagnet.name)
|
||||
lambdaMagnet.listener = this
|
||||
magnetName!!.text = lambdaMagnet.name
|
||||
|
||||
magnetSpeedField!!.text = java.lang.Double.toString(this.lambdaMagnet!!.speed)
|
||||
|
||||
}
|
||||
|
||||
override fun acceptStatus(name: String, state: MagnetStatus) {
|
||||
Platform.runLater {
|
||||
this.labelI!!.text = java.lang.Double.toString(state.measuredCurrent)
|
||||
this.labelU!!.text = java.lang.Double.toString(state.measuredVoltage)
|
||||
outputModeChanged(name, state.isOutputOn)
|
||||
|
||||
logger!!.info(String.format("%s (%s): Im = %f, Um = %f, Is = %f, Us = %f;",
|
||||
name,
|
||||
state.isOutputOn,
|
||||
state.measuredCurrent,
|
||||
state.measuredVoltage,
|
||||
state.setCurrent,
|
||||
state.setVoltage
|
||||
))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun acceptNextI(name: String, nextI: Double) {
|
||||
logger!!.debug("{}: nextI = {};", name, nextI)
|
||||
}
|
||||
|
||||
override fun acceptMeasuredI(name: String, measuredI: Double) {
|
||||
logger!!.debug("{}: measuredI = {};", name, measuredI)
|
||||
Platform.runLater { this.labelI!!.text = java.lang.Double.toString(measuredI) }
|
||||
}
|
||||
|
||||
override fun outputModeChanged(name: String, out: Boolean) {
|
||||
Platform.runLater {
|
||||
if (out) {
|
||||
this.statusLabel!!.text = "OK"
|
||||
this.statusLabel.textFill = Color.BLUE
|
||||
} else {
|
||||
this.statusLabel!!.text = "OFF"
|
||||
this.statusLabel.textFill = Color.BLACK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateTaskStateChanged(name: String, updateTaskRunning: Boolean) {
|
||||
this.setButton!!.isSelected = updateTaskRunning
|
||||
targetIField!!.isDisable = updateTaskRunning
|
||||
}
|
||||
|
||||
override fun monitorTaskStateChanged(name: String, monitorTaskRunning: Boolean) {
|
||||
this.monitorButton!!.isScaleShape = monitorTaskRunning
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param logger the logger to set
|
||||
// */
|
||||
// public void setLogger(PrintStream logger) {
|
||||
// this.logger = logger;
|
||||
// }
|
||||
override fun displayState(state: String) {
|
||||
Platform.runLater { this.statusLabel!!.text = state }
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun build(lambdaMagnet: LambdaMagnet): MagnetControllerComponent {
|
||||
val component = MagnetControllerComponent()
|
||||
val loader = FXMLLoader(lambdaMagnet.javaClass.getResource("/fxml/SingleMagnet.fxml"))
|
||||
|
||||
loader.setRoot(component)
|
||||
loader.setController(component)
|
||||
|
||||
try {
|
||||
loader.load<Any>()
|
||||
} catch (ex: Exception) {
|
||||
LoggerFactory.getLogger("FX").error("Error during fxml initialization", ex)
|
||||
throw Error(ex)
|
||||
}
|
||||
|
||||
component.setLambdaMagnet(lambdaMagnet)
|
||||
return component
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.control.magnet.fx
|
||||
|
||||
import ch.qos.logback.classic.Level
|
||||
import ch.qos.logback.classic.Logger
|
||||
import hep.dataforge.control.ports.GenericPortController
|
||||
import hep.dataforge.control.ports.Port
|
||||
import hep.dataforge.control.ports.PortFactory
|
||||
import hep.dataforge.exceptions.PortException
|
||||
import hep.dataforge.utils.DateTimeUtils
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import java.time.Duration
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
*
|
||||
* @author darksnake
|
||||
*/
|
||||
object TestApp {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
MagnetControllerApp.main(arrayOf("--port=192.168.111.31:4001"))
|
||||
//MagnetControllerApp.main(new String[]{"--port=192.168.111.31:4001", "--logLevel=DEBUG"});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
object Talk {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@Throws(Exception::class)
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
Locale.setDefault(Locale.US)
|
||||
val rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger
|
||||
rootLogger.level = Level.INFO
|
||||
|
||||
var portName = "/dev/ttyr00"
|
||||
|
||||
if (args.size > 0) {
|
||||
portName = args[0]
|
||||
}
|
||||
val handler: Port
|
||||
handler = PortFactory.getPort(portName)
|
||||
handler.setPhraseCondition { str: String -> str.endsWith("\r") }
|
||||
|
||||
// LambdaMagnet controller = new LambdaMagnet(handler, 1);
|
||||
val reader = BufferedReader(InputStreamReader(System.`in`))
|
||||
|
||||
System.out.printf("INPUT > ")
|
||||
var nextString = reader.readLine()
|
||||
|
||||
while ("exit" != nextString) {
|
||||
try {
|
||||
val start = DateTimeUtils.now()
|
||||
val answer = GenericPortController.sendAndWait(handler, nextString + "\r", Duration.ofSeconds(1))
|
||||
//String answer = controller.request(nextString);
|
||||
System.out.printf("ANSWER (latency = %s): %s;%n", Duration.between(start, DateTimeUtils.now()), answer.trim { it <= ' ' })
|
||||
} catch (ex: PortException) {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
|
||||
System.out.printf("INPUT > ")
|
||||
nextString = reader.readLine()
|
||||
}
|
||||
|
||||
handler.close()
|
||||
|
||||
}
|
||||
|
||||
}
|
7
numass-control/magnet/src/main/resources/debug.xml
Normal file
7
numass-control/magnet/src/main/resources/debug.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<magnets port="virtual">
|
||||
<magnet name="SOURCE" address="1" resistance="0.02"/>
|
||||
<magnet name="PINCH" address="2" resistance="0.01"/>
|
||||
<magnet name="CONUS" address="3" resistance="0.005"/>
|
||||
<magnet name="DETECTOR" address="4" resistance="0.007"/>
|
||||
</magnets>
|
Loading…
Reference in New Issue
Block a user