Generate a wrapper for the old protek driver from a protekmm.sct template.

This commit is contained in:
Ferdi Franceschini
2014-07-11 13:52:37 +10:00
parent 4f72bcaaf5
commit 867c6c8eaa
5 changed files with 168 additions and 105 deletions

View File

@ -0,0 +1,9 @@
# vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent
driver protekmm = {
protocol = protek608
class = environment
simulation_group = environment_simulation
code mkDriver = {%%
MakeProtek $name $sct_controller
%%}
}

View File

@ -60,10 +60,10 @@ proc rdStateRep {} {
array set stateArr [split $stateRep "|:"]
if {$stateArr(AUTOOFF)} {
broadcast "PROTEK608:[sct IP]:[sct PORT] WARNING AUTO OFF IS ENABLED"
broadcast "PROTEK608:[sct] WARNING AUTO OFF IS ENABLED"
}
if {$stateArr(LOBAT)} {
broadcast "PROTEK608: LOW BATTERY WARNING"
broadcast "PROTEK608:[sct] LOW BATTERY WARNING"
}
if {$stateRep != [sct oldval]} {
sct update $stateRep
@ -122,7 +122,7 @@ close $fd
# @param cbFunc, this function will be called after the voltage reading has been updated
# NOTE: If the interval is negative then the multimeter will be polled on every cycle of
# the SICS task loop.
proc MakeProtek {name IP PORT {scale 1.0} {offset 0.0} {interval 0.5} {cbFunc "return idle"}} {
proc MakeProtek {name sctName {scale 1.0} {offset 0.0} {interval 0.5} {cbFunc "return idle"}} {
set catch_status [ catch {
set sctName "sct_$name"
set sobjName "$name"
@ -149,9 +149,6 @@ proc MakeProtek {name IP PORT {scale 1.0} {offset 0.0} {interval 0.5} {cbFunc "r
::scobj::hinitprops $sobjName
sicslist setatt $sobjName long_name $name
if {[SplitReply [environment_simulation]] == false} {
makesctcontroller $sctName protek608 $IP:$PORT
hsetprop /sics/$soState/state IP $IP
hsetprop /sics/$soState/state PORT $PORT
$sctName poll /sics/$soState/state $interval
$sctName poll /sics/$sobjName $interval
}
@ -162,102 +159,11 @@ proc MakeProtek {name IP PORT {scale 1.0} {offset 0.0} {interval 0.5} {cbFunc "r
}
proc add_protekmm {name IP PORT CTYPE CID {scale 1.0} {offset 0.0} {interval 0.5} {cbFunc "return idle"}} {
set catch_status [ catch {
MakeProtek $name $IP $PORT $scale $offset $interval $cbFunc
hsetprop /sics/$name permlink data_set ${CTYPE}${CID}S1
} catch_message ] {
handle_exception ${catch_status} ${catch_message}
}
}
namespace eval ::scobj::add_protekmm {
set debug_threshold 5
}
proc ::scobj::add_protekmm::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::add_protekmm::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::add_protekmm::${debug_string}"
}
} catch_message ]
}
clientput "file evaluation of sct_protekmm.tcl"
::scobj::add_protekmm::sics_log 9 "file evaluation of sct_protekmm.tcl"
proc ::scobj::add_protekmm::read_config {} {
set catch_status [ catch {
set ns "::scobj::add_protekmm"
dict for {k v} $::config_dict {
if { [dict exists $v "implementation"] } {
if { !([dict exists $v "name"] && [dict exists $v "enabled"]) } {
continue
}
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "implementation"]
if [dict exists $v "datype"] {
set datype [dict get $v "datype"]
}
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"] "protekmm"] } {
set driver [dict get $v driver]
${ns}::sics_log 9 "Found ${name}: $driver"
if { [string equal -nocase $enabled "true" ] || [string equal -nocase $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
${ns}::sics_log 9 "${name}:${driver}: MakeAsyncProtocol ${asyncprotocol}"
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]
${ns}::sics_log 9 "${name}:${driver}: MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}"
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
set arg_list [list]
foreach arg {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"
}
}
${ns}:sics_log 9 "add_protekmm ${name} aqadapter ${asyncqueue} {*}$arg_list"
add_protekmm ${name} "aqadapter" ${asyncqueue} {*}$arg_list
}
}
}
}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::add_protekmm::read_config
} else {
::scobj::add_protekmm::sics_log 5 "No config dict"
}
# proc add_protekmm {name IP PORT CTYPE CID {scale 1.0} {offset 0.0} {interval 0.5} {cbFunc "return idle"}} {
# set catch_status [ catch {
# MakeProtek $name $IP $PORT $scale $offset $interval $cbFunc
# hsetprop /sics/$name permlink data_set ${CTYPE}${CID}S1
# } catch_message ] {
# handle_exception ${catch_status} ${catch_message}
# }
# }

View File

@ -0,0 +1,145 @@
# Generated driver for protekmm
# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
#
namespace eval ::scobj::protekmm {
set debug_threshold 5
}
proc ::scobj::protekmm::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 fd [open "../log/protekmm_[basename ${tc_root}].log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
}
} catch_message ]
}
proc ::scobj::protekmm::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::protekmm::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::protekmm::${debug_string}"
}
} catch_message ]
}
proc ::scobj::protekmm::mkDriver { sct_controller name } {
::scobj::protekmm::sics_log 9 "::scobj::protekmm::mkDriver for ${name}"
set ns "[namespace current]"
set catch_status [ catch {
MakeSICSObj ${name} SCT_OBJECT
sicslist setatt ${name} klass environment
sicslist setatt ${name} long_name ${name}
set scobj_hpath /sics/${name}
hsetprop ${scobj_hpath} klass environment
hsetprop ${scobj_hpath} debug_threshold 5
# mkDriver hook code starts
MakeProtek $name $sct_controller
# mkDriver hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::protekmm {
namespace export debug_threshold
namespace export debug_log
namespace export sics_log
namespace export mkDriver
}
proc add_protekmm {name IP port} {
set catch_status [ catch {
::scobj::protekmm::sics_log 9 "add_protekmm ${name} ${IP} ${port}"
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
::scobj::protekmm::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
::scobj::protekmm::sics_log 9 "makesctcontroller sct_${name} protek608 ${IP}:${port}"
makesctcontroller sct_${name} protek608 ${IP}:${port}
}
} else {
::scobj::protekmm::sics_log 9 "[environment_simulation] => No sctcontroller for protekmm"
}
::scobj::protekmm::sics_log 1 "::scobj::protekmm::mkDriver sct_${name} ${name}"
::scobj::protekmm::mkDriver sct_${name} ${name}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
clientput "file evaluation of sct_protekmm.tcl"
::scobj::protekmm::sics_log 9 "file evaluation of sct_protekmm.tcl"
proc ::scobj::protekmm::read_config {} {
set catch_status [ catch {
set ns "::scobj::protekmm"
dict for {k v} $::config_dict {
if { [dict exists $v "implementation"] } {
if { !([dict exists $v "name"] && [dict exists $v "enabled"]) } {
continue
}
set name [dict get $v name]
set enabled [string tolower [dict get $v "enabled"]]
set implementation [dict get $v "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"] "protekmm"] } {
if { [string equal -nocase $enabled "true" ] || [string equal -nocase $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"]
if { [string equal -nocase ${asyncqueue} "sct"] } {
set IP [dict get $v ip]
set PORT [dict get $v port]
}
} 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"]"
}
}
if { [string equal -nocase ${asyncqueue} "sct"] } {
add_protekmm ${name} ${IP} ${PORT}
} else {
add_protekmm ${name} "aqadapter" ${asyncqueue}
}
}
}
}
}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::protekmm::read_config
} else {
::scobj::protekmm::sics_log 5 "No config dict"
}

View File

@ -218,6 +218,7 @@ desc = "This is the default sample stage configuration with xy translation and p
imptype = motion_axis
[protek_01]
asyncqueue = sct
desc = "Protek Multimeter"
driver = "protekmm"
id = 1
@ -226,6 +227,7 @@ ip = 10.157.205.36
port = 4001
[protek_02]
asyncqueue = sct
desc = "Protek Multimeter"
driver = "protekmm"
id = 2

View File

@ -27,6 +27,7 @@ fileeval $cfPath(plc)/plc.tcl
fileeval $cfPath(counter)/counter.tcl
fileeval $cfPath(environment)/sct_keithley_2700.tcl
fileeval $cfPath(environment)/sct_protek_common.tcl
fileeval $cfPath(environment)/sct_protekmm.tcl
#TODO Provide method for choosing environment controller
fileeval $cfPath(environment)/temperature/sct_eurotherm_2000.tcl
fileeval $cfPath(environment)/temperature/sct_lakeshore_336.tcl