Files
sics/site_ansto/instrument/dmc2280_util.tcl
Ferdi Franceschini ccd6337687 Provides connect, send and receive functions for DMC2280
r1093 | ffr | 2006-08-31 16:28:37 +1000 (Thu, 31 Aug 2006) | 2 lines
2012-11-15 12:46:34 +11:00

39 lines
1.0 KiB
Tcl

# 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
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 channel($contName) $con
fconfigure $channel($contName) -buffering line -translation crlf -blocking true
}
# Send a dmc2280 command
proc sendCmd {chan cmd} {
puts $chan $cmd
set status [read $chan 1]
if {$status == "?"} {
error "error: dmc command $cmd failed"
} else {
return $status
}
}
# Receive a dmc2280 command
proc receive {chan} {
gets $chan line
# Consume the following colon
read $chan 1
return $line
}