From 7bdd25b2484b9a8a7f089db34a31658f2baea181 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Fri, 1 Sep 2006 13:54:17 +1000 Subject: [PATCH] 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 --- site_ansto/instrument/dmc2280_util.tcl | 33 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/site_ansto/instrument/dmc2280_util.tcl b/site_ansto/instrument/dmc2280_util.tcl index b1a47f6f..4a3c2b1a 100644 --- a/site_ansto/instrument/dmc2280_util.tcl +++ b/site_ansto/instrument/dmc2280_util.tcl @@ -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 == "?"} { - error "error: dmc command $cmd failed" + 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 }