Provides connect, send and receive functions for DMC2280

r1093 | ffr | 2006-08-31 16:28:37 +1000 (Thu, 31 Aug 2006) | 2 lines
This commit is contained in:
Ferdi Franceschini
2006-08-31 16:28:37 +10:00
committed by Douglas Clowes
parent ffd898cf16
commit ccd6337687

View File

@@ -0,0 +1,38 @@
# 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
}