Adding Gun device to numass

This commit is contained in:
Alexander Nozik 2018-11-29 16:04:09 +03:00
parent 669766e816
commit aab01f964f
7 changed files with 71 additions and 10 deletions

View File

@ -19,7 +19,7 @@ apply plugin: 'application'
version = "0.1.0"
if (!hasProperty('mainClass')) {
ext.mainClass = 'inr.numass.control.gun.EGunApplicationkt'
ext.mainClass = 'inr.numass.control.gun.EGunApplication'
}
mainClassName = mainClass

View File

@ -25,8 +25,10 @@ import hep.dataforge.meta.Meta
import hep.dataforge.meta.Metoid
import hep.dataforge.names.Name
import hep.dataforge.optional
import inr.numass.control.DeviceView
import java.util.*
@DeviceView(GunDisplay::class)
class EGun(context: Context, meta: Meta) : AbstractDevice(context, meta), DeviceHub, ContextAware, Metoid {
val sources: List<IT6800Device> by lazy {
meta.getMetaList("source").map {IT6800Device(context, it) }
@ -37,4 +39,14 @@ class EGun(context: Context, meta: Meta) : AbstractDevice(context, meta), Device
override fun optDevice(name: Name): Optional<Device> {
return sources.find { it.name == name.toString() }.optional
}
override fun init() {
super.init()
sources.forEach { it.init() }
}
override fun shutdown() {
sources.forEach { it.shutdown() }
super.shutdown()
}
}

View File

@ -38,6 +38,6 @@ class EGunApplication: NumassControlApplication<EGun>() {
}
override fun getDeviceMeta(config: Meta): Meta {
return MetaUtils.findNode(config,"device"){it.getString("name") == "numass.gun"}.orElseThrow{RuntimeException("Gun configuration not found")}
return MetaUtils.findNode(config,"device"){it.getString("type") == "numass.gun"}.orElseThrow{RuntimeException("Gun configuration not found")}
}
}

View File

@ -16,19 +16,58 @@
package inr.numass.control.gun
import hep.dataforge.fx.asBooleanProperty
import hep.dataforge.fx.asDoubleProperty
import inr.numass.control.DeviceDisplayFX
import inr.numass.control.indicator
import javafx.geometry.Orientation
import tornadofx.*
class EGunView(gun: EGun) : View() {
class GunDisplay: DeviceDisplayFX<EGun>(){
override fun buildView(device: EGun): UIComponent? {
return EGunView(device)
}
}
class EGunView(val gun: EGun) : View() {
override val root = borderpane {
top{
buttonbar {
button("refresh"){
action {
gun.sources.forEach {
it.update()
}
}
}
}
}
center {
vbox {
gun.sources.forEach { device ->
gun.sources.forEach { source ->
hbox {
label(device.name)
slider(range = 0.0..5.0, value = 0){
valueProperty().bindBidirectional(device.currentState.asDoubleProperty())
label(source.name)
separator(Orientation.VERTICAL)
indicator {
bind(source.connected.asBooleanProperty())
}
val voltageProperty = source.voltageState.asDoubleProperty()
val currentProperty = source.currentState.asDoubleProperty()
textfield {
}
separator(Orientation.VERTICAL)
label("V: ")
label(voltageProperty)
separator(Orientation.VERTICAL)
label("I: ")
label(currentProperty)
}
}
}

View File

@ -38,7 +38,7 @@ class IT6800Device(context: Context, meta: Meta) : AbstractDevice(context, meta)
private var monitorJob: Job? = null
val connected get() = portHelper.connected
val connected get() = portHelper.connectedState
val address: Byte = meta.getValue("address", 0).number.toByte()

View File

@ -0,0 +1,9 @@
<config>
<device type="numass.gun">
<source name="bending" port="tcp::192.168.111.34:4001" />
<source name="focus" port="tcp::192.168.111.34:4002" />
<source name="transport.1" port="tcp::192.168.111.34:4003" />
<source name="transport.2" port="tcp::192.168.111.34:4004" />
<source name="transport.middle" port="tcp::192.168.111.34:4005" />
</device>
</config>

View File

@ -24,6 +24,7 @@ import hep.dataforge.values.Value
import hep.dataforge.values.ValueMap
import hep.dataforge.values.Values
import hep.dataforge.values.asValue
import java.lang.Math.sqrt
import java.util.*
import java.util.stream.Stream
@ -83,8 +84,8 @@ class SpectrumAdapter : BasicAdapter {
when {
y < 0 -> Optional.empty()
y == 0.0 -> //avoid infinite weights
Optional.of(Value.of(1.0 / getTime(values)))
else -> Optional.of(Value.of(Math.sqrt(y / getTime(values))))
Optional.of(Value.of(1.0 / sqrt(getTime(values))))
else -> Optional.of(Value.of(sqrt(y / getTime(values))))
}
}
}