Intermediate commit for devices update

This commit is contained in:
Alexander Nozik 2017-11-14 21:14:15 +03:00
parent 1b76b42d55
commit 1f5b7ea58a
7 changed files with 35 additions and 61 deletions

View File

@ -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{

View File

@ -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"

View File

@ -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
}
}

View File

@ -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()
}

View File

@ -154,11 +154,9 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(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<PKT8Result>(context,
}
inner class PKT8Measurement(internal val handler: PortHandler) : AbstractMeasurement<PKT8Result>(), PortHandler.PortController {
inner class PKT8Measurement(private val handler: PortHandler) : AbstractMeasurement<PKT8Result>(), 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<PKT8Result>(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<PKT8Result>(context,
private val CHANNEL_DESIGNATIONS = arrayOf("a", "b", "c", "d", "e", "f", "g", "h")
}
init {
setContext(context)
setMeta(meta)
}
}

View File

@ -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<PKT8Device>(), MeasurementListener {
override fun buildView(device: PKT8Device): View {
return CryoView()
}
override fun buildView(device: PKT8Device): View = CryoView()
internal val table = FXCollections.observableHashMap<String, PKT8Result>()
val lastUpdateProperty = SimpleObjectProperty<String>("NEVER")
@ -146,9 +143,9 @@ class PKT8Display : DeviceDisplay<PKT8Device>(), 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<PKT8Device>(), 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<PKT8Device>(), MeasurementListener {
}
fun clearPlot() {
plottables.forEach {
it.clear()
}
plottables.clear()
}
}
}

View File

@ -31,7 +31,7 @@ annotation class DeviceView(val value: KClass<out DeviceDisplay<*>>)
* 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<D : Device> : 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<D : Device> : 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<D : Device> : Component(), Connection, DeviceListen
* Default display shows only board pane and nothing else
*/
class DefaultDisplay() : DeviceDisplay<Device>() {
override fun buildView(device: Device): UIComponent? {
return null;
}
override fun buildView(device: Device): UIComponent? = null
}