From 3773bb98b31cb9516e2b3a1fb2cb416cf35ab08d Mon Sep 17 00:00:00 2001 From: l_samenv Date: Fri, 15 Sep 2023 10:37:13 +0200 Subject: [PATCH] fix autofill with extrnal level meter when no value is available, filling must be inhibited. this patch checks whether a value newer than 30 sec is available --- tcl/17tf.config | 2 +- tcl/drivers/ccu4ext.tcl | 66 +++++++++++++++++++++++++++++----------- tcl/startup/autofill.tcl | 4 +-- 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/tcl/17tf.config b/tcl/17tf.config index 195505e..8dde30d 100644 --- a/tcl/17tf.config +++ b/tcl/17tf.config @@ -28,7 +28,7 @@ GraphAdd 17tf.nlevel % N2_lev black #makeCCU4 blank nv #GraphAdd nv.flow mbar nv_flow red -makenv ln2fill -driver ccu4ext n2 "17tf nlevel" +makenv ln2fill -driver ccu4ext n2 /17tf/nlevel #make17tfNv diff --git a/tcl/drivers/ccu4ext.tcl b/tcl/drivers/ccu4ext.tcl index 4292795..c3b15d9 100644 --- a/tcl/drivers/ccu4ext.tcl +++ b/tcl/drivers/ccu4ext.tcl @@ -3,7 +3,7 @@ namespace eval ccu4ext { } # automatic fill with level reading from external source -proc stdConfig::ccu4ext {type {readlevel 0}} { +proc stdConfig::ccu4ext {type {readpath 0}} { variable node variable ctrl @@ -27,13 +27,14 @@ proc stdConfig::ccu4ext {type {readlevel 0}} { node state upd -text - node readlevel -text par $readlevel + node readpath -text par $readpath prop visible false node lowlevel par 10 node highlevel par 100 node smooth upd prop fmt %.7g + prop geterror undefined default -1 node minfillminutes par 3.0 @@ -89,7 +90,7 @@ proc ccu4ext::changestate {type state} { proc ccu4ext::calcsmooth {level minspeed maxspeed} { if {![string is double $level]} { - return 999.9 + return 199 } set now [clock seconds] set lasttime [silent 0 sct lasttime] @@ -98,10 +99,7 @@ proc ccu4ext::calcsmooth {level minspeed maxspeed} { } set delta [expr $now - $lasttime] sct lasttime $now - set smooth [hvali [sct]/smooth] - if {$smooth < 0} { - set smooth $level - } + set smooth [silent $level hvali [sct]/smooth] set gs [expr $smooth + $delta * $maxspeed] if {$level > $gs} { set smooth $gs @@ -126,6 +124,7 @@ proc ccu4ext::calcsmooth {level minspeed maxspeed} { } } hupdate [sct]/smooth $smooth + hdelprop [sct]/smooth geterror return $smooth } @@ -148,7 +147,8 @@ proc ccu4ext::fillExt {type} { } } set errtxt "" - set sm [expr [DoubleTime] > [silent 0 sct change_time] + 10] + set now [DoubleTime] + set sm [expr $now > [silent 0 sct change_time] + 10] switch -- $valve { 0 { set txt "fill valve off" @@ -178,6 +178,12 @@ proc ccu4ext::fillExt {type} { set errtxt "unknown error" } } + set rdpath [hvali [sct]/readpath] + set level [hvali $rdpath] + set levelerror [silent "" hgetpropval $rdpath geterror] + if {$levelerror ne "" && $errtxt eq ""} { + set errtxt "$txt ($rdpath $levelerror)" + } if {$errtxt eq ""} { updateval [sct]/state $txt hupdate [sct]/status "" @@ -189,11 +195,6 @@ proc ccu4ext::fillExt {type} { changestate $type fill return idle } - set level [silent invalid result [hvali [sct]/readlevel]] - if {! [string is double $level]} { - hsetprop [sct]/readlevel geterror "illegal $type level reading" - return idle - } set state [sctval [sct]] set now [clock seconds] set lowlevel [hvali [sct]/lowlevel] @@ -219,6 +220,7 @@ proc ccu4ext::fillExt {type} { return idle } 0 { # watching + validated_level set minspeed [expr - 100.0 / [hvali [sct]/minholdhours] / 3600.] set maxspeed [expr - 100.0 / [hvali [sct]/maxholdhours] / 3600.] set s [calcsmooth $level $minspeed $maxspeed] @@ -231,13 +233,18 @@ proc ccu4ext::fillExt {type} { } # start fill hset [sct] 1 - clientput "$type level low - start fill" + clientput "$type level low ($level smooth $s) - start fill" } else { changestate $type stop } return idle } - 1 { + 1 { # filling + if {[validated_level] eq ""} { + hset [sct] 2 + changestate $type off + return idle + } set vcmd [silent 0 sct vessel_cmd] # check that vessel command works if {$vcmd ne "0" && [catch {[result $vcmd]}]} { @@ -246,7 +253,7 @@ proc ccu4ext::fillExt {type} { set vmd 0 } set now [clock seconds] - set s [hvali [sct]/smooth] + set s [silent $level hval [sct]/smooth] sct minlevel [silent 999 sct minlevel] if {$s < [sct minlevel]} { sct minlevel $s @@ -321,12 +328,30 @@ proc ccu4ext::fillExt {type} { return idle } +proc ccu4ext::validated_level {} { + set rdpath [hval [sct]/readpath] + if {[DoubleTime] < [silent 0 hgetpropval $rdpath read_time] + 30} { + return [hval $rdpath] + } + if {[silent "" hgetpropval $rdpath geterror] eq ""} { + clientlog "ERROR: no reading of $rdpath within 30 sec" + } + hsetprop $rdpath geterror not_available + return "" +} + proc ccu4ext::writeExt {type {activate 1}} { sct update [sct target] - hupdate [sct]/smooth [silent 0 result [hvali [sct]/readlevel]] switch -- [sct target] { # watching 0 { + set level [validated_level] + if {$level eq ""} { + changestate $type off + sct update 2 + return idle + } + hupdate [sct]/smooth $level catch {logsetup [sct]/vext clear} hupdate [sct]/status "" eval [silent "expr 0" sct slow_cmd] @@ -350,6 +375,13 @@ proc ccu4ext::writeExt {type {activate 1}} { } # fill 1 { + set level [validated_level] + if {$level eq ""} { + changestate $type off + sct update 2 + return idle + } + hupdate [sct]/smooth $level hupdate [sct]/status "" set vcmd [silent 0 sct vessel_cmd] if {$vcmd ne "0"} { diff --git a/tcl/startup/autofill.tcl b/tcl/startup/autofill.tcl index ebb203a..6cbbf6c 100644 --- a/tcl/startup/autofill.tcl +++ b/tcl/startup/autofill.tcl @@ -19,7 +19,7 @@ proc makeHeFill {levcmd} { if {$levcmd eq "ccu"} { makenv hefill he_ext_ccu ccu } elseif {$levcmd eq "ccu4ilm"} { - makenv hefill -driver ccu4ext he lev + makenv hefill -driver ccu4ext he /lev lappend fast_cmd {lev mode 1} lappend slow_cmd {lev mode 0} } else { @@ -90,7 +90,7 @@ proc makeN2Fill {{option ccu} {code 0}} { GraphAdd n2.upper K_2 N2_Upper red GraphAdd n2.lower K_2 N2_Lower green } elseif {$option eq "ccu4ilm"} { - makenv ln2fill -driver ccu4ext n2 "lev n2" + makenv ln2fill -driver ccu4ext n2 /lev/n2 GraphAdd lev.n2 % "N2_level" black if {! $c} { # switch silently to inactive