39 lines
1.0 KiB
Tcl
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
|
|
}
|
|
|