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
This commit is contained in:
committed by
Douglas Clowes
parent
07967e0201
commit
7bdd25b248
@@ -1,8 +1,7 @@
|
|||||||
# Open a communications channel to a dmc2280 motor controller
|
# Open a communications channel to a dmc2280 motor controller
|
||||||
# contName: controller name, eg dmc2280_controller1
|
# contName: controller name, eg dmc2280_controller1
|
||||||
# The host and port in the SICS configuration file will be used by default
|
# The host and port in the SICS configuration file will be used by default
|
||||||
proc connect {contName {host ""} {port ""}} {
|
proc dmc_connect {contName {host ""} {port ""}} {
|
||||||
global channel
|
|
||||||
upvar #0 $contName controller
|
upvar #0 $contName controller
|
||||||
|
|
||||||
if {$host == ""} {set host $controller(host)}
|
if {$host == ""} {set host $controller(host)}
|
||||||
@@ -13,26 +12,38 @@ proc connect {contName {host ""} {port ""}} {
|
|||||||
$con\n
|
$con\n
|
||||||
Is the motor controller switched on? Are the network cables plugged in?"
|
Is the motor controller switched on? Are the network cables plugged in?"
|
||||||
}
|
}
|
||||||
set channel($contName) $con
|
set controller(socket) $con
|
||||||
fconfigure $channel($contName) -buffering line -translation crlf -blocking true
|
fconfigure $controller(socket) -buffering line -translation crlf -blocking true
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send a dmc2280 command
|
# Send a dmc2280 command
|
||||||
proc sendCmd {chan cmd} {
|
proc dmc_sendCmd {contName cmd} {
|
||||||
puts $chan $cmd
|
upvar #0 $contName controller
|
||||||
set status [read $chan 1]
|
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 == "?"} {
|
if {$status == "?"} {
|
||||||
error "error: dmc command $cmd failed"
|
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 {
|
} else {
|
||||||
return $status
|
return $status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Receive a dmc2280 command
|
# Receive a dmc2280 command
|
||||||
proc receive {chan} {
|
proc dmc_receive {contName} {
|
||||||
gets $chan line
|
upvar #0 $contName controller
|
||||||
|
gets $controller(socket) line
|
||||||
# Consume the following colon
|
# Consume the following colon
|
||||||
read $chan 1
|
read $controller(socket) 1
|
||||||
return $line
|
return $line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user