XPS-Q8
Tcl Manual
MyScript.tcl
# 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
TCPTimeOut 6
0
set
code
0
set
GlobalVarNumber 1
set
ReadValue
0
set
NewValue
0
set
END
10
set
Positioner "SINGLE_AXIS.MY_STAGE"
set
EventName "Timer1"
set
EventPara
0
# Open TCP socket
set
code [
catch
"
OpenConnection
$TCPTimeOut socketID"]
if
{$code !=
0
} {
puts
"OpenConnection failed => $code"
}
else
{
# Read global variable
set
code [
catch
"
GlobalArrayGet
$socketID $GlobalVarNumber ReadValue”]
if
{$code !=
0
} {
DisplayErrorAndClose
$socketID $code "GlobalArrayGet" $telnetOut
return
}
else
{
puts
$telnetOut "Read value: $ReadValue"
flush
$telnetOut
}
if
{$ReadValue < $END} {
# Increment global variable
set
NewValue [expr {$ReadValue
+ 1
}]
# Set global variable to a new value
set
code [
catch
"
GlobalArraySet
$socketID $GlobalVarNumb $NewValue"]
if
{$code !=
0
} {
DisplayErrorAndClose
$socketID $code "GlobalArraySet" $telnetOut
return
}
else
{
puts
$telnetOut "New value: $NewValue"
flush
$telnetOut
}
}
else
{
# Delete timer event
set
code [
catch
"
EventRemove
$socketID $Positioner $EventName
$EventPara"]
if
{$code !=
0
} {
EDH0307En1041 — 10/17
55