New sicsconfig.ini file configuration editor.

Updated wombat sics_config.ini and gen_sct.py
Generated new tcl files from sct templates and
modified some old sct_*.tcl drivers.

TODO
sct_keithley_2700.tcl
magneticField/sct_oxford_labview.tcl
magneticField/sct_bruker_BEC1.tcl
temperature/sct_watlow_st4.tcl
temperature/sct_oxford_mercury.tcl
temperature/sct_mercury_pres.tcl
temperature/sct_julabo_lh45.tcl
temperature/sct_lakeshore_340.tcl
temperature/sct_julabo_lh45_gen.tcl
temperature/sct_watlow_rm.tcl
temperature/sct_eurotherm_2000.tcl
temperature/sct_lakeshore_336.tcl
temperature/sct_watlow_pm.tcl
temperature/sct_oxford_itc.tcl
temperature/sct_lakeshore_370.tcl
temperature/west400.tcl
This commit is contained in:
Ferdi Franceschini
2014-06-30 09:08:19 +10:00
parent c960a3bb2d
commit e971cd8b64
25 changed files with 782 additions and 344 deletions

View File

@ -568,10 +568,13 @@ proc ::scobj::astrium_chopper::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::astrium_chopper" set ns "::scobj::astrium_chopper"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "astrium_chopper" } { if { [dict get $v "driver"] == "astrium_chopper" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [chopper_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [chopper_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[chopper_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[chopper_simulation] => using null asyncqueue"

View File

@ -306,10 +306,13 @@ proc ::scobj::shutters::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::shutters" set ns "::scobj::shutters"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "shutters" } { if { [dict get $v "driver"] == "shutters" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [motor_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [motor_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[motor_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[motor_simulation] => using null asyncqueue"

View File

@ -341,10 +341,13 @@ proc ::scobj::tank::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::tank" set ns "::scobj::tank"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "tank" } { if { [dict get $v "driver"] == "tank" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [motor_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [motor_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[motor_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[motor_simulation] => using null asyncqueue"

View File

@ -495,7 +495,7 @@ publish OxfordSetHTemp user
publish OxfordSetDTemp user publish OxfordSetDTemp user
publish OxfordSetHS user publish OxfordSetHS user
proc add_oxmag { name IP PORT {interval 5} } { proc add_oxford_labview { name IP PORT {interval 5} } {
::scobj::magnetic::mkMagnetic [subst { ::scobj::magnetic::mkMagnetic [subst {
name $name name $name
IP $IP IP $IP
@ -504,11 +504,83 @@ proc add_oxmag { name IP PORT {interval 5} } {
interval $interval interval $interval
}] }]
} }
# NEW START
if { [ info exists ::config_dict ] && [ dict get $::config_dict 12tmagnet enabled ] } { namespace eval ::scobj::oxford_labview {
set IP [dict get $::config_dict 12tmagnet ip] set debug_threshold 5
set PORT [dict get $::config_dict 12tmagnet port]
set NAME [dict get $::config_dict 12tmagnet name]
puts "MAGNET: add_oxmag $NAME $IP $PORT"
add_oxmag $NAME $IP $PORT
} }
proc ::scobj::oxford_labview::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::oxford_labview::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::oxford_labview::${debug_string}"
}
} catch_message ]
}
proc ::scobj::oxford_labview::read_config {} {
set catch_status [ catch {
set ns "::scobj::oxford_labview"
dict for {k v} $::config_dict {
if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "oxford_labview" } {
if { $enabled == "true" || $enabled == "always" } {
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"
} elseif { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set IP [dict get $v ip]
set PORT [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
set arg_list [list]
foreach arg {interval} {
if {[dict exists $v $arg]} {
lappend arg_list "[dict get $v $arg]"
} else {
${ns}::sics_log 9 "Missing configuration value $arg"
error "Missing configuration value $arg"
}
}
add_oxford_labview ${name} "aqadapter" ${asyncqueue} {*}$arg_list
}
}
}
}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::oxford_labview::read_config
} else {
::scobj::oxford_labview::sics_log 5 "No config dict"
}
# NEW END
#OLD START
# if { [ info exists ::config_dict ] && [ dict get $::config_dict 12tmagnet enabled ] } {
# set IP [dict get $::config_dict 12tmagnet ip]
# set PORT [dict get $::config_dict 12tmagnet port]
# set NAME [dict get $::config_dict 12tmagnet name]
# puts "MAGNET: add_oxmag $NAME $IP $PORT"
# add_oxmag $NAME $IP $PORT
# }
#OLD END

View File

@ -1155,10 +1155,13 @@ proc ::scobj::hiden_xcs::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::hiden_xcs" set ns "::scobj::hiden_xcs"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "hiden_xcs" } { if { [dict get $v "driver"] == "hiden_xcs" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -459,10 +459,13 @@ proc ::scobj::huber_pilot::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::huber_pilot" set ns "::scobj::huber_pilot"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "huber_pilot" } { if { [dict get $v "driver"] == "huber_pilot" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -346,10 +346,13 @@ proc ::scobj::isotech_ps::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::isotech_ps" set ns "::scobj::isotech_ps"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "isotech_ps" } { if { [dict get $v "driver"] == "isotech_ps" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -706,10 +706,13 @@ proc ::scobj::nhq_200::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::nhq_200" set ns "::scobj::nhq_200"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "nhq_200" } { if { [dict get $v "driver"] == "nhq_200" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -273,10 +273,13 @@ proc ::scobj::omron_hldc::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::omron_hldc" set ns "::scobj::omron_hldc"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "omron_hldc" } { if { [dict get $v "driver"] == "omron_hldc" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -339,10 +339,13 @@ proc ::scobj::lakeshore_218::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::lakeshore_218" set ns "::scobj::lakeshore_218"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "lakeshore_218" } { if { [dict get $v "driver"] == "lakeshore_218" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -1886,7 +1886,7 @@ proc createNode {scobj_hpath sct_controller cmdGroup varName readable writable p
# @param port port number on the moxabox (typ. 4001, 4002, 4003, or 4004) # @param port port number on the moxabox (typ. 4001, 4002, 4003, or 4004)
# @param tol temperature tolerance in Kelvin (typ. 1) # @param tol temperature tolerance in Kelvin (typ. 1)
# @return nothing (well, the sct object) # @return nothing (well, the sct object)
proc add_sct_ls336 {name IP port terminator {_tol1 1.0} {_tol2 1.0} {CID 1} {CTYPE T} {_verbose 0} } { proc add_lakeshore_336 {name IP port {terminator \r\n} {_tol1 1.0} {_tol2 1.0} {CID 1} {CTYPE T} {_verbose 0} } {
# ffr 2009-11-09, Don't create a temperature controller for the script validator, this causes the # ffr 2009-11-09, Don't create a temperature controller for the script validator, this causes the
# lakeshore to lock up. # lakeshore to lock up.
# NOTE: I put this outside the catch block because "return" raises an exception # NOTE: I put this outside the catch block because "return" raises an exception
@ -1896,10 +1896,10 @@ proc add_sct_ls336 {name IP port terminator {_tol1 1.0} {_tol2 1.0} {CID 1} {CTY
if {[ catch { if {[ catch {
if {[string equal -nocase "aqadapter" "${IP}"]} { if {[string equal -nocase "aqadapter" "${IP}"]} {
# dcl 2013-05-27: in this case the port is the name of the AsyncQueue # dcl 2013-05-27: in this case the port is the name of the AsyncQueue
puts "\nadd_ls336: makesctcontroller sct_ls336_$name aqadapter ${port} for Lakeshore model 336" puts "\add_lakeshore_336: makesctcontroller sct_ls336_$name aqadapter ${port} for Lakeshore model 336"
makesctcontroller sct_ls336_$name aqadapter ${port} makesctcontroller sct_ls336_$name aqadapter ${port}
} else { } else {
puts "\nadd_ls336: makesctcontroller sct_ls336_$name std ${IP}:$port $terminator for Lakeshore model 336" puts "\add_lakeshore_336: makesctcontroller sct_ls336_$name std ${IP}:$port $terminator for Lakeshore model 336"
makesctcontroller sct_ls336_$name std ${IP}:$port $terminator makesctcontroller sct_ls336_$name std ${IP}:$port $terminator
} }
::scobj::ls336::mk_sct_lakeshore_336 sct_ls336_$name environment $name $CID $CTYPE $_tol1 $_tol2 $_verbose ::scobj::ls336::mk_sct_lakeshore_336 sct_ls336_$name environment $name $CID $CTYPE $_tol1 $_tol2 $_verbose
@ -1911,26 +1911,77 @@ proc add_sct_ls336 {name IP port terminator {_tol1 1.0} {_tol2 1.0} {CID 1} {CTY
} }
} }
if {[ catch { namespace eval ::scobj::lakeshore_336 {
if { [ info exists ::config_dict ] } { set debug_threshold 5
dict for {secname secinfo} $::config_dict { }
if { [dict exists $secinfo "driver"] && ([dict get $secinfo "driver"] == "ls336") } { proc ::scobj::lakeshore_336::sics_log {debug_level debug_string} {
if { [ dict get $::secinfo enabled ] } { set catch_status [ catch {
set IP [dict get $::secinfo ip] set debug_threshold ${::scobj::lakeshore_336::debug_threshold}
set PORT [dict get $::secinfo port] if {${debug_level} >= ${debug_threshold}} {
set name [dict get $::secinfo name] sicslog "::scobj::lakeshore_336::${debug_string}"
set ctype [dict get $::secinfo type] }
set cid [dict get $::secinfo id] } catch_message ]
set term [dict get $::secinfo terminator] }
set tol1 [dict get $::secinfo tol1] proc ::scobj::lakeshore_336::read_config {} {
set tol2 [dict get $::secinfo tol2] set catch_status [ catch {
set ns "::scobj::lakeshore_336"
add_sct_ls336 $name $IP $PORT $term $tol1 $tol2 $cid $ctype dict for {k v} $::config_dict {
if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "lakeshore_336" } {
if { $enabled == "true" || $enabled == "always" } {
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"
} elseif { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set IP [dict get $v ip]
set PORT [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
set arg_list [list]
foreach arg {tol1 tol2 id} {
if {[dict exists $v $arg]} {
lappend arg_list "[dict get $v $arg]"
} else {
${ns}::sics_log 9 "Missing configuration value $arg"
error "Missing configuration value $arg"
}
}
add_lakeshore_336 ${name} "aqadapter" ${asyncqueue} {*}$arg_list
}
} }
} }
} }
} } catch_message ]
} message ]} { handle_exception ${catch_status} ${catch_message}
puts "ERROR: $message"
} }
if { [info exists ::config_dict] } {
::scobj::lakeshore_336::read_config
} else {
::scobj::lakeshore_336::sics_log 5 "No config dict"
}
namespace import ::scobj::ls336::* namespace import ::scobj::ls336::*

View File

@ -2083,14 +2083,14 @@ proc createNode {scobj_hpath sct_controller cmdGroup varName readable writable p
# end of namespace mk_sct_lakeshore_340 # end of namespace mk_sct_lakeshore_340
## ##
# @brief add_ls340() adds a scriptcontext object for a Lakeshore 336 o 340 temperature controller # @brief add_lakeshore_340() adds a scriptcontext object for a Lakeshore 336 o 340 temperature controller
# and makes it available to SICServer # and makes it available to SICServer
# @param name short name for the temperature controller scriptcontext object (typ. tc1 or tc2) # @param name short name for the temperature controller scriptcontext object (typ. tc1 or tc2)
# @param IP IP address of the device (e.g. IP of moxabox that hooks up to the Lakeshore 340) # @param IP IP address of the device (e.g. IP of moxabox that hooks up to the Lakeshore 340)
# @param port port number on the moxabox (typ. 4001, 4002, 4003, or 4004) # @param port port number on the moxabox (typ. 4001, 4002, 4003, or 4004)
# @param tol temperature tolerance in Kelvin (typ. 1) # @param tol temperature tolerance in Kelvin (typ. 1)
# @return nothing (well, the sct object) # @return nothing (well, the sct object)
proc add_sct_ls340 {name IP port terminator {_tol1 1.0} {_tol2 1.0} {CID 1} {CTYPE T} {_verbose 0} } { proc add_lakeshore_340 {name IP port {terminator \r\n} {_tol1 1.0} {_tol2 1.0} {CID 1} {CTYPE T} {_verbose 0} } {
# ffr 2009-11-09, Don't create a temperature controller for the script validator, this causes the # ffr 2009-11-09, Don't create a temperature controller for the script validator, this causes the
# lakeshore to lock up. # lakeshore to lock up.
# NOTE: I put this outside the catch block because "return" raises an exception # NOTE: I put this outside the catch block because "return" raises an exception
@ -2100,10 +2100,10 @@ proc add_sct_ls340 {name IP port terminator {_tol1 1.0} {_tol2 1.0} {CID 1} {CTY
if {[ catch { if {[ catch {
set _ls340_LSmodel 340 set _ls340_LSmodel 340
if {[string equal -nocase "aqadapter" "${IP}"]} { if {[string equal -nocase "aqadapter" "${IP}"]} {
puts "\nadd_ls340: makesctcontroller sct_ls340_$name aqadapter ${port} for Lakeshore model 340" puts "\add_lakeshore_340: makesctcontroller sct_ls340_$name aqadapter ${port} for Lakeshore model 340"
makesctcontroller sct_ls340_$name aqadapter ${port} makesctcontroller sct_ls340_$name aqadapter ${port}
} else { } else {
puts "\nadd_ls340: makesctcontroller sct_ls340_$name std ${IP}:$port $terminator for Lakeshore model 340" puts "\add_lakeshore_340: makesctcontroller sct_ls340_$name std ${IP}:$port $terminator for Lakeshore model 340"
makesctcontroller sct_ls340_$name std ${IP}:$port $terminator makesctcontroller sct_ls340_$name std ${IP}:$port $terminator
} }
::scobj::ls340::mk_sct_lakeshore_340 sct_ls340_$name environment $name $CID $CTYPE $_ls340_LSmodel $_tol1 $_tol2 $_verbose ::scobj::ls340::mk_sct_lakeshore_340 sct_ls340_$name environment $name $CID $CTYPE $_ls340_LSmodel $_tol1 $_tol2 $_verbose
@ -2111,30 +2111,77 @@ proc add_sct_ls340 {name IP port terminator {_tol1 1.0} {_tol2 1.0} {CID 1} {CTY
# set m2 "_2" # set m2 "_2"
# makesctemon $name$m2 /sics/$name/emon/monMode_Lp2 /sics/$name/emon/isInTolerance_Lp2 /sics/$name/emon/errhandler # makesctemon $name$m2 /sics/$name/emon/monMode_Lp2 /sics/$name/emon/isInTolerance_Lp2 /sics/$name/emon/errhandler
} message ]} { } message ]} {
return -code error "in add_ls340: $message" return -code error "in add_lakeshore_340: $message"
} }
} }
if {[ catch { namespace eval ::scobj::lakeshore_340 {
if { [ info exists ::config_dict ] } { set debug_threshold 5
dict for {secname secinfo} $::config_dict { }
if { [dict exists $secinfo "driver"] && ([dict get $secinfo "driver"] == "ls340") } { proc ::scobj::lakeshore_340::sics_log {debug_level debug_string} {
if { [ dict get $::secinfo enabled ] } { set catch_status [ catch {
set IP [dict get $::secinfo ip] set debug_threshold ${::scobj::lakeshore_340::debug_threshold}
set PORT [dict get $::secinfo port] if {${debug_level} >= ${debug_threshold}} {
set name [dict get $::secinfo name] sicslog "::scobj::lakeshore_340::${debug_string}"
set ctype [dict get $::secinfo type] }
set cid [dict get $::secinfo id] } catch_message ]
set term [dict get $::secinfo terminator] }
set tol1 [dict get $::secinfo tol1] proc ::scobj::lakeshore_340::read_config {} {
set tol2 [dict get $::secinfo tol2] set catch_status [ catch {
set ns "::scobj::lakeshore_340"
add_sct_ls340 $name $IP $PORT $term $tol1 $tol2 $cid $ctype dict for {k v} $::config_dict {
if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "lakeshore_340" } {
if { $enabled == "true" || $enabled == "always" } {
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"
} elseif { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set IP [dict get $v ip]
set PORT [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
set arg_list [list]
foreach arg {tol1 tol2 id} {
if {[dict exists $v $arg]} {
lappend arg_list "[dict get $v $arg]"
} else {
${ns}::sics_log 9 "Missing configuration value $arg"
error "Missing configuration value $arg"
}
}
add_lakeshore_340 ${name} "aqadapter" ${asyncqueue} {*}$arg_list
}
} }
} }
} }
} catch_message ]
handle_exception ${catch_status} ${catch_message}
} }
} message ]} {
puts "ERROR: $message" if { [info exists ::config_dict] } {
::scobj::lakeshore_340::read_config
} else {
::scobj::lakeshore_340::sics_log 5 "No config dict"
} }
namespace import ::scobj::ls340::* namespace import ::scobj::ls340::*

View File

@ -549,10 +549,13 @@ proc ::scobj::mercury_base::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::mercury_base" set ns "::scobj::mercury_base"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "mercury_base" } { if { [dict get $v "driver"] == "mercury_base" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -226,10 +226,13 @@ proc ::scobj::mercury_level::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::mercury_level" set ns "::scobj::mercury_level"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "mercury_level" } { if { [dict get $v "driver"] == "mercury_level" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -390,10 +390,13 @@ proc ::scobj::mercury_pres::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::mercury_pres" set ns "::scobj::mercury_pres"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "mercury_pres" } { if { [dict get $v "driver"] == "mercury_pres" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -745,10 +745,13 @@ proc ::scobj::mercury_scpi::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::mercury_scpi" set ns "::scobj::mercury_scpi"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "mercury_scpi" } { if { [dict get $v "driver"] == "mercury_scpi" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -395,10 +395,13 @@ proc ::scobj::mercury_temp::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::mercury_temp" set ns "::scobj::mercury_temp"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "mercury_temp" } { if { [dict get $v "driver"] == "mercury_temp" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -344,10 +344,13 @@ proc ::scobj::mercury_valve::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::mercury_valve" set ns "::scobj::mercury_valve"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "mercury_valve" } { if { [dict get $v "driver"] == "mercury_valve" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -494,10 +494,13 @@ proc ::scobj::pfeiffer_hg::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::pfeiffer_hg" set ns "::scobj::pfeiffer_hg"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "pfeiffer_hg" } { if { [dict get $v "driver"] == "pfeiffer_hg" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue"

View File

@ -345,10 +345,13 @@ proc ::scobj::reactor_status::read_config {} {
set catch_status [ catch { set catch_status [ catch {
set ns "::scobj::reactor_status" set ns "::scobj::reactor_status"
dict for {k v} $::config_dict { dict for {k v} $::config_dict {
if { [dict exists $v "driver"] } { if { [dict exists $v "implementation"] } {
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
set v [dict get $::config_dict $implementation]
if { [dict get $v "driver"] == "reactor_status" } { if { [dict get $v "driver"] == "reactor_status" } {
if { [dict get $v enabled] } { if { [dict get $v enabled] } {
set name [dict get $v name]
if { ![string equal -nocase [SplitReply [opal_simulation]] "false"] } { if { ![string equal -nocase [SplitReply [opal_simulation]] "false"] } {
set asyncqueue "null" set asyncqueue "null"
${ns}::sics_log 9 "[opal_simulation] => using null asyncqueue" ${ns}::sics_log 9 "[opal_simulation] => using null asyncqueue"

View File

@ -111,16 +111,19 @@ set move_count 10
set axis_config 0 set axis_config 0
if { [ info exists ::config_dict ] } { if { [ info exists ::config_dict ] } {
if {[ dict get $::config_dict normal_sample_stage enabled ] } { if { [ dict exists $::config_dict sample_stage implementation ] } {
set axis_config 0 set implementation [ dict get $::config_dict sample_stage implementation ]
} elseif {[ dict get $::config_dict eularian_cradle enabled ] } { if {$implementation == "normal_sample_stage"} {
set axis_config 1 set axis_config 0
} elseif {[ dict get $::config_dict small_omega enabled ] } { } elseif {$implementation == "eularian_cradle"} {
set axis_config 2 set axis_config 1
} elseif {[ dict get $::config_dict 12tmagnet_sample_insert enabled ] } { } elseif {$implementation == "small_omega"} {
set axis_config 3 set axis_config 2
} else { } elseif {$implementation == "12tmagnet_sample_insert"} {
set axis_config 0 set axis_config 3
} else {
set axis_config 0
}
} }
} }

View File

@ -1,32 +1,76 @@
[12tmagnet] [12tmagnet]
desc = "12 Tesla Oxford Magnet" desc = "12 Tesla Oxford Magnet"
driver = "12tmagnet" driver = "12tmagnet"
enabled = False group = implementation
group = environment:magnet
id = 11 id = 11
ip = 10.157.205.3 ip = 10.157.205.3
name = magnetic name = magnetic
port = 55001 port = 55001
type = B type = B
imptype = magnetic_field
[12tmagnet_sample_insert] [12tmagnet_sample_insert]
desc = "som will be redefined as the magnet sample insert rotation. Sample stage will be renamed to somss" desc = "som will be redefined as the magnet sample insert rotation. Sample stage will be renamed to somss"
enabled = False group = implementation
group = motors
offifon = normal_sample_stage,eularian_cradle,small_omega offifon = normal_sample_stage,eularian_cradle,small_omega
radio = samstage radio = samstage
imptype = motion_axis
[Default]
cascade = sample_stage:normal_sample_stage
enabled = True
group = Configuration
[12tmagnet_setup] [12tmagnet_setup]
cascade = 12tmagnet,12tmagnet_sample_insert,mercury_scpi cascade = B1:12tmagnet,sample_stage:12tmagnet_sample_insert,T1:mercury_scpi
enabled = False enabled = True
group = 0setup group = Configuration
onifoff = normal_sample_stage onifoff = normal_sample_stage
[CF1] [CF1]
desc = "cf1: Bottom loading cryofurnace" cascade = T1:CF1_ls340,sample_stage:normal_sample_stage
driver = "ls340"
enabled = False enabled = False
group = environment:temperature group = Configuration
[T1]
name = tc1
enabled = True
group = Configuration Components
implementation = mercury_scpi
type = temperature
[T2]
name = tc2
enabled = False
group = Configuration Components
implementation = ls336_02
type = temperature
[T3]
name = tc3
enabled = False
group = Configuration Components
implementation = ls336_04
type = temperature
[B1]
name = magnet1
enabled = True
group = Configuration Components
implementation = 12tmagnet
type = magnetic_field
[sample_stage]
name = sample_stage
enabled = Always
group = Configuration Components
implementation = 12tmagnet_sample_insert
type = motion_axis
[CF1_ls340]
desc = "cf1: Bottom loading cryofurnace"
driver = "lakeshore_340"
group = implementation
id = 12 id = 12
ip = 10.157.205.43 ip = 10.157.205.43
name = cf1 name = cf1
@ -35,19 +79,19 @@ terminator = \r\n
tol1 = 1.0 tol1 = 1.0
tol2 = 1.0 tol2 = 1.0
type = T type = T
imptype = temperature
[eularian_cradle] [eularian_cradle]
desc = "Load the Eulerian cradle configuration" desc = "Load the Eulerian cradle configuration"
enabled = False group = implementation
group = motors
offifon = normal_sample_stage,small_omega,12tmagnet_sample_insert offifon = normal_sample_stage,small_omega,12tmagnet_sample_insert
radio = samstage radio = samstage
imptype = motion_axis
[ls336_01] [ls336_01]
desc = "tc1: Lakeshore 336 temperature controller" desc = "tc1: Lakeshore 336 temperature controller"
driver = "ls336" driver = "lakeshore_336"
enabled = False group = implementation
group = environment:temperature
id = 1 id = 1
ip = 10.157.205.28 ip = 10.157.205.28
name = tc1 name = tc1
@ -56,12 +100,12 @@ terminator = \r\n
tol1 = 1.0 tol1 = 1.0
tol2 = 1.0 tol2 = 1.0
type = T type = T
imptype = temperature
[ls336_02] [ls336_02]
desc = "tc2: Lakeshore 336 temperature controller" desc = "tc2: Lakeshore 336 temperature controller"
driver = "ls336" driver = "lakeshore_336"
enabled = False group = implementation
group = environment:temperature
id = 2 id = 2
ip = 10.157.205.29 ip = 10.157.205.29
name = tc2 name = tc2
@ -70,12 +114,12 @@ terminator = \r\n
tol1 = 1.0 tol1 = 1.0
tol2 = 1.0 tol2 = 1.0
type = T type = T
imptype = temperature
[ls336_04] [ls336_04]
desc = "tc3: Lakeshore 336 temperature controller" desc = "tc3: Lakeshore 336 temperature controller"
driver = "ls336" driver = "lakeshore_336"
enabled = False group = implementation
group = environment:temperature
id = 3 id = 3
ip = 10.157.205.30 ip = 10.157.205.30
name = tc3 name = tc3
@ -84,12 +128,12 @@ terminator = \r\n
tol1 = 1.0 tol1 = 1.0
tol2 = 1.0 tol2 = 1.0
type = T type = T
imptype = temperature
[ls336_05] [ls336_05]
desc = "tc4: Lakeshore 336 temperature controller" desc = "tc4: Lakeshore 336 temperature controller"
driver = "ls336" driver = "lakeshore_336"
enabled = False group = implementation
group = environment:temperature
id = 4 id = 4
ip = 137.157.201.21 ip = 137.157.201.21
name = tc4 name = tc4
@ -98,12 +142,12 @@ terminator = \r\n
tol1 = 1.0 tol1 = 1.0
tol2 = 1.0 tol2 = 1.0
type = T type = T
imptype = temperature
[ls336_06] [ls336_06]
desc = "tc5: Lakeshore 336 temperature controller" desc = "tc5: Lakeshore 336 temperature controller"
driver = "ls336" driver = "lakeshore_336"
enabled = False group = implementation
group = environment:temperature
id = 5 id = 5
ip = 137.157.201.21 ip = 137.157.201.21
name = tc5 name = tc5
@ -112,12 +156,12 @@ terminator = \r\n
tol1 = 1.0 tol1 = 1.0
tol2 = 1.0 tol2 = 1.0
type = T type = T
imptype = temperature
[ls336_12] [ls336_12]
desc = "tc6: Lakeshore 336 temperature controller" desc = "tc6: Lakeshore 336 temperature controller"
driver = "ls336" driver = "lakeshore_336"
enabled = False group = implementation
group = environment:temperature
id = 6 id = 6
ip = 10.157.205.31 ip = 10.157.205.31
name = tc6 name = tc6
@ -126,11 +170,12 @@ terminator = \r\n
tol1 = 1.0 tol1 = 1.0
tol2 = 1.0 tol2 = 1.0
type = T type = T
imptype = temperature
[ls340_01] [ls340_01]
desc = "tc7: Lakeshore 340 temperature controller" desc = "tc7: Lakeshore 340 temperature controller"
enabled = False group = implementation
group = environment:temperature driver = "lakeshore_340"
id = 7 id = 7
ip = 137.157.201.86 ip = 137.157.201.86
name = tc7 name = tc7
@ -139,11 +184,12 @@ terminator = \r\n
tol1 = 1.0 tol1 = 1.0
tol2 = 1.0 tol2 = 1.0
type = T type = T
imptype = temperature
[ls340_02] [ls340_02]
desc = "tc8: Lakeshore 340 temperature controller" desc = "tc8: Lakeshore 340 temperature controller"
enabled = False group = implementation
group = environment:temperature driver = "lakeshore_340"
id = 8 id = 8
ip = 137.157.201.86 ip = 137.157.201.86
name = tc8 name = tc8
@ -152,42 +198,42 @@ terminator = \r\n
tol1 = 1.0 tol1 = 1.0
tol2 = 1.0 tol2 = 1.0
type = T type = T
imptype = temperature
[mercury_scpi] [mercury_scpi]
desc = "tc9: Oxford Mercury temperature controller in Mercury mode" desc = "tc9: Oxford Mercury temperature controller in Mercury mode"
driver = "mercury_scpi" driver = "mercury_scpi"
enabled = False group = implementation
group = environment:temperature
id = 9 id = 9
ip = 10.157.205.5 ip = 10.157.205.5
name = tc9 name = tc9
offifon = mercury_itc500
port = 7020 port = 7020
terminator = \r terminator = \r
tol = 2.0 tol = 2.0
type = T type = T
imptype = temperature
[normal_sample_stage] [normal_sample_stage]
desc = "This is the default sample stage configuration with xy translation and phi and chi tilt stages" desc = "This is the default sample stage configuration with xy translation and phi and chi tilt stages"
enabled = True group = implementation
group = motors
offifon = eularian_cradle,small_omega,12tmagnet_sample_insert offifon = eularian_cradle,small_omega,12tmagnet_sample_insert
radio = samstage radio = samstage
imptype = motion_axis
[small_omega] [small_omega]
desc = "Load the small omega configuration" desc = "Load the small omega configuration"
enabled = False group = implementation
group = motors
offifon = normal_sample_stage,eularian_cradle,12tmagnet_sample_insert offifon = normal_sample_stage,eularian_cradle,12tmagnet_sample_insert
radio = samstage radio = samstage
imptype = motion_axis
[west4100] [west4100]
desc = "tc10: Blue furnace temperature controller" desc = "tc10: Blue furnace temperature controller"
driver = "west4100" driver = "west4100"
enabled = False group = implementation
group = environment:temperature
id = 10 id = 10
ip = 10.157.205.19 ip = 10.157.205.19
name = tc10 name = tc10
type = T type = T
imptype = temperature

View File

@ -76,9 +76,9 @@ SetVoltScale 2000.0
# LS336 01 at 205.28 # LS336 01 at 205.28
# LS336 02 at 205.29 # LS336 02 at 205.29
add_sct_ls336 tc2 10.157.205.30 7777 "\r\n" 1.0 1.0 # add_sct_ls336 tc2 10.157.205.30 7777 "\r\n" 1.0 1.0
add_sct_ls336 tc1 10.157.205.31 7777 "\r\n" 1.0 1.0 # add_sct_ls336 tc1 10.157.205.31 7777 "\r\n" 1.0 1.0
add_sct_ls340 tc3 137.157.201.86 4001 "\r\n" 1.0 1.0 # add_sct_ls340 tc3 137.157.201.86 4001 "\r\n" 1.0 1.0
server_init server_init
########################################### ###########################################

View File

@ -1,236 +1,401 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim: tabstop=8 softtabstop=2 shiftwidth=2 nocin si et ft=python # vim: tabstop=8 softtabstop=2 shiftwidth=2 nocin si et ft=python
# View Screen has 3 parts
# (SICS Configuration), (Configuration Components), (Component Implementation)
# Uses MVC implemented as InstConfigData<M>, InstConfigView<V>, ConfigEdit<C>
#
# InstConfigData <>--- ConfigParser.SafeConfig
# |--set_cfparse()
# ConfigEdit <>--- InstConfigData, PresentationData
# |--set_cfdata(), set_presdata()
# |--set_xyz_data() call self.cfgdata.set_xyz() methods
#
# urwid.Frame
# ^
# InstConfigView <>--- ConfigEdit, PresentationData
# |--set_cfedit(), set_presdata()
#
# PresentationData
# |--set_cfdata()
# TODO
# cfgini = ConfigParser.SafeConfig()
# cfgdata = InstConfigData()
# DONE presentation = PresentationData()
# cfgedit = ConfigEdit()
# DONE cf_viewer = InstConfigView()
# config = ConfigParser.SafeConfig()
# cfgdata.set_cfparse(config)
# presentation.set_cfdata(cfgdata)
# cfgedit.set_cfdata(cfgdata)
# cfgedit.set_presdata(presentation)
# cf_viewer.set_cfedit(cfgedit)
# cf_viewer.set_presdata(presentation)
#
# cf_viewer calls self.cfgedit.set_xyz_data() methods on state change
# cf_viewer
import os import os
import sys import argparse
import ConfigParser
import urwid
import copy
from collections import defaultdict
global config
global verbose
global depth_list, line_list
config = None
verbose = False
depth_list = []
line_list = []
Radio_Groups = {}
def read_config_file(config_filename): class InstConfigData:
import ConfigParser msg_index = 4
config = ConfigParser.SafeConfigParser() # configuration_dict: dict of instrument configurations as defined below,
config.read(config_filename) # {configname: {'enabled':T/F, 'cascade_list':[(option, dflt_imp)]} }
return config configuration_dict = defaultdict(dict)
def reread_config_file(config_filename, cb_list): # opt_dict: dict of configuration options as defined below,
config = read_config_file(config_filename) # {optname:{'enabled': T/F/Always, 'imptype':type, 'selected_imp':dflt}}
for cb in cb_list: opt_dict = defaultdict(dict)
lbl = cb.original_widget.get_label()
if ":" in lbl:
lbl = lbl.split(":")[0]
state = False
if 'enabled' in config.options(lbl):
if config.get(lbl, 'enabled').lower() in ['1', 'yes', 'true']:
state = True
config.set(lbl, 'enabled', str(state))
cb.original_widget.set_state(state, False)
return config
def write_config_file(config, config_filename): # imp_dict: dict of implementations indexed by type,
for idx in range(8, 0, -1): # {type: [impname] }
if os.path.exists(config_filename + "." + str(idx)): imp_dict = defaultdict(list)
os.rename(config_filename + "." + str(idx),
config_filename + "." + str(idx + 1))
if os.path.exists(config_filename):
os.rename(config_filename, config_filename + ".1")
with open(config_filename, "wb") as configfile:
for section in sorted(config.sections()):
configfile.write("[%s]\n" % section)
for option in sorted(config.options(section)):
configfile.write("%s = %s\n" % (option, config.get(section, option)))
configfile.write("\n")
#config.write(configfile)
def do_cascade(config, name, cb_list, label, new_state): def __init__(self):
global depth_list return
try:
if name in depth_list:
depth_list.append(name)
raise Exception("Recursion on " + str(depth_list))
depth_list.append(name)
if label in config.options(name):
cascade_list = config.get(name, label).lower().split(",")
for cb in cb_list:
lbl = cb.original_widget.get_label().lower()
if ":" in lbl:
lbl = lbl.split(":")[0]
if lbl in cascade_list:
cb.original_widget.set_state(new_state)
finally:
depth_list.pop()
def main(config_filename): def __get_configurations(self):
import urwid for s in self.file_parser.sections():
global config cascade_list = []
if self.file_parser.has_option(s, 'cascade'):
enabled = self.file_parser.get(s, 'enabled')
for cascade_str in self.file_parser.get(s,'cascade').split(','):
cascade_list.append(tuple(cascade_str.split(':')))
if enabled.lower() in ['true','always']:
stateval = True
else:
stateval = False
self.configuration_dict[s]['enabled'] = stateval
self.configuration_dict[s]['cascade_list'] = cascade_list
config = read_config_file(config_filename) def __get_options(self):
text_header = ( for s in self.file_parser.sections():
u"SICS Config Editor! SPACE/ENTER: Toggle, w/W/F12: Write+Exit\n" if self.file_parser.has_option(s, 'implementation'):
u"UP/DOWN/PAGE UP/PAGE DOWN: scroll, r/R: Reread, q/Q/F8: Quit") selected_imp = self.file_parser.get(s, 'implementation')
imptype = self.file_parser.get(s, 'type')
enabled = self.file_parser.get(s, 'enabled').lower()
if enabled == 'always':
stateval = True
permanent = True
elif enabled == 'true':
stateval = True
permanent = False
else:
stateval = False
permanent = False
def checkbox_change(check_box, new_state, user_data): self.opt_dict[s]['enabled'] = stateval
global config, verbose, depth_list, line_list self.opt_dict[s]['permanent'] = permanent
if len(depth_list) == 0: self.opt_dict[s]['imptype'] = imptype
line_list = [] self.opt_dict[s]['selected_imp'] = selected_imp
frame.footer = urwid.AttrMap(urwid.Text(""), 'header')
config.set(user_data, 'enabled', str(new_state))
if verbose:
line = u"Checkbox: name=%s, new_state=%s, user_data=%s" % (
check_box.get_label(), str(new_state), str(user_data))
line_list.append(line + "\n")
frame.footer = urwid.AttrMap(urwid.Text(line_list), 'header')
try:
order = ['offifoff', 'offifon', 'onifon', 'onifoff', 'cascade']
if 'order' in config.options(user_data):
order = config.get(user_data, 'order').lower().split(",")
for item in order:
if 'cascade' == item:
do_cascade(config, user_data, cb_list, 'cascade', new_state)
if (True == new_state) and 'onifon' == item:
do_cascade(config, user_data, cb_list, 'onifon', True)
if (True == new_state) and 'offifon' == item:
do_cascade(config, user_data, cb_list, 'offifon', False)
if (False == new_state) and 'onifoff' == item:
do_cascade(config, user_data, cb_list, 'onifoff', True)
if (False == new_state) and 'offifoff' == item:
do_cascade(config, user_data, cb_list, 'offifoff', False)
except Exception as prang:
line = "Exception: %s" % prang
line_list.append(line + "\n")
frame.footer = urwid.AttrMap(urwid.Text(line_list), 'header')
text_cb_list = list(config.sections()) def __get_implementations(self):
cb_map = {} for s in self.file_parser.sections():
for txt in sorted(text_cb_list): if self.file_parser.has_option(s, 'imptype'):
if 'group' in config.options(txt): key = self.file_parser.get(s, 'imptype')
group = config.get(txt, 'group').lower() self.imp_dict[key].append(s)
else:
group = "" def read_config_file(self, config_filename):
if group not in cb_map: self.config_filename = config_filename
cb_map[group] = [] self.file_parser = ConfigParser.SafeConfigParser()
cb_map[group].append(txt) self.file_parser.read(config_filename)
lb_list = [] self.__get_options()
cb_list = [] self.__get_implementations()
for key in sorted(cb_map.keys()): self.__get_configurations()
if len(key) > 0: return
lb_list.append(urwid.AttrMap(urwid.Text("Group: %s" % key), 'bright'))
for txt in sorted(cb_map[key]): def backup_files(self):
state = False for idx in range(8, 0, -1):
if 'enabled' in config.options(txt): if os.path.exists(self.config_filename + "." + str(idx)):
if config.get(txt, 'enabled').lower() in ['1', 'yes', 'true']: os.rename(self.config_filename + "." + str(idx),
state = True self.config_filename + "." + str(idx + 1))
config.set(txt, 'enabled', str(state)) if os.path.exists(self.config_filename):
cb_text = txt os.rename(self.config_filename, self.config_filename + ".1")
if 'group' in config.options(txt) or 'desc' in config.options(txt): return
cb_text += ": ("
if 'group' in config.options(txt): def write_config_file(self):
cb_text += config.get(txt, 'group').strip("\"") + ": " for item,dict in self.opt_dict.iteritems():
if 'desc' in config.options(txt): if self.file_parser.get(item, 'enabled').lower() == 'always':
cb_text += config.get(txt, 'desc').strip("\"") enabled = 'Always'
cb_text += ")"
if 'radio' in config.options(txt):
radio = config.get(txt, 'radio').strip("\"")
if radio not in Radio_Groups:
Radio_Groups[radio] = []
cb = urwid.AttrMap(urwid.RadioButton(
Radio_Groups[radio],
cb_text,
state=state,
on_state_change=checkbox_change,
user_data=txt), 'buttn', 'buttnf')
else: else:
cb = urwid.AttrMap(urwid.CheckBox(cb_text, enabled = dict['enabled'].__str__()
state=state, self.file_parser.set(item, 'enabled', enabled)
on_state_change=checkbox_change, self.file_parser.set(item, 'implementation', dict['selected_imp'])
user_data=txt), 'buttn', 'buttnf') self.file_parser.set(item, 'type', dict['imptype'])
cb_list.append(cb) for item,dict in self.configuration_dict.iteritems():
lb_list.append(cb) enabled = dict['enabled'].__str__()
self.file_parser.set(item, 'enabled', enabled)
with open(self.config_filename,'w') as cfile:
self.file_parser.write(cfile)
def fcc(focus): def cf_statechange(self, checkbox, new_state, udat=None):
frame.footer = urwid.AttrMap(urwid.Text( cfg_id = checkbox.get_label()
[u"Focus: " + str(focus)]), 'header') self.configuration_dict[cfg_id]['enabled'] = new_state
def opt_statechange(self, checkbox, new_state, udat=None):
opt = checkbox.get_label()
dbg.msg(3, 'InstConfigData:opt_statechange({},{},{})'.format(opt, new_state, udat))
self.opt_dict[opt]['enabled'] = new_state
def imp_statechange(self, button, new_state, opt):
selected_imp = button.get_label()
dbg.msg(self.msg_index, 'InstConfigData:imp_statechange({},{},{})'.format(selected_imp, new_state, opt))
self.msg_index = (self.msg_index - 3) % 2 + 4
if new_state == True:
self.opt_dict[opt]['selected_imp'] = selected_imp
blank = urwid.Divider() ## TODO Configuration Editor
listbox_content = [ ## Configuration Viewer
blank, Palette = [
urwid.Padding(urwid.GridFlow( ('body', 'dark cyan', '', 'standout'),
cb_list, ('focus', 'dark red', '', 'standout'),
76, 1, 0, 'left'), ('head', 'light red', 'black'),
left=2, right=2, min_width=76), ]
blank,
blank
]
header = urwid.AttrMap(urwid.Text(text_header), 'header') #FIXME Replace the [(name,stateval)] list imp_states with list of item names
sflw = urwid.SimpleListWalker(lb_list) class RadioButtonListWalker(urwid.SimpleListWalker):
listbox = urwid.ListBox(sflw) button_dict = {}
frame = urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) def __init__(self, item_states, on_state_change=None, user_data=None):
frame.footer = urwid.AttrMap(urwid.Text(""), 'header') radio_grp = []
mapped_rb_list = []
for item,stateval in item_states:
rb = urwid.RadioButton(radio_grp, item, state=stateval, on_state_change=on_state_change, user_data=user_data)
self.button_dict[item] = rb
mapped_rb = urwid.AttrMap(rb, 'body', 'focus')
mapped_rb_list.append(mapped_rb)
palette = [ super(RadioButtonListWalker, self).__init__(mapped_rb_list)
('body', 'black', 'light gray', 'standout'), return
('reverse', 'light gray', 'black'),
('header', 'white', 'dark red', 'bold'),
('important', 'dark blue', 'light gray', ('standout', 'underline')),
('editfc', 'white', 'dark blue', 'bold'),
('editbx', 'light gray', 'dark blue'),
('editcp', 'black', 'light gray', 'standout'),
('bright', 'dark gray', 'light gray', ('bold', 'standout')),
('buttn', 'black', 'dark cyan'),
('buttnf', 'white', 'dark blue', 'bold'),
]
def unhandled(key):
global config class CheckBoxListWalker(urwid.SimpleListWalker):
if key in ['w', 'W', 'f12']: button_dict = {}
write_config_file(config, config_filename) def __init__(self, item_states, on_state_change = None, user_data = None):
raise urwid.ExitMainLoop() mapped_cb_list = []
elif key in ['r', 'R']: for item,stateval in item_states:
config = reread_config_file(config_filename, cb_list) cb = urwid.CheckBox(item, state = stateval, on_state_change = on_state_change, user_data = user_data)
elif key in ['e', 'E', 'f4']: self.button_dict[item] = cb
f = sflw.get_focus() mapped_cb = urwid.AttrMap(cb, 'body', 'focus')
frame.footer = urwid.AttrMap(urwid.Text([u"EditE: " + str(dir(f[0]))]), 'header') mapped_cb_list.append(mapped_cb)
elif key in ['q', 'Q', 'f8']:
raise urwid.ExitMainLoop() super(CheckBoxListWalker, self).__init__(mapped_cb_list)
# elif key in ['b', 'B']: return
# l = sflw[1].base_widget
# f = l.focus_cell
# b = l.cells.index(f) # Selects listwalker to display for ImpListBox on focus
# l.cells.insert(b + 1, urwid.AttrMap(urwid.Edit(edit_text=u"Hello"), 'header')) class OptionListWalker(CheckBoxListWalker):
# l.set_focus(b + 1) def __init__(self, opt_dict, statechange_cb):
# frame.footer = urwid.AttrMap(urwid.Text([u"EditB: " + str(b)]), 'header') urwid.register_signal(OptionListWalker, ['focus_change'])
item_states = [(i,d['enabled']) for i,d in opt_dict.iteritems()]
item_states.sort()
super(OptionListWalker, self).__init__(item_states, statechange_cb)
return
def set_focus(self, pos):
dbg.msg(0, 'OptionListWalker:set_focus({}) -> emit focus_change'.format(pos))
urwid.emit_signal(self, 'focus_change', pos)
return super(OptionListWalker, self).set_focus(pos)
# ClosedListBox implements a ListBox which prevents selection outside of the
# list using the 'up' or 'down' keys
class ClosedListBox(urwid.ListBox):
def keypress(self, size, key):
"""Prevents navigating outside of a ClosedListBox with the up and down arrow keys"""
pos = self.get_focus()[1]
ll = len(self.body)
if (pos <= 0 and key == 'up') or (pos >= ll-1 and key == 'down'):
return
else: else:
if not key[0] == 'mouse release': return super(ClosedListBox, self).keypress(size, key)
frame.footer = urwid.AttrMap(urwid.Text([u"Press: " + str(key)]), 'header')
urwid.MainLoop(frame, palette, unhandled_input=unhandled).run()
if '__main__'==__name__: # List of Checkboxes
global verbose class OptionListBox(ClosedListBox):
import argparse def __init__(self, listwalker):
super(OptionListBox, self).__init__(listwalker)
return
# set default_ini to the name of the file to edit when no name is supplied # Contains OptionListWalker dict indexed by option
# Contains ImpListBox
# Connects OptionListWalker 'focus_change' signal to update_imp_lb handler
# Tracks selected implementation for each option
# and sets selection on ImpListBox
class InstConfigManager:
cf_msg_index = 8
options = []
imp_lw_dict = {}
def __init__(self, cfdat):
self.cfdat = cfdat
urwid.register_signal(InstConfigManager, ['focus_change'])
for opt,dict in cfdat.opt_dict.iteritems():
self.options.append((opt, dict['imptype']))
imp_items = []
for imp in cfdat.imp_dict[dict['imptype']]:
if imp == dict['selected_imp']:
imp_items.append((imp, True))
else:
imp_items.append((imp, False))
imp_items.sort()
self.imp_lw_dict[opt] = RadioButtonListWalker(imp_items, on_state_change=self.imp_statechange, user_data=opt)
self.options.sort()
self.option_lw = OptionListWalker(cfdat.opt_dict, self.opt_statechange)
opt = self.options[0][0]
self.imp_lb = ImpListBox(copy.copy(self.imp_lw_dict[opt]))
urwid.connect_signal(self.option_lw, 'focus_change', self.update_imp_lb)
item_states = [(i,d['enabled']) for i,d in cf_dat.configuration_dict.iteritems()]
item_states.sort()
self.cfg_lw = RadioButtonListWalker(item_states, on_state_change = self.cf_statechange)
self.config_lb = OptionListBox(self.cfg_lw)
self.opt_lb = OptionListBox(self.option_lw)
return
def cf_statechange(self, button, new_state, udat=None):
self.cfdat.cf_statechange(button, new_state, udat)
b = button.get_label()
cascade = self.cfdat.configuration_dict[b]['cascade_list']
if new_state == True:
for opt in self.cfdat.opt_dict.keys():
if self.cfdat.opt_dict[opt]['permanent'] == False:
self.option_lw.button_dict[opt].set_state(False)
for opt,imp in cascade:
self.option_lw.button_dict[opt].set_state(True)
self.imp_lw_dict[opt].button_dict[imp].set_state(True)
dbg.msg(self.cf_msg_index, 'InstConfigManager:cf_statechange({},{},{}), cascade = {}'.format(b, new_state, udat, cascade))
self.cf_msg_index = (self.cf_msg_index - 7) % 2 + 8
return
def opt_statechange(self, button, new_state, udat=None):
self.cfdat.opt_statechange(button, new_state, udat)
return
def imp_statechange(self, button, new_state, udat=None):
self.cfdat.imp_statechange(button, new_state, udat)
return
def update_imp_lb(self, pos):
optname = self.options[pos][0]
type = self.options[pos][1]
mstr = 'InstConfigManager:update_imp_lb({}) -> select {}'.format(pos, type)
dbg.msg(1, mstr)
self.imp_lb.use_listwalker(self.imp_lw_dict[optname])
return
# List of RadioButtons
class ImpListBox(ClosedListBox):
def __init__(self, listwalker):
super(ImpListBox, self).__init__(listwalker)
return
def use_listwalker(self, liswalker):
self.body.contents[:] = liswalker
return
class InstConfigView(urwid.Pile):
def __init__(self, cf_dat, cf_man, dbmsg):
self.cf_dat = cf_dat
self.cf_man = cf_man
option_ListBoxes = [
self.cf_man.config_lb,
self.cf_man.opt_lb,
self.cf_man.imp_lb,
dbmsg]
super(InstConfigView, self).__init__(option_ListBoxes)
return
def keyinput(self, key):
if key == 'meta q':
raise urwid.ExitMainLoop()
elif key == 'w':
self.cf_dat.backup_files()
self.cf_dat.write_config_file()
elif key in ['right', 'tab']:
if self.get_focus() == self.cf_man.config_lb:
self.set_focus(self.cf_man.opt_lb)
elif self.get_focus() == self.cf_man.opt_lb:
self.set_focus(self.cf_man.imp_lb)
else:
self.set_focus(self.cf_man.config_lb)
elif key in ['left', 'shift tab']:
if self.get_focus() == self.cf_man.config_lb:
self.set_focus(self.cf_man.imp_lb)
elif self.get_focus() == self.cf_man.opt_lb:
self.set_focus(self.cf_man.config_lb)
else:
self.set_focus(self.cf_man.opt_lb)
return
import pdb
class DEBUG:
msgTextDict = {}
msglist = []
msg_ids = [ 'm0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9' ]
def __init__(self, enabled=False):
self.enabled = enabled
if enabled:
for msgID in self.msg_ids:
msgText = urwid.Text(u'Space for message {}'.format(msgID))
self.msgTextDict[msgID] = msgText
self.msglist.append(urwid.AttrMap(msgText, 'body', 'focus'))
mlw = urwid.SimpleListWalker(self.msglist)
self.mlb = urwid.ListBox(mlw)
return
def msg(self, index, msg):
if self.enabled:
mid = self.msg_ids[index]
self.msgTextDict[mid].set_text(msg)
return
dbg = DEBUG(enabled=True)
def main(config_ini):
global cf_dat, cf_man, cf_viewer
# Make configuration data
cf_dat = InstConfigData()
cf_dat.read_config_file(config_ini)
# Make configuration editor
cf_man = InstConfigManager(cf_dat)
# Make configuration viewer
cf_viewer = InstConfigView(cf_dat, cf_man, dbg.mlb)
urwid.MainLoop(cf_viewer, Palette, unhandled_input=cf_viewer.keyinput).run()
return
if '__main__' == __name__:
default_ini = "/usr/local/sics/sics_config.ini" default_ini = "/usr/local/sics/sics_config.ini"
parser = argparse.ArgumentParser(description = """ parser = argparse.ArgumentParser(description = """
Edit a configuration (*.ini) file using python urwid widget library. Edit a configuration (*.ini) file using python urwid widget library.
Options can be enabled or disabled with mouse or spacebar. Options can be enabled or disabled with mouse or spacebar.
Navigate with arrow keys.
Press W to save.
Press Alt-Q to quit.
The default configuration filename is %s. The default configuration filename is %s.
""" % default_ini) """ % default_ini)
parser.add_argument("-v", "--verbose", action="store_true", help="give more infor in the footer") parser.add_argument("-v", "--verbose", action="store_true", help="give more info in the footer")
parser.add_argument("path", nargs="?", default = default_ini, help="name of file to edit [%s]" % default_ini) parser.add_argument("path", nargs="?", default = default_ini, help="name of file to edit [%s]" % default_ini)
args = parser.parse_args() args = parser.parse_args()
default_ini = os.path.abspath(args.path) default_ini = os.path.abspath(args.path)
if args.verbose:
verbose = True
main(default_ini) main(default_ini)

View File

@ -1399,10 +1399,13 @@ def put_read_config(MyDriver):
txt += [' set catch_status [ catch {'] txt += [' set catch_status [ catch {']
txt += [' set ns "%s"' % MyDriver['namespace']] txt += [' set ns "%s"' % MyDriver['namespace']]
txt += [' dict for {k v} $::config_dict {'] txt += [' dict for {k v} $::config_dict {']
txt += [' if { [dict exists $v "driver"] } {'] txt += [' if { [dict exists $v "implementation"] } {']
txt += [' set name [dict get $v name]']
txt += [' set enabled [string tolower [dict get $v "enabled"]]']
txt += [' set implementation [dict get $v "implementation"]']
txt += [' set v [dict get $::config_dict $implementation]']
txt += [' if { [dict get $v "driver"] == "%s" } {' % MyDriver['name']] txt += [' if { [dict get $v "driver"] == "%s" } {' % MyDriver['name']]
txt += [' if { [dict get $v enabled] } {'] txt += [' if { [dict get $v enabled] } {']
txt += [' set name [dict get $v name]']
txt += [' if { ![string equal -nocase [SplitReply [%s]] "false"] } {' % MyDriver['simulation_group']] txt += [' if { ![string equal -nocase [SplitReply [%s]] "false"] } {' % MyDriver['simulation_group']]
txt += [' set asyncqueue "null"'] txt += [' set asyncqueue "null"']
txt += [' ${ns}::sics_log 9 "[%s] => using null asyncqueue"' % MyDriver['simulation_group']] txt += [' ${ns}::sics_log 9 "[%s] => using null asyncqueue"' % MyDriver['simulation_group']]