Files
sics/site_ansto/instrument/dmc2280_util.tcl
Ferdi Franceschini 1999d88cda Added revision info
r1101 | ffr | 2006-09-01 14:52:58 +1000 (Fri, 01 Sep 2006) | 2 lines
2012-11-15 12:46:53 +11:00

55 lines
1.6 KiB
Tcl

# $Revision: 1.3 $
# $Date: 2006-09-01 04:52:58 $
# Author: Ferdi Franceschini (ffr@ansto.gov.au)
# Last revision by $Author: ffr $
# 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 dmc_connect {contName {host ""} {port ""}} {
upvar #0 $contName controller
if {$host == ""} {set host $controller(host)}
if {$port == ""} {set port $controller(port)}
if [catch {socket $host $port} con] {
error "Failed to connect to $contName IP($host) port($port)\n\
$con\n
Is the motor controller switched on? Are the network cables plugged in?"
}
set controller(socket) $con
fconfigure $controller(socket) -buffering line -translation crlf -blocking true
}
# Send a dmc2280 command
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 dmc_receive {contName} {
upvar #0 $contName controller
gets $controller(socket) line
# Consume the following colon
read $controller(socket) 1
return $line
}