XPS-Q8
Tcl Manual
# Initialization
set
TCPTimeOut
60
set
code
0
set
ISRPeriodSec
0.0001
set
Positioner "SINGLE_AXIS.MY_STAGE"
set
TimerName "Timer1"
set
TimerPeriodSec
2
set
EvtParam
0
set
Action "ExecuteTCLScript"
set
TCLFile "MyScript.tcl"
set
TCLTask "MyTask"
set
GlobalVarNumber
1
set
Value
5
# Open TCP socket
set
code [
catch
"
OpenConnection
$TCPTimeOut socketID"]
if
{$code !=
0
} {
puts
$telnetOut "OpenConnection failed => $code"
flush
$telnetOut
}
else
{
# Calculate divisor (periods are in seconds)
set
Divisor [expr {$TimerPeriodSec / $ISRPeriodSec}]
puts
$telnetOut "Divisor: $Divisor"
flush
$telnetOut
set
Divisor [expr {int($Divisor)} ]
puts
$telnetOut "Divisor troncated in integer: $Divisor"
flush
$telnetOut
# Configure a timer
set
code [
catch
"
TimerSet
$socketID $TimerName $Divisor"]
if
{$code !=
0
} {
DisplayErrorAndClose
$socketID $code "TimerSet" $telnetOut
return
}
else
{
puts
$telnetOut "Timer set"
flush
$telnetOut
}
# Add timer event with an action that allows to execute
# “MyScript.tcl”
set
code [
catch
"
EventAdd
$socketID $Positioner $TimerName
$EvtParam $Action $TCLFile $TCLTask $tcl_argv(
0
)"]
if
{$code !=
0
} {
DisplayErrorAndClose
$socketID $code "EventAdd" $telnetOut
return
}
# Set global variable
set
code [
catch
"
GlobalArraySet
$socketID $GlobalVarNumber $Value"]
if
{$code !=
0
} {
DisplayErrorAndClose
$socketID $code "GlobalArraySet"
$telnetOut
return
}
# close TCP socket
set
code [
catch
"TCP_CloseSocket $socketID"]
}
EDH0307En1041 — 10/17
54