7.2.2 Description
This example opens a TCP connection, kills the XY group, then initializes and homes
the group. Five relative moves of 1 unit each are commanded to the group. Then, the
value of the GPIO1 digital input is read in a continuous loop and sent to the redirected
stdout as long as the value of the input is not 255 (Refer to Section 4, Principle of a
Tcl script redirection to a telnet session ). When the value of the digital GPIO1 input is
equal to 1, absolute moves are commanded to both axes: the X positioner moves to the
absolute position 1 and the Y positioner moves to the absolute position -1. When the
value of 255 is obtained, the last display occurs. Finally, the program ends by closing
the socket. If the GPIO1 input value is 255 during the first reading, the program goes to
the end without displaying the digital input value.
Please see the Section 6, Proposed function for error handling.
7.2.3 Tcl Code
# Set channel’s name to be used for telnet.
# In this example we assume it is passed to the script as the
# first argument, if not specified output to stdio.
# Open the channel for read mode and get its id,
# this is the id that will be passed to puts function.
if {$tcl_argv(0) != 0} {
set telnetOut [ open "/dev/$tcl_argv(0)" r+]
} else {
set telnetOut stdout
}
# Initialization
set TimeOut 60
set group "alignstation"
set axis1 "alignstation.middle"
set axis2 "alignstation.base"
set digitalin "GPIO1.DI"
# Open socket
set code [catch "OpenConnection $TimeOut socketID"]
if {$code != 0} {
puts $telnetOut "OpenConnection failed => $code"
# Force transfer to channel’s output buffer
flush $telnetOut
} else {
# Kill group
set code [catch "GroupKill $socketID $group"]
if {$code != 0} {
DisplayErrorAndClose $socketID $code "GroupKill" $telnetOut
return
}
EDH0307En1041 — 10/17
26