diff --git a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaHub.kt b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaHub.kt index d6860251..8995dad7 100644 --- a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaHub.kt +++ b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaHub.kt @@ -12,14 +12,20 @@ import hep.dataforge.meta.Meta import hep.dataforge.names.Name import hep.dataforge.states.StateDef import hep.dataforge.values.ValueType +import inr.numass.control.DeviceDisplayFX +import inr.numass.control.DeviceView +import inr.numass.control.getDisplay +import javafx.scene.Parent +import tornadofx.* import java.util.* import java.util.stream.Stream import kotlin.collections.ArrayList @StateDef(value = ValueDef(name = "address", type = arrayOf(ValueType.NUMBER), info = "Current active magnet")) +@DeviceView(LambdaHubDisplay::class) class LambdaHub(context: Context, meta: Meta) : DeviceHub, AbstractDevice(context, meta) { - private val magnets = ArrayList(); + val magnets = ArrayList(); private val port: Port = buildPort() private val controller = LambdaPortController(context, port) @@ -60,4 +66,17 @@ class LambdaHub(context: Context, meta: Meta) : DeviceHub, AbstractDevice(contex override val deviceNames: Stream get() = magnets.stream().map { Name.ofSingle(it.name) } +} + +class LambdaHubDisplay: DeviceDisplayFX() { + override fun buildView(device: LambdaHub): UIComponent? { + return object: View() { + override val root: Parent = vbox { + device.magnets.forEach { + this.add(it.getDisplay().view!!) + } + } + + } + } } \ No newline at end of file diff --git a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt index 6b2c10c2..151f34e2 100644 --- a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt +++ b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt @@ -29,6 +29,8 @@ import hep.dataforge.states.StateDefs import hep.dataforge.states.valueState import hep.dataforge.utils.DateTimeUtils import hep.dataforge.values.ValueType.* +import inr.numass.control.DeviceView +import inr.numass.control.magnet.fx.MagnetDisplay import kotlinx.coroutines.experimental.runBlocking import java.time.Instant import java.time.temporal.ChronoUnit @@ -50,8 +52,9 @@ import java.util.concurrent.TimeUnit StateDef(value = ValueDef(name = "updating", type = arrayOf(BOOLEAN), def = "false", info = "Shows if current ramping in progress"), writable = true), StateDef(value = ValueDef(name = "monitoring", type = arrayOf(BOOLEAN), def = "false", info = "Shows if monitoring task is running"), writable = true), StateDef(value = ValueDef(name = "speed", type = arrayOf(NUMBER), info = "Current change speed in Ampere per minute"), writable = true), - StateDef(ValueDef(name = "state", type = [STRING], def = "INIT", enumeration = LambdaMagnet.MagnetState::class, info = "Current state of magnet operation")) + StateDef(ValueDef(name = "status", type = [STRING], def = "INIT", enumeration = LambdaMagnet.MagnetStatus::class, info = "Current state of magnet operation")) ) +@DeviceView(MagnetDisplay::class) class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : AbstractDevice(controller.context, meta) { private var closePortOnShutDown = false @@ -100,7 +103,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A val output = valueState("output", getter = { controller.talk(address, "OUT?") == "OK" }) { _, value -> setOutputMode(value.booleanValue()) if (!value.booleanValue()) { - state = MagnetState.OFF + status = MagnetStatus.OFF } } @@ -134,7 +137,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A var speed by valueState("speed").doubleDelegate - var state by valueState("state").enumDelegate() + var status by valueState("status").enumDelegate() private set /** @@ -211,9 +214,9 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A val nextI = nextI(measuredI, targetI) if (bound(nextI)) { outCurrent = nextI - state = MagnetState.OK + status = MagnetStatus.OK } else { - state = MagnetState.BOUND + status = MagnetStatus.BOUND } } else { stopUpdateTask() @@ -313,7 +316,7 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A controller.bound = { i -> Math.abs(this.current.doubleValue - i) <= difference } } - enum class MagnetState { + enum class MagnetStatus { INIT, // no information OFF, // Magnet output is off OK, // Magnet ouput is on diff --git a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/fx/MagnetDisplay.kt b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/fx/MagnetDisplay.kt index efa2c59e..2c8c97f7 100644 --- a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/fx/MagnetDisplay.kt +++ b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/fx/MagnetDisplay.kt @@ -20,13 +20,10 @@ import inr.numass.control.DeviceDisplayFX import inr.numass.control.magnet.LambdaMagnet import javafx.application.Platform import javafx.beans.value.ObservableValue -import javafx.fxml.Initializable import javafx.scene.control.* import javafx.scene.layout.AnchorPane import javafx.scene.paint.Color import tornadofx.* -import java.net.URL -import java.util.* /** * FXML Controller class @@ -38,42 +35,34 @@ class MagnetDisplay : DeviceDisplayFX() { return MagnetControllerComponent(device) } - val current by lazy { valueBinding(device.voltage) } - val voltage by lazy { valueBinding(device.current) } - - var target by device.target.doubleDelegate - - var output by device.output.booleanDelegate - - var monitoring by device.monitoring.booleanDelegate - - var updating by device.updating.booleanDelegate - - - inner class MagnetControllerComponent(val device: LambdaMagnet) : Fragment(), Initializable { + inner class MagnetControllerComponent(val device: LambdaMagnet) : Fragment() { override val root: AnchorPane by fxml("/fxml/SingleMagnet.fxml") - private var showConfirmation = true + var showConfirmation = true - val labelI: Label by fxml() - val labelU: Label by fxml() - val targetIField: TextField by fxml() - val magnetName: Label by fxml() - val monitorButton: ToggleButton by fxml() - val statusLabel: Label by fxml() - val setButton: ToggleButton by fxml() - val magnetSpeedField: TextField by fxml() - /** - * Initializes the controller class. - * - * @param url - * @param rb - */ - override fun initialize(url: URL, rb: ResourceBundle) { + val current = valueBinding(device.voltage) + val voltage = valueBinding(device.current) + var target by device.target.doubleDelegate + var output by device.output.booleanDelegate + var monitoring by device.monitoring.booleanDelegate + var updating by device.updating.booleanDelegate + //TODO add status + + val labelI: Label by fxid() + val labelU: Label by fxid() + val targetIField: TextField by fxid() + val magnetName: Label by fxid() + val monitorButton: ToggleButton by fxid() + val statusLabel: Label by fxid() + val setButton: ToggleButton by fxid() + val magnetSpeedField: TextField by fxid() + + + init{ targetIField.textProperty().addListener { observable: ObservableValue, oldValue: String, newValue: String -> if (!newValue.matches("\\d*(\\.)?\\d*".toRegex())) { targetIField.text = oldValue @@ -129,7 +118,7 @@ class MagnetDisplay : DeviceDisplayFX() { setButton.selectedProperty().onChange { try { - setOutput(it) + setOutputOn(it) } catch (ex: PortException) { displayError(this.device.name, null, ex) } @@ -145,12 +134,10 @@ class MagnetDisplay : DeviceDisplayFX() { } } - fun setShowConfirmation(showConfirmation: Boolean) { - this.showConfirmation = showConfirmation - } + @Throws(PortException::class) - private fun setOutput(outputOn: Boolean) { + private fun setOutputOn(outputOn: Boolean) { if (outputOn) { if (showConfirmation) { val alert = Alert(Alert.AlertType.WARNING) diff --git a/numass-control/magnet/src/main/resources/fxml/SingleMagnet.fxml b/numass-control/magnet/src/main/resources/fxml/SingleMagnet.fxml index 965ba23a..c6febe53 100644 --- a/numass-control/magnet/src/main/resources/fxml/SingleMagnet.fxml +++ b/numass-control/magnet/src/main/resources/fxml/SingleMagnet.fxml @@ -16,110 +16,98 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + diff --git a/numass-control/src/main/kotlin/inr/numass/control/NumassControlApplication.kt b/numass-control/src/main/kotlin/inr/numass/control/NumassControlApplication.kt index c1dd50aa..72fd3ff3 100644 --- a/numass-control/src/main/kotlin/inr/numass/control/NumassControlApplication.kt +++ b/numass-control/src/main/kotlin/inr/numass/control/NumassControlApplication.kt @@ -72,6 +72,7 @@ abstract class NumassControlApplication : App() { try { device?.shutdown() } catch (ex: Exception) { + device?.context?.close() LoggerFactory.getLogger(javaClass).error("Failed to shutdown application", ex); } finally { super.stop() diff --git a/numass-control/src/main/kotlin/inr/numass/control/NumassControlUtils.kt b/numass-control/src/main/kotlin/inr/numass/control/NumassControlUtils.kt index 9dcb3591..ae4cfb00 100644 --- a/numass-control/src/main/kotlin/inr/numass/control/NumassControlUtils.kt +++ b/numass-control/src/main/kotlin/inr/numass/control/NumassControlUtils.kt @@ -22,7 +22,7 @@ import java.nio.file.Paths /** * Created by darksnake on 08-May-17. */ -val DEFAULT_CONFIG_LOCATION = "./numass-control.xml" +const val DEFAULT_CONFIG_LOCATION = "./numass-control.xml" //val STORING_STATE = "storing" //val dfIcon: Image = Image(Global::class.java.getResourceAsStream("/img/df.png"))