numass control update

This commit is contained in:
Alexander Nozik 2017-05-19 15:02:31 +03:00
parent 5570afea77
commit 809c38689a
18 changed files with 140 additions and 48 deletions

View File

@ -28,9 +28,8 @@ task installAll(type: Copy) {
def configRoot = new Node(null, "config"); def configRoot = new Node(null, "config");
subprojects { sub -> subprojects { sub ->
//add device configuration file //add device configuration file
def cfgFile = sub.file("src/main/resources/config/devices.xml") sub.fileTree(dir: 'src/main/resources/config', includes: ['**/*.xml']).each { cfgFile ->
if (cfgFile.exists()) { println "Found config file ${cfgFile}"
println "Found device config file ${cfgFile}"
parser.parse(cfgFile).children().each { parser.parse(cfgFile).children().each {
configRoot.append(it as Node) configRoot.append(it as Node)
} }

View File

@ -1,5 +1,5 @@
plugins{ plugins{
id "org.jetbrains.kotlin.jvm" version '1.1.2-2' id "org.jetbrains.kotlin.jvm" version '1.1.2'
id "application" id "application"
} }
@ -8,7 +8,7 @@ repositories {
} }
if (!hasProperty('mainClass')) { if (!hasProperty('mainClass')) {
ext.mainClass = 'inr.numass.viewer.Viewer'//"inr.numass.viewer.test.TestApp" ext.mainClass = 'inr.numass.control.ServerApp'//"inr.numass.viewer.test.TestApp"
} }
mainClassName = mainClass mainClassName = mainClass
@ -22,11 +22,12 @@ compileKotlin.kotlinOptions.jvmTarget = "1.8"
dependencies { dependencies {
compile project(':numass-core') compile project(':numass-core')
compile project(':numass-control') compile project(':numass-control')
compile project(':numass-server')
compile 'org.controlsfx:controlsfx:8.40.12' compile 'org.controlsfx:controlsfx:8.40.12'
compile "no.tornado:tornadofx:1.7.4" compile "no.tornado:tornadofx:1.7.4"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3" compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2"
} }
apply plugin: 'kotlin' apply plugin: 'kotlin'

View File

@ -0,0 +1,21 @@
package inr.numass.control
import hep.dataforge.context.Global
import javafx.scene.Scene
import tornadofx.*
/**
* Created by darksnake on 19-May-17.
*/
class ServerApp : App(ServerView::class) {
override fun createPrimaryScene(view: UIComponent): Scene {
if (view is ServerView) {
view.context = Global.getContext("NUMASS-SERVER")
NumassControlUtils.getConfig(this).ifPresent { view.configure(it) }
}
return super.createPrimaryScene(view)
}
}

View File

@ -0,0 +1,85 @@
package inr.numass.control
import hep.dataforge.context.Context
import hep.dataforge.exceptions.StorageException
import hep.dataforge.meta.Meta
import hep.dataforge.server.ServerManager
import hep.dataforge.storage.commons.StorageFactory
import inr.numass.client.ClientUtils
import javafx.beans.property.SimpleObjectProperty
import javafx.event.EventHandler
import javafx.scene.control.Hyperlink
import tornadofx.*
/**
* Created by darksnake on 18-May-17.
*/
class ServerView() : View("Numass server controller") {
val contextProperty = SimpleObjectProperty<Context>()
var context by contextProperty
val serverManagerProperty = SimpleObjectProperty<ServerManager>()
var serverManager: ServerManager by serverManagerProperty
var label: Hyperlink by singleAssign();
override val root = borderpane {
center {
hbox {
togglebutton("Server") {
isSelected = false
disableProperty().bind(serverManagerProperty.isNull)
action {
if (isSelected) {
serverManager.startServer()
label.text = serverManager.link;
} else {
serverManager.stopServer()
label.text = ""
}
}
}
label = hyperlink{
action {
hostServices.showDocument(serverManager.link);
}
}
}
}
}
init {
NumassControlUtils.setDFStageIcon(primaryStage)
contextProperty.addListener { _, oldValue, newValue ->
if (oldValue != newValue) {
if (newValue != null) {
serverManager = newValue.pluginManager().getOrLoad(ServerManager::class.java);
} else {
serverManagerProperty.set(null);
}
}
}
primaryStage.onCloseRequest = EventHandler { serverManager.stopServer() }
}
fun configure(meta: Meta) {
meta.optMeta("storage").ifPresent { node ->
context.logger.info("Creating storage for server with meta {}", node)
//building storage in a separate thread
runAsync {
val numassRun = ClientUtils.getRunName(meta)
var storage = StorageFactory.buildStorage(context, node)
if (!numassRun.isEmpty()) {
try {
storage = storage.buildShelf(numassRun, Meta.empty())
} catch (e: StorageException) {
context.logger.error("Failed to build shelf", e)
}
}
serverManager.addStorage("numass", storage);
}
}
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<config>
<server port="8337"/>
</config>

View File

@ -50,6 +50,8 @@ public class PKT8View extends DeviceViewConnection<PKT8Device> implements Initia
@FXML @FXML
private ToggleButton startStopButton; private ToggleButton startStopButton;
@FXML @FXML
private ToggleButton storeButton;
@FXML
private ToggleButton consoleButton; private ToggleButton consoleButton;
@FXML @FXML
private ToggleButton plotButton; private ToggleButton plotButton;
@ -70,6 +72,7 @@ public class PKT8View extends DeviceViewConnection<PKT8Device> implements Initia
sensorColumn.setCellValueFactory(new PropertyValueFactory<>("channel")); sensorColumn.setCellValueFactory(new PropertyValueFactory<>("channel"));
resColumn.setCellValueFactory(new PropertyValueFactory<>("rawString")); resColumn.setCellValueFactory(new PropertyValueFactory<>("rawString"));
tempColumn.setCellValueFactory(new PropertyValueFactory<>("temperatureString")); tempColumn.setCellValueFactory(new PropertyValueFactory<>("temperatureString"));
bindBooleanToState("storing", storeButton.selectedProperty());
} }
@Override @Override

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<config> <config>
<storage path="D:\\temp\\cryo"/>
<device type="PKT8" name="thermo-1"> <device type="PKT8" name="thermo-1">
<!-- Device configuration --> <!-- Device configuration -->
<port>192.168.111.36:4001</port> <port>192.168.111.36:4001</port>

View File

@ -19,15 +19,14 @@
</center> </center>
<top> <top>
<ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER"> <ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>
<ToggleButton fx:id="startStopButton" mnemonicParsing="false" onAction="#onStartStopClick" <ToggleButton fx:id="startStopButton" mnemonicParsing="false" onAction="#onStartStopClick"
text="Start"/> text="Start"/>
<ToggleButton fx:id="storeButton" text="Store"/>
<Separator orientation="VERTICAL"/> <Separator orientation="VERTICAL"/>
<Pane HBox.hgrow="ALWAYS"/> <Pane HBox.hgrow="ALWAYS"/>
<Separator orientation="VERTICAL"/> <Separator orientation="VERTICAL"/>
<ToggleButton fx:id="plotButton" mnemonicParsing="false" text="Plot"/> <ToggleButton fx:id="plotButton" mnemonicParsing="false" text="Plot"/>
<ToggleButton fx:id="consoleButton" mnemonicParsing="false" text="Console"/> <ToggleButton fx:id="consoleButton" mnemonicParsing="false" text="Console"/>
</items>
</ToolBar> </ToolBar>
</top> </top>
<bottom> <bottom>

View File

@ -42,12 +42,12 @@ public abstract class DeviceViewConnection<D extends Device> extends DeviceConne
*/ */
protected void bindBooleanToState(String state, BooleanProperty property) { protected void bindBooleanToState(String state, BooleanProperty property) {
getStateBinding(state).addListener((observable, oldValue, newValue) -> { getStateBinding(state).addListener((observable, oldValue, newValue) -> {
if (oldValue != newValue) { if (isOpen() && oldValue != newValue) {
property.setValue(newValue.booleanValue()); property.setValue(newValue.booleanValue());
} }
}); });
property.addListener((observable, oldValue, newValue) -> { property.addListener((observable, oldValue, newValue) -> {
if (oldValue != newValue) { if (isOpen() && oldValue != newValue) {
getDevice().setState(state, newValue); getDevice().setState(state, newValue);
} }
}); });

View File

@ -1,16 +0,0 @@
package inr.numass.control;
import hep.dataforge.control.devices.Device;
import hep.dataforge.fx.fragments.FXFragment;
import hep.dataforge.fx.fragments.LogFragment;
import hep.dataforge.utils.MetaFactory;
/**
* Created by darksnake on 20-Oct-16.
*/
public interface Framework<T extends Device> {
LogFragment getLogFragment();
FXFragment getPlotFragment();
DeviceFragment<T> getDeviceFragment();
MetaFactory<T> getDeviceFactory();
}

View File

@ -36,6 +36,7 @@ public abstract class NumassControlApplication<D extends Device> extends Applica
primaryStage.show(); primaryStage.show();
device = setupDevice(controller); device = setupDevice(controller);
NumassControlUtils.setDFStageIcon(primaryStage);
setupStage(primaryStage, device); setupStage(primaryStage, device);
} }

View File

@ -14,6 +14,8 @@ import hep.dataforge.storage.commons.StorageFactory;
import hep.dataforge.storage.commons.StorageManager; import hep.dataforge.storage.commons.StorageManager;
import inr.numass.client.ClientUtils; import inr.numass.client.ClientUtils;
import javafx.application.Application; import javafx.application.Application;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -98,4 +100,8 @@ public class NumassControlUtils {
return ctx; return ctx;
} }
public static void setDFStageIcon(Stage stage){
stage.getIcons().add(new Image(NumassControlUtils.class.getResourceAsStream("/img/df.png")));
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -5,8 +5,6 @@
*/ */
package inr.numass.readvac.fx; package inr.numass.readvac.fx;
import hep.dataforge.values.Value;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Node;
@ -41,11 +39,9 @@ public class PoweredVacuumeterView extends VacuumeterView {
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
super.initialize(location,resources);
unitLabel.setText(getDevice().meta().getString("units", "mbar")); unitLabel.setText(getDevice().meta().getString("units", "mbar"));
deviceNameLabel.setText(getDevice().getName()); deviceNameLabel.setText(getDevice().getName());
powerSwitch.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { bindBooleanToState("power", powerSwitch.selectedProperty());
getDevice().setState("power", Value.of(newValue));
});
} }
} }

View File

@ -10,7 +10,6 @@ import hep.dataforge.control.devices.Device;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.MeasurementListener; import hep.dataforge.control.measurements.MeasurementListener;
import hep.dataforge.control.measurements.Sensor; import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.values.Value;
import inr.numass.control.DeviceViewConnection; import inr.numass.control.DeviceViewConnection;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
@ -98,11 +97,6 @@ public class VacuumeterView extends DeviceViewConnection<Sensor<Double>> impleme
}); });
} }
@Override
public void notifyDeviceStateChanged(Device device, String name, Value state) {
}
@Override @Override
public void onMeasurementFailed(Measurement measurement, Throwable exception) { public void onMeasurementFailed(Measurement measurement, Throwable exception) {
Platform.runLater(() -> { Platform.runLater(() -> {

View File

@ -2,7 +2,7 @@
<config> <config>
<!--<storage path="D:/temp/test"/>--> <!--<storage path="D:/temp/test"/>-->
<device type="numass:vac"> <device type="numass:vac">
<sensor name="P1" color="red" port="com::/dev/ttyUSB0" sensorType="mks"/> <sensor name="P1" color="red" port="tcp::192.168.111.33:4002" sensorType="mks"/>
<sensor name="P2" color="blue" port="tcp::192.168.111.32:4002" sensorType="CM32"/> <sensor name="P2" color="blue" port="tcp::192.168.111.32:4002" sensorType="CM32"/>
<sensor name="P3" color="green" port="tcp::192.168.111.32:4003" sensorType="CM32"/> <sensor name="P3" color="green" port="tcp::192.168.111.32:4003" sensorType="CM32"/>
<sensor name="Px" color="black" port="tcp::192.168.111.33:4003" sensorType="meradat" address="1"/> <sensor name="Px" color="black" port="tcp::192.168.111.33:4003" sensorType="meradat" address="1"/>

View File

@ -37,7 +37,7 @@ public class TestServer {
NumassStorage storage = new NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true)); NumassStorage storage = new NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true));
serverManager.addObject("numass", storage, NumassStorageHandler::new); serverManager.addObject("numass", storage, NumassStorageHandler::new);
serverManager.startSetver(); serverManager.startServer();
String stopLine = ""; String stopLine = "";