# Generated driver for west_6100 # vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent # namespace eval ::scobj::west_6100 { set debug_threshold 5 } proc ::scobj::west_6100::debug_log {tc_root debug_level debug_string} { set catch_status [ catch { set debug_threshold [hgetpropval ${tc_root} debug_threshold] if {${debug_level} >= ${debug_threshold}} { set now [clock seconds] set ts [clock format ${now} -format "%Y%m%d"] set log_file_name "../log/west_6100_[basename ${tc_root}]_${ts}.log" set fd [open "${log_file_name}" "a"] set ts [clock format ${now} -format "%T"] puts ${fd} "${ts} ${debug_string}" close ${fd} } } catch_message ] } proc ::scobj::west_6100::sics_log {debug_level debug_string} { set catch_status [ catch { set debug_threshold ${::scobj::west_6100::debug_threshold} if {${debug_level} >= ${debug_threshold}} { sicslog "::scobj::west_6100::${debug_string}" } } catch_message ] } # checklimits function for driveable interface proc ::scobj::west_6100::checklimits {tc_root} { set catch_status [ catch { debug_log ${tc_root} 1 "checklimits tc_root=${tc_root} sct=[sct] target=[sct target]" set setpoint [sct target] if { [hpropexists [sct] lowerlimit] } { set lolimit [sct lowerlimit] } else { # lowerlimit not set, use target set lolimit [sct target] } if { [hpropexists [sct] upperlimit] } { set hilimit [sct upperlimit] } else { # upperlimit not set, use target set hilimit [sct target] } # checklimits hook code goes here if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } { sct driving 0 error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]" } return OK } catch_message ] handle_exception ${catch_status} ${catch_message} } # check function for hset change proc ::scobj::west_6100::checkrange {tc_root} { set catch_status [ catch { debug_log ${tc_root} 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]" set setpoint [sct target] if { [hpropexists [sct] lowerlimit] } { set lolimit [sct lowerlimit] } else { # lowerlimit not set, use target set lolimit [sct target] } if { [hpropexists [sct] upperlimit] } { set hilimit [sct upperlimit] } else { # upperlimit not set, use target set hilimit [sct target] } # checkrange hook code goes here if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } { error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]" } return OK } catch_message ] handle_exception ${catch_status} ${catch_message} } # checkstatus function for driveable interface proc ::scobj::west_6100::checkstatus {tc_root} { set catch_status [ catch { # checkstatus hook code goes here if {[sct driving]} { set sp "[sct target]" if {[hpropexists [sct] simulated] && [sct simulated] == "true"} { set pv "${sp}" hupdateif ${tc_root}/[sct driveable] ${sp} } else { set pv "[hval ${tc_root}/[sct driveable]]" } if { abs(${pv} - ${sp}) <= [sct tolerance] } { if { [hpropexists [sct] settle_time] } { if { [hpropexists [sct] settle_time_start] } { if { [sct utime] - [sct settle_time_start] >= [sct settle_time]} { sct driving 0 return "idle" } return "busy" } else { sct utime settle_time_start return "busy" } } sct driving 0 return "idle" } if { [hpropexists [sct] settle_time_start] } { hdelprop [sct] settle_time_start } return "busy" } else { return "idle" } } catch_message ] handle_exception ${catch_status} ${catch_message} } # function to request the read of a parameter on a device proc ::scobj::west_6100::getDecimal {tc_root nextState cmd_str} { set catch_status [ catch { debug_log ${tc_root} 1 "getDecimal tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" if { [hpropexists [sct] geterror] } { hdelprop [sct] geterror } set cmd "${cmd_str}" # getDecimal hook code starts set cmd "1:3:${cmd_str}:1:U16" # getDecimal hook code ends if { [hpropexists [sct] geterror] } { debug_log ${tc_root} 9 "[sct] error: [sct geterror]" error "[sct geterror]" } debug_log ${tc_root} 1 "getDecimal sct send ${cmd}" if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { sct send "${cmd}" } return ${nextState} } catch_message ] handle_exception ${catch_status} ${catch_message} } # function to request the read of a parameter on a device proc ::scobj::west_6100::getInteger {tc_root nextState cmd_str} { set catch_status [ catch { debug_log ${tc_root} 1 "getInteger tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" if { [hpropexists [sct] geterror] } { hdelprop [sct] geterror } set cmd "${cmd_str}" # getInteger hook code starts set cmd "1:3:${cmd_str}:1:U16" # getInteger hook code ends if { [hpropexists [sct] geterror] } { debug_log ${tc_root} 9 "[sct] error: [sct geterror]" error "[sct geterror]" } debug_log ${tc_root} 1 "getInteger sct send ${cmd}" if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { sct send "${cmd}" } return ${nextState} } catch_message ] handle_exception ${catch_status} ${catch_message} } # halt function for driveable interface proc ::scobj::west_6100::halt {tc_root} { set catch_status [ catch { debug_log ${tc_root} 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]" ### TODO hset [sct] [hval [sct]] # halt hook code goes here sct driving 0 return "idle" } catch_message ] handle_exception ${catch_status} ${catch_message} } # function to check the write parameter on a device proc ::scobj::west_6100::noResponse {tc_root} { set catch_status [ catch { debug_log ${tc_root} 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]" # noResponse hook code goes here return "idle" } catch_message ] handle_exception ${catch_status} ${catch_message} } # function to parse the read of a parameter on a device proc ::scobj::west_6100::rdDecimal {tc_root} { set catch_status [ catch { debug_log ${tc_root} 1 "rdDecimal tc_root=${tc_root} sct=[sct] result=[sct result]" if { [hpropexists [sct] geterror] } { hdelprop [sct] geterror } set data [sct result] set nextState "idle" if {[string equal -nocase -length 7 ${data} "ASCERR:"]} { # the protocol driver has reported an error sct geterror "${data}" error "[sct geterror]" } # rdDecimal hook code starts set decimal [hval ${tc_root}/aux/decimal] if { ${decimal} > 0 } { set data [expr {pow(10, -${decimal}) * ${data}}] } # rdDecimal hook code ends if { [hpropexists [sct] geterror] } { debug_log ${tc_root} 9 "[sct] error: [sct geterror]" error "[sct geterror]" } if { ${data} != [sct oldval] } { debug_log ${tc_root} 1 "[sct] changed to new:${data}, from old:[sct oldval]" sct oldval ${data} sct update ${data} sct utime readtime } return ${nextState} } catch_message ] handle_exception ${catch_status} ${catch_message} } # function to parse the read of a parameter on a device proc ::scobj::west_6100::rdInteger {tc_root} { set catch_status [ catch { debug_log ${tc_root} 1 "rdInteger tc_root=${tc_root} sct=[sct] result=[sct result]" if { [hpropexists [sct] geterror] } { hdelprop [sct] geterror } set data [sct result] set nextState "idle" if {[string equal -nocase -length 7 ${data} "ASCERR:"]} { # the protocol driver has reported an error sct geterror "${data}" error "[sct geterror]" } # rdInteger hook code goes here if { ${data} != [sct oldval] } { debug_log ${tc_root} 1 "[sct] changed to new:${data}, from old:[sct oldval]" sct oldval ${data} sct update ${data} sct utime readtime } return ${nextState} } catch_message ] handle_exception ${catch_status} ${catch_message} } # function to write a parameter value on a device proc ::scobj::west_6100::setValue {tc_root nextState cmd_str} { set catch_status [ catch { debug_log ${tc_root} 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" if { [hpropexists [sct] geterror] } { hdelprop [sct] geterror } set par [sct target] set cmd "${cmd_str}${par}" # setValue hook code goes here if { [hpropexists [sct] driving] } { if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } { sct driving 1 } } debug_log ${tc_root} 1 "setValue sct send ${cmd}" if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { sct send "${cmd}" } return ${nextState} } catch_message ] handle_exception ${catch_status} ${catch_message} } # function to write a parameter value on a device proc ::scobj::west_6100::wrDecimal {tc_root nextState cmd_str} { set catch_status [ catch { debug_log ${tc_root} 1 "wrDecimal tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" if { [hpropexists [sct] geterror] } { hdelprop [sct] geterror } set par [sct target] set cmd "${cmd_str}${par}" # wrDecimal hook code starts set decimal [hval ${tc_root}/aux/decimal] set par [sct target] if { ${decimal} > 0 } { set par [expr {pow(10, ${decimal}) * ${par}}] } set par [expr {round(${par})}] set cmd "1:16:${cmd_str}:1:U16:${par}" # wrDecimal hook code ends if { [hpropexists [sct] geterror] } { debug_log ${tc_root} 9 "[sct] error: [sct geterror]" error "[sct geterror]" } if { [hpropexists [sct] driving] } { if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } { sct driving 1 } } debug_log ${tc_root} 1 "wrDecimal sct send ${cmd}" if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { sct send "${cmd}" } return ${nextState} } catch_message ] handle_exception ${catch_status} ${catch_message} } # function to write a parameter value on a device proc ::scobj::west_6100::wrInteger {tc_root nextState cmd_str} { set catch_status [ catch { debug_log ${tc_root} 1 "wrInteger tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" if { [hpropexists [sct] geterror] } { hdelprop [sct] geterror } set par [sct target] set cmd "${cmd_str}${par}" # wrInteger hook code starts set cmd "1:16:${cmd_str}:1:U16:${par}" # wrInteger hook code ends if { [hpropexists [sct] geterror] } { debug_log ${tc_root} 9 "[sct] error: [sct geterror]" error "[sct geterror]" } if { [hpropexists [sct] driving] } { if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } { sct driving 1 } } debug_log ${tc_root} 1 "wrInteger sct send ${cmd}" if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { sct send "${cmd}" } return ${nextState} } catch_message ] handle_exception ${catch_status} ${catch_message} } proc ::scobj::west_6100::mkDriver { sct_controller name device_class simulation_flag ip_address tcp_port id } { ::scobj::west_6100::sics_log 9 "::scobj::west_6100::mkDriver ${sct_controller} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id}" set ns "[namespace current]" set catch_status [ catch { MakeSICSObj ${name} SCT_OBJECT sicslist setatt ${name} klass ${device_class} sicslist setatt ${name} long_name ${name} set scobj_hpath /sics/${name} hfactory ${scobj_hpath}/alarm1 plain user float hsetprop ${scobj_hpath}/alarm1 read ${ns}::getDecimal ${scobj_hpath} rdDecimal {13} hsetprop ${scobj_hpath}/alarm1 rdDecimal ${ns}::rdDecimal ${scobj_hpath} hsetprop ${scobj_hpath}/alarm1 write ${ns}::wrDecimal ${scobj_hpath} noResponse {13} hsetprop ${scobj_hpath}/alarm1 noResponse ${ns}::noResponse ${scobj_hpath} hsetprop ${scobj_hpath}/alarm1 check ${ns}::checkrange ${scobj_hpath} hsetprop ${scobj_hpath}/alarm1 control true hsetprop ${scobj_hpath}/alarm1 data true hsetprop ${scobj_hpath}/alarm1 mutable true hsetprop ${scobj_hpath}/alarm1 nxsave true hsetprop ${scobj_hpath}/alarm1 oldval 0.0 hsetprop ${scobj_hpath}/alarm1 klass "parameter" hsetprop ${scobj_hpath}/alarm1 sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/alarm1 type "part" hsetprop ${scobj_hpath}/alarm1 nxalias "${name}_alarm1" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/alarm1 1 ${sct_controller} write ${scobj_hpath}/alarm1 hsetprop ${scobj_hpath}/alarm1 simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/alarm1 simulated true } hfactory ${scobj_hpath}/alarm2 plain user float hsetprop ${scobj_hpath}/alarm2 read ${ns}::getDecimal ${scobj_hpath} rdDecimal {14} hsetprop ${scobj_hpath}/alarm2 rdDecimal ${ns}::rdDecimal ${scobj_hpath} hsetprop ${scobj_hpath}/alarm2 write ${ns}::wrDecimal ${scobj_hpath} noResponse {14} hsetprop ${scobj_hpath}/alarm2 noResponse ${ns}::noResponse ${scobj_hpath} hsetprop ${scobj_hpath}/alarm2 check ${ns}::checkrange ${scobj_hpath} hsetprop ${scobj_hpath}/alarm2 control true hsetprop ${scobj_hpath}/alarm2 data true hsetprop ${scobj_hpath}/alarm2 mutable true hsetprop ${scobj_hpath}/alarm2 nxsave true hsetprop ${scobj_hpath}/alarm2 oldval 0.0 hsetprop ${scobj_hpath}/alarm2 klass "parameter" hsetprop ${scobj_hpath}/alarm2 sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/alarm2 type "part" hsetprop ${scobj_hpath}/alarm2 nxalias "${name}_alarm2" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/alarm2 1 ${sct_controller} write ${scobj_hpath}/alarm2 hsetprop ${scobj_hpath}/alarm2 simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/alarm2 simulated true } hfactory ${scobj_hpath}/power plain user int hsetprop ${scobj_hpath}/power read ${ns}::getInteger ${scobj_hpath} rdInteger {3} hsetprop ${scobj_hpath}/power rdInteger ${ns}::rdInteger ${scobj_hpath} hsetprop ${scobj_hpath}/power control true hsetprop ${scobj_hpath}/power data true hsetprop ${scobj_hpath}/power mutable true hsetprop ${scobj_hpath}/power nxsave true hsetprop ${scobj_hpath}/power oldval 0 hsetprop ${scobj_hpath}/power klass "parameter" hsetprop ${scobj_hpath}/power sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/power type "part" hsetprop ${scobj_hpath}/power nxalias "${name}_power" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/power 1 hsetprop ${scobj_hpath}/power simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/power simulated true } hfactory ${scobj_hpath}/powermax plain user int hsetprop ${scobj_hpath}/powermax read ${ns}::getInteger ${scobj_hpath} rdInteger {20} hsetprop ${scobj_hpath}/powermax rdInteger ${ns}::rdInteger ${scobj_hpath} hsetprop ${scobj_hpath}/powermax write ${ns}::wrInteger ${scobj_hpath} noResponse {20} hsetprop ${scobj_hpath}/powermax noResponse ${ns}::noResponse ${scobj_hpath} hsetprop ${scobj_hpath}/powermax check ${ns}::checkrange ${scobj_hpath} hsetprop ${scobj_hpath}/powermax control true hsetprop ${scobj_hpath}/powermax data true hsetprop ${scobj_hpath}/powermax mutable true hsetprop ${scobj_hpath}/powermax nxsave true hsetprop ${scobj_hpath}/powermax oldval 0 hsetprop ${scobj_hpath}/powermax klass "parameter" hsetprop ${scobj_hpath}/powermax sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/powermax type "part" hsetprop ${scobj_hpath}/powermax nxalias "${name}_powermax" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/powermax 1 ${sct_controller} write ${scobj_hpath}/powermax hsetprop ${scobj_hpath}/powermax simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/powermax simulated true } hfactory ${scobj_hpath}/ramprate plain user float hsetprop ${scobj_hpath}/ramprate read ${ns}::getDecimal ${scobj_hpath} rdDecimal {24} hsetprop ${scobj_hpath}/ramprate rdDecimal ${ns}::rdDecimal ${scobj_hpath} hsetprop ${scobj_hpath}/ramprate write ${ns}::wrDecimal ${scobj_hpath} noResponse {24} hsetprop ${scobj_hpath}/ramprate noResponse ${ns}::noResponse ${scobj_hpath} hsetprop ${scobj_hpath}/ramprate check ${ns}::checkrange ${scobj_hpath} hsetprop ${scobj_hpath}/ramprate control true hsetprop ${scobj_hpath}/ramprate data true hsetprop ${scobj_hpath}/ramprate mutable true hsetprop ${scobj_hpath}/ramprate nxsave true hsetprop ${scobj_hpath}/ramprate oldval 0.0 hsetprop ${scobj_hpath}/ramprate klass "parameter" hsetprop ${scobj_hpath}/ramprate sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/ramprate type "part" hsetprop ${scobj_hpath}/ramprate nxalias "${name}_ramprate" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/ramprate 1 ${sct_controller} write ${scobj_hpath}/ramprate hsetprop ${scobj_hpath}/ramprate simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/ramprate simulated true } hfactory ${scobj_hpath}/sensor plain user float hsetprop ${scobj_hpath}/sensor read ${ns}::getDecimal ${scobj_hpath} rdDecimal {1} hsetprop ${scobj_hpath}/sensor rdDecimal ${ns}::rdDecimal ${scobj_hpath} hsetprop ${scobj_hpath}/sensor control true hsetprop ${scobj_hpath}/sensor data true hsetprop ${scobj_hpath}/sensor mutable true hsetprop ${scobj_hpath}/sensor nxsave true hsetprop ${scobj_hpath}/sensor permlink data_set "T[format "%02d" ${id}]S01" hsetprop ${scobj_hpath}/sensor @description "T[format "%02d" ${id}]S01" hsetprop ${scobj_hpath}/sensor oldval 0.0 hsetprop ${scobj_hpath}/sensor klass "parameter" hsetprop ${scobj_hpath}/sensor sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/sensor type "part" hsetprop ${scobj_hpath}/sensor nxalias "${name}_sensor" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/sensor 1 hsetprop ${scobj_hpath}/sensor simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/sensor simulated true } hfactory ${scobj_hpath}/setpoint plain user float hsetprop ${scobj_hpath}/setpoint read ${ns}::getDecimal ${scobj_hpath} rdDecimal {2} hsetprop ${scobj_hpath}/setpoint rdDecimal ${ns}::rdDecimal ${scobj_hpath} hsetprop ${scobj_hpath}/setpoint write ${ns}::wrDecimal ${scobj_hpath} noResponse {2} hsetprop ${scobj_hpath}/setpoint noResponse ${ns}::noResponse ${scobj_hpath} hsetprop ${scobj_hpath}/setpoint check ${ns}::checkrange ${scobj_hpath} hsetprop ${scobj_hpath}/setpoint driving 0 hsetprop ${scobj_hpath}/setpoint checklimits ${ns}::checklimits ${scobj_hpath} hsetprop ${scobj_hpath}/setpoint checkstatus ${ns}::checkstatus ${scobj_hpath} hsetprop ${scobj_hpath}/setpoint halt ${ns}::halt ${scobj_hpath} hsetprop ${scobj_hpath}/setpoint driveable sensor hsetprop ${scobj_hpath}/setpoint control true hsetprop ${scobj_hpath}/setpoint data true hsetprop ${scobj_hpath}/setpoint mutable true hsetprop ${scobj_hpath}/setpoint nxsave true hsetprop ${scobj_hpath}/setpoint lowerlimit 0 hsetprop ${scobj_hpath}/setpoint upperlimit 1600 hsetprop ${scobj_hpath}/setpoint tolerance 1 hsetprop ${scobj_hpath}/setpoint permlink data_set "T[format "%02d" ${id}]SP01" hsetprop ${scobj_hpath}/setpoint @description "T[format "%02d" ${id}]SP01" hsetprop ${scobj_hpath}/setpoint oldval 0.0 hsetprop ${scobj_hpath}/setpoint klass "parameter" hsetprop ${scobj_hpath}/setpoint sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/setpoint settle_time "30" hsetprop ${scobj_hpath}/setpoint type "drivable" hsetprop ${scobj_hpath}/setpoint nxalias "${name}_setpoint" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/setpoint 1 ${sct_controller} write ${scobj_hpath}/setpoint hsetprop ${scobj_hpath}/setpoint simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/setpoint simulated true } hfactory ${scobj_hpath}/w_sp plain user float hsetprop ${scobj_hpath}/w_sp read ${ns}::getDecimal ${scobj_hpath} rdDecimal {21} hsetprop ${scobj_hpath}/w_sp rdDecimal ${ns}::rdDecimal ${scobj_hpath} hsetprop ${scobj_hpath}/w_sp write ${ns}::wrDecimal ${scobj_hpath} noResponse {21} hsetprop ${scobj_hpath}/w_sp noResponse ${ns}::noResponse ${scobj_hpath} hsetprop ${scobj_hpath}/w_sp check ${ns}::checkrange ${scobj_hpath} hsetprop ${scobj_hpath}/w_sp control true hsetprop ${scobj_hpath}/w_sp data true hsetprop ${scobj_hpath}/w_sp mutable true hsetprop ${scobj_hpath}/w_sp nxsave true hsetprop ${scobj_hpath}/w_sp oldval 0.0 hsetprop ${scobj_hpath}/w_sp klass "parameter" hsetprop ${scobj_hpath}/w_sp sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/w_sp type "part" hsetprop ${scobj_hpath}/w_sp nxalias "${name}_w_sp" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/w_sp 1 ${sct_controller} write ${scobj_hpath}/w_sp hsetprop ${scobj_hpath}/w_sp simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/w_sp simulated true } hsetprop ${scobj_hpath} data "true" hsetprop ${scobj_hpath} klass "@none" hsetprop ${scobj_hpath} type "part" ansto_makesctdrive ${name}_setpoint ${scobj_hpath}/setpoint ${scobj_hpath}/sensor ${sct_controller} hfactory ${scobj_hpath}/aux plain spy none hfactory ${scobj_hpath}/aux/decimal plain user int hsetprop ${scobj_hpath}/aux/decimal read ${ns}::getInteger ${scobj_hpath} rdInteger {18} hsetprop ${scobj_hpath}/aux/decimal rdInteger ${ns}::rdInteger ${scobj_hpath} hsetprop ${scobj_hpath}/aux/decimal control false hsetprop ${scobj_hpath}/aux/decimal data false hsetprop ${scobj_hpath}/aux/decimal mutable false hsetprop ${scobj_hpath}/aux/decimal nxsave false hsetprop ${scobj_hpath}/aux/decimal oldval 0 hset ${scobj_hpath}/aux/decimal 0 hsetprop ${scobj_hpath}/aux/decimal sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/aux/decimal type "part" hsetprop ${scobj_hpath}/aux/decimal nxalias "${name}_aux_decimal" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/aux/decimal 2 hsetprop ${scobj_hpath}/aux/decimal simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/aux/decimal simulated true } hfactory ${scobj_hpath}/aux/instatus plain user int hsetprop ${scobj_hpath}/aux/instatus read ${ns}::getInteger ${scobj_hpath} rdInteger {133} hsetprop ${scobj_hpath}/aux/instatus rdInteger ${ns}::rdInteger ${scobj_hpath} hsetprop ${scobj_hpath}/aux/instatus control false hsetprop ${scobj_hpath}/aux/instatus data false hsetprop ${scobj_hpath}/aux/instatus mutable false hsetprop ${scobj_hpath}/aux/instatus nxsave false hsetprop ${scobj_hpath}/aux/instatus oldval 0 hsetprop ${scobj_hpath}/aux/instatus sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/aux/instatus type "part" hsetprop ${scobj_hpath}/aux/instatus nxalias "${name}_aux_instatus" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/aux/instatus 2 hsetprop ${scobj_hpath}/aux/instatus simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/aux/instatus simulated true } hfactory ${scobj_hpath}/aux/model plain user int hsetprop ${scobj_hpath}/aux/model read ${ns}::getInteger ${scobj_hpath} rdInteger {122} hsetprop ${scobj_hpath}/aux/model rdInteger ${ns}::rdInteger ${scobj_hpath} hsetprop ${scobj_hpath}/aux/model control false hsetprop ${scobj_hpath}/aux/model data false hsetprop ${scobj_hpath}/aux/model mutable false hsetprop ${scobj_hpath}/aux/model nxsave false hsetprop ${scobj_hpath}/aux/model oldval 0 hsetprop ${scobj_hpath}/aux/model sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/aux/model type "part" hsetprop ${scobj_hpath}/aux/model nxalias "${name}_aux_model" if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/aux/model 2 hsetprop ${scobj_hpath}/aux/model simulated false } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for west_6100" hsetprop ${scobj_hpath}/aux/model simulated true } hsetprop ${scobj_hpath}/aux data "false" hsetprop ${scobj_hpath}/aux klass "@none" hsetprop ${scobj_hpath}/aux type "part" hsetprop ${scobj_hpath} klass ${device_class} hsetprop ${scobj_hpath} data true hsetprop ${scobj_hpath} debug_threshold 5 # mkDriver hook code goes here } catch_message ] handle_exception ${catch_status} ${catch_message} } proc ::scobj::west_6100::add_driver {name device_class simulation_flag ip_address tcp_port id} { set catch_status [ catch { ::scobj::west_6100::sics_log 9 "::scobj::west_6100::add_driver ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id}" if {[string equal -nocase "${simulation_flag}" "false"]} { if {[string equal -nocase "aqadapter" "${ip_address}"]} { ::scobj::west_6100::sics_log 9 "makesctcontroller sct_${name} aqadapter ${tcp_port}" makesctcontroller sct_${name} aqadapter ${tcp_port} } else { ::scobj::west_6100::sics_log 9 "makesctcontroller sct_${name} modbus_ap ${ip_address}:${tcp_port}" makesctcontroller sct_${name} modbus_ap ${ip_address}:${tcp_port} } } else { ::scobj::west_6100::sics_log 9 "simulation_flag=${simulation_flag} => Null sctcontroller for west_6100" ::scobj::west_6100::sics_log 9 "makesctcontroller sct_${name} aqadapter NULL" makesctcontroller sct_${name} aqadapter NULL } ::scobj::west_6100::sics_log 1 "::scobj::west_6100::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id}" ::scobj::west_6100::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id} } catch_message ] handle_exception ${catch_status} ${catch_message} } namespace eval ::scobj::west_6100 { namespace export debug_threshold namespace export debug_log namespace export sics_log namespace export mkDriver namespace export add_driver } proc add_west_6100 {name ip_address tcp_port id} { set simulation_flag "[string tolower [SplitReply [environment_simulation]]]" ::scobj::west_6100::add_driver ${name} "environment" ${simulation_flag} ${ip_address} ${tcp_port} ${id} } clientput "file evaluation of sct_west_6100.tcl" ::scobj::west_6100::sics_log 9 "file evaluation of sct_west_6100.tcl" proc ::scobj::west_6100::read_config {} { set catch_status [ catch { set ns "::scobj::west_6100" dict for {k u} $::config_dict { if { [dict exists $u "implementation"] } { set simulation_flag "[string tolower [SplitReply [environment_simulation]]]" set device_class "environment" if { !([dict exists $u "name"] && [dict exists $u "enabled"]) } { continue } set enabled [string tolower [dict get $u "enabled"]] if { ! ([string equal -nocase $enabled "true" ] || [string equal -nocase $enabled "always"]) } { continue } if { [dict exists $u "simulation_group"] } { set simulation_flag [SplitReply [[string tolower [dict get $u "simulation_group"]]]] } if { [dict exists $u "device_class"] } { set device_class "[dict get $u "device_class"]" } set name [dict get $u name] set implementation [dict get $u "implementation"] if { !([dict exists $::config_dict $implementation]) } { continue } set v [dict get $::config_dict $implementation] if { !([dict exists $v "driver"]) } { continue } if { [string equal -nocase [dict get $v "driver"] "west_6100"] } { if { ![string equal -nocase "${simulation_flag}" "false"] } { set asyncqueue "null" ${ns}::sics_log 9 "simulation_flag=${simulation_flag} => using null asyncqueue" ${ns}::sics_log 9 "makesctcontroller sct_${name} aqadapter NULL" makesctcontroller sct_${name} aqadapter NULL } elseif { [dict exists $v "asyncqueue"] } { set asyncqueue [dict get $v "asyncqueue"] if { [string equal -nocase ${asyncqueue} "sct"] } { set ip_address [dict get $v ip] set tcp_port [dict get $v port] makesctcontroller sct_${name} modbus_ap ${ip_address}:${tcp_port} } else { makesctcontroller sct_${name} aqadapter ${asyncqueue} } } else { if { [dict exists $v "asyncprotocol"] } { set asyncprotocol [dict get $v "asyncprotocol"] } else { set asyncprotocol ${name}_protocol MakeAsyncProtocol ${asyncprotocol} if { [dict exists $v "sendterminator"] } { ${asyncprotocol} sendterminator "[dict get $v "sendterminator"]" } elseif { [dict exists $v "terminator"] } { ${asyncprotocol} sendterminator "[dict get $v "terminator"]" } if { [dict exists $v "replyterminator"] } { ${asyncprotocol} replyterminator "[dict get $v "replyterminator"]" } elseif { [dict exists $v "terminator"] } { ${asyncprotocol} replyterminator "[dict get $v "terminator"]" } } set asyncqueue ${name}_queue set ip_address [dict get $v ip] set tcp_port [dict get $v port] MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${ip_address} ${tcp_port} if { [dict exists $v "timeout"] } { ${asyncqueue} timeout "[dict get $v "timeout"]" } makesctcontroller sct_${name} aqadapter ${asyncqueue} } set arg_list [list] set missing_list [list] foreach arg {id} { if {[dict exists $u $arg]} { lappend arg_list "[dict get $u $arg]" } elseif {[dict exists $v $arg]} { lappend arg_list "[dict get $v $arg]" } else { ${ns}::sics_log 9 "Missing configuration value $arg" lappend missing_list $arg } } if { [llength $missing_list] > 0 } { error "$name is missing configuration values $missing_list" } ${ns}::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} {*}$arg_list } } } } catch_message ] handle_exception ${catch_status} ${catch_message} } if { [info exists ::config_dict] } { ::scobj::west_6100::read_config } else { ::scobj::west_6100::sics_log 5 "No config dict" }