diff --git a/build.gradle b/build.gradle index 02790dcf..effdee77 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "org.jetbrains.kotlin.jvm" version "1.1.51" apply false + id "org.jetbrains.kotlin.jvm" version "1.1.60" apply false } allprojects{ diff --git a/numass-control/build.gradle b/numass-control/build.gradle index 3478e86f..f0dfac84 100644 --- a/numass-control/build.gradle +++ b/numass-control/build.gradle @@ -1,15 +1,3 @@ -buildscript { - ext.kotlin_version = '1.1.51' - - repositories { - mavenCentral() - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects{ apply plugin: "kotlin" diff --git a/numass-control/control-room/build.gradle b/numass-control/control-room/build.gradle index 24d047b4..5b47f69e 100644 --- a/numass-control/control-room/build.gradle +++ b/numass-control/control-room/build.gradle @@ -1,6 +1,6 @@ -plugins{ +plugins { id "application" - id 'com.github.johnrengelman.shadow' version '2.0.0' + id 'com.github.johnrengelman.shadow' version '2.0.1' } @@ -16,7 +16,7 @@ description = "The control room application for numass slow control" compileKotlin.kotlinOptions.jvmTarget = "1.8" -configurations{ +configurations { devices.extendsFrom(compile) } @@ -31,34 +31,34 @@ dependencies { devices project(':numass-control:vac') } -shadowJar{ +shadowJar { mergeServiceFiles() } task debugWithDevice(dependsOn: classes, type: JavaExec) { main mainClass - args "--config.resource=/config/server.xml" - classpath = sourceSets.main.runtimeClasspath + configurations.devices + args = ["--config.resource=/config/control.xml"] + classpath = sourceSets.main.runtimeClasspath + configurations.devices description "Start application in debug mode" group "debug" } -task startScriptWithDevices(type: CreateStartScripts){ +task startScriptWithDevices(type: CreateStartScripts) { applicationName = "control-room-devices" mainClassName = mainClass outputDir = new File(project.buildDir, 'scripts') classpath = jar.outputs.files + project.configurations.devices } -distributions{ - devices{ +distributions { + devices { contents { into("lib") { from jar from configurations.devices } - into("bin"){ + into("bin") { from startScriptWithDevices } } diff --git a/numass-control/cryotemp/build.gradle b/numass-control/cryotemp/build.gradle index f62ff8a7..f6f110c7 100644 --- a/numass-control/cryotemp/build.gradle +++ b/numass-control/cryotemp/build.gradle @@ -23,7 +23,7 @@ task testDevice(dependsOn: classes, type: JavaExec) { group "test" } buildscript { - ext.kotlin_version = '1.1.51' + ext.kotlin_version = '1.1.60' repositories { mavenCentral() } diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt index c7040581..1396a919 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt @@ -154,11 +154,9 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, @Throws(ControlException::class) override fun shutdown() { - storageHelper!!.close() - if (collector != null) { - collector!!.stop() - collector = null - } + storageHelper?.close() + collector?.stop() + collector = null super.shutdown() } @@ -299,11 +297,9 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, } - inner class PKT8Measurement(internal val handler: PortHandler) : AbstractMeasurement(), PortHandler.PortController { + inner class PKT8Measurement(private val handler: PortHandler) : AbstractMeasurement(), PortHandler.PortController { - override fun getDevice(): Device { - return this@PKT8Device - } + override fun getDevice(): Device = this@PKT8Device override fun start() { if (isStarted) { @@ -327,14 +323,14 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, logger.warn("Trying to stop measurement which is already stopped") } - try { + return try { logger.info("Stopping measurement") val response = sendAndWait("p", TIMEOUT).trim { it <= ' ' } // Должно быть именно с большой буквы!!! - return "Stopped" == response || "stopped" == response + "Stopped" == response || "stopped" == response } catch (ex: Exception) { error(ex) - return false + false } finally { if (collector != null) { collector!!.clear() @@ -384,8 +380,4 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, private val CHANNEL_DESIGNATIONS = arrayOf("a", "b", "c", "d", "e", "f", "g", "h") } - init { - setContext(context) - setMeta(meta) - } } \ No newline at end of file diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt index a8990ab4..0698483d 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt @@ -10,7 +10,6 @@ import hep.dataforge.meta.Meta import hep.dataforge.plots.PlotFrame import hep.dataforge.plots.PlotUtils import hep.dataforge.plots.data.TimePlot -import hep.dataforge.plots.data.TimePlottableGroup import hep.dataforge.plots.jfreechart.JFreeChartFrame import inr.numass.control.DeviceDisplay import javafx.application.Platform @@ -33,9 +32,7 @@ import java.time.Instant */ class PKT8Display : DeviceDisplay(), MeasurementListener { - override fun buildView(device: PKT8Device): View { - return CryoView() - } + override fun buildView(device: PKT8Device): View = CryoView() internal val table = FXCollections.observableHashMap() val lastUpdateProperty = SimpleObjectProperty("NEVER") @@ -146,9 +143,9 @@ class PKT8Display : DeviceDisplay(), MeasurementListener { } } - var rawDataButton: ToggleButton by singleAssign() + private val plottables = plotFrame.plots - val plottables: TimePlottableGroup = TimePlottableGroup() + var rawDataButton: ToggleButton by singleAssign() override val root: Parent = borderpane { prefWidth = 800.0 @@ -187,16 +184,16 @@ class PKT8Display : DeviceDisplay(), MeasurementListener { } if (device.meta().hasMeta("plotConfig")) { plottables.configure(device.meta().getMeta("plotConfig")) - plottables.setMaxItems(1000) - plottables.setPrefItems(400) + TimePlot.setMaxItems(plottables, 1000) + TimePlot.setPrefItems(plottables, 400) } table.addListener(MapChangeListener { change -> if (change.wasAdded()) { change.valueAdded.apply { - if (rawDataButton.isSelected()) { - plottables.put(this.channel, this.rawValue) + if (rawDataButton.isSelected) { + plottables.opt(channel).ifPresent { TimePlot.put(it, rawValue) } } else { - plottables.put(this.channel, this.temperature) + plottables.opt(channel).ifPresent { TimePlot.put(it, temperature) } } } } @@ -204,9 +201,7 @@ class PKT8Display : DeviceDisplay(), MeasurementListener { } fun clearPlot() { - plottables.forEach { - it.clear() - } + plottables.clear() } } } diff --git a/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt b/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt index 854209b9..f9daac48 100644 --- a/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt +++ b/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt @@ -31,7 +31,7 @@ annotation class DeviceView(val value: KClass>) * Get existing view connection or create a new one */ fun Device.getDisplay(): DeviceDisplay<*> { - val type = DefaultDisplay::class; + val type = (this::class.annotations.find { it is DeviceView } as DeviceView?)?.value ?: DefaultDisplay::class return optConnection(Roles.VIEW_ROLE, DeviceDisplay::class.java).orElseGet { type.createInstance().also { connect(it, Roles.VIEW_ROLE, Roles.DEVICE_LISTENER_ROLE); @@ -57,9 +57,7 @@ abstract class DeviceDisplay : Component(), Connection, DeviceListen buildView(device) } - override fun isOpen(): Boolean { - return this.deviceProperty.get() != null - } + override fun isOpen(): Boolean = this.deviceProperty.get() != null override fun open(obj: Any) { if (!isOpen) { @@ -121,6 +119,9 @@ abstract class DeviceDisplay : Component(), Connection, DeviceListen property.addListener { observable, oldValue, newValue -> if (isOpen && oldValue != newValue) { runAsync { + if(!device.isInitialized){ + device.init() + } device.setState(state, newValue).get().booleanValue(); } ui { property.set(it) @@ -160,8 +161,6 @@ abstract class DeviceDisplay : Component(), Connection, DeviceListen * Default display shows only board pane and nothing else */ class DefaultDisplay() : DeviceDisplay() { - override fun buildView(device: Device): UIComponent? { - return null; - } + override fun buildView(device: Device): UIComponent? = null }