Add socket field to controller hash instead of using the 'channel' array.
r1098 | ffr | 2006-09-01 13:54:17 +1000 (Fri, 01 Sep 2006) | 2 lines
This commit is contained in:
committed by
Douglas Clowes
parent
07967e0201
commit
7bdd25b248
@@ -1,8 +1,7 @@
|
||||
# Open a communications channel to a dmc2280 motor controller
|
||||
# contName: controller name, eg dmc2280_controller1
|
||||
# The host and port in the SICS configuration file will be used by default
|
||||
proc connect {contName {host ""} {port ""}} {
|
||||
global channel
|
||||
proc dmc_connect {contName {host ""} {port ""}} {
|
||||
upvar #0 $contName controller
|
||||
|
||||
if {$host == ""} {set host $controller(host)}
|
||||
@@ -13,26 +12,38 @@ proc connect {contName {host ""} {port ""}} {
|
||||
$con\n
|
||||
Is the motor controller switched on? Are the network cables plugged in?"
|
||||
}
|
||||
set channel($contName) $con
|
||||
fconfigure $channel($contName) -buffering line -translation crlf -blocking true
|
||||
set controller(socket) $con
|
||||
fconfigure $controller(socket) -buffering line -translation crlf -blocking true
|
||||
}
|
||||
|
||||
# Send a dmc2280 command
|
||||
proc sendCmd {chan cmd} {
|
||||
puts $chan $cmd
|
||||
set status [read $chan 1]
|
||||
proc dmc_sendCmd {contName cmd} {
|
||||
upvar #0 $contName controller
|
||||
puts $controller(socket) $cmd
|
||||
set status [read $controller(socket) 1]
|
||||
if {$status == "?"} {
|
||||
puts $controller(socket) "TC 1"
|
||||
set status [read $controller(socket) 1]
|
||||
if {$status == "?"} {
|
||||
error "error: dmc command $cmd failed"
|
||||
} else {
|
||||
set dmcError [dmc_receive $controller(socket)]
|
||||
set errInfo "DM2280 controller $contName
|
||||
host $controller(host)
|
||||
port $controller(port)"
|
||||
error "DMC2280 ERROR $dmcError: when running command $cmd\n$errInfo"
|
||||
}
|
||||
} else {
|
||||
return $status
|
||||
}
|
||||
}
|
||||
|
||||
# Receive a dmc2280 command
|
||||
proc receive {chan} {
|
||||
gets $chan line
|
||||
proc dmc_receive {contName} {
|
||||
upvar #0 $contName controller
|
||||
gets $controller(socket) line
|
||||
# Consume the following colon
|
||||
read $chan 1
|
||||
read $controller(socket) 1
|
||||
return $line
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user