15
Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Embed Size (px)

Citation preview

Page 1: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk

Page 2: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

Contents

■ Tcl/Tk overview■Graphical user interfaces►pep►pvAssign►SLS widgets

■ Direct EPICS access►pvget, pvput, pvmon

■ Problems■ References

Page 3: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

What is Tcl/Tk?

■ Tcl is a scripting programming language.■ Tk is a widget toolkit, available for Tcl and other languages.■ It provides a command line shell: tclsh■ And a GUI shell: wish■ And a help program: tclhelp■ Tcl can be extended with so called "packages".►We provide an EPICS package for Tcl/Tk.►We also provide special widgets for Tcl/Tk.

■ Tcl is really well supported by the controls section.

Page 4: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

Tcl/Tk quick start

■ Tcl is easy■ Tk makes GUI creation simple■ Type: wish

button .b -text "Press me!" -command {puts "Hello world!"}pack .b

■ Press button■ Look in tclhelp for: button, puts, pack■Write the program in a file and add first line:

#!/usr/bin/wish

■Make file executable: chmod +x filename

Page 5: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

Graphical user interfaces in Tcl/Tk: pep■ pep -mc X11MA-ID1-CHU1:I-SET►connects magnet control widget to X11MA-ID1-CHU1:I-SET

■ pep X11MA-ID1-CHU1:I-SET►asks what widget type to connect to X11MA-ID1-CHU1:I-SET

■ pep –f configfile► loads configfile.prc from . or $SLSBASE/sls/config/panel►Try files from /work/sls/config/panel

■ Also see "How to use pep" item in Help menu.

Page 6: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

Beyond pep: Write your own Tcl-GUI with pvAssign

■ Start wish and load pvAssign packagepackage require pvAssign

■ Create Widgetlabel .temperaturepack .temperature

■ Connect EPICS channelpvAssign .temperature MTRT1-TEMP:READ

■ Enjoy the features►See value and alarm updates►Try right click and middle click

Page 7: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

Supported widget types■ Standard Tcl/Tk widgets► label● display string/number

► entry● set string/number

► checkbutton● set bit

► menubutton ● set enum with menu

► scale● set number with slider

■ Special SLS widgets► formattedlabel● display formatted number with units

► comparelabel● display = or ≠ (compare to 0)

► wheelswitch● set number

► led● show bit as LED

► choicebutton● set enum with row/column of buttons

■ Load widget packagespackage require Wheelswitch

Page 8: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

SLS Widgets types: Formattedlabel

■ Use standalone Formattedlabelpackage require Formattedlabelformattedlabel .fl -bg paleGreen -format "%9.4f mA"pack .fl.fl set 3.14159265359

■ Use Formattedlabel with EPICSpackage require pvAssignpackage require Formattedlabelformattedlabel .temp1 -bg paleGreenpack .temp1pvassign .temp1 MTRT1-LI-COOL:TEMP1

Page 9: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

SLS Widgets types: Wheelswitch

■ Use standalone Wheelswitchpackage require Wheelswitchwheelswitch .ws -bg paleGreen -format 9.4 -label mA \

-min -100 -max -100 -command putspack .ws.ws set 3.14159265359

■ Use Wheelswitch with EPICSpackage require pvAssignpackage require Wheelswitchwheelswitch .limit -bg paleGreenpack .limitpvassign .limit MTRT1-LI-COOL:LIMIT

Page 10: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

SLS Widgets types: Led

■ Use standalone Ledpackage require Ledled .led -color redpack .led

■ Use Led with EPICSpackage require pvAssignpackage require Ledled .statuspack .statuspvassign .status MTRT1-LI-COOL:SW

Page 11: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

Beyond pvAssign: direct EPICS access

■ Load EPICS package (which is also used by pvAssign)package require Epics

■ Read valuepvget MTRT1-LI-COOL:TEMP1pvget MTRT1-LI-COOL:TEMP1 -format

■Write valuepvput MTRT1-LI-COOL:LIMIT 10

■ Crate monitorpvmon MTRT1-LI-COOL:TEMP1 updateTemp1

►Monitors need a callback procedure (here: updateTemp1)proc updateTemp1 {iostate value sevr stat time}

Page 12: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

Monitor example#!/usr/bin/tclshpackage require Epics

proc updateValue {channel iostate value sevr stat time} {if {$iostate != "OK"} { puts "$channel disconnected" return } if {$sevr != "NO_ALARM"} { puts "$channel has $sevr alarm because of $stat status" } puts "$time $channel = $value"}

set device MTEST-VME-T1foreach property {UPTIME LOAD WD} { set channel $device:$property pvmon $channel "updateValue $channel"}

vwait forever

Page 13: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

Frequently asked questions about monitors

■Why can't I simply call pvget in a loop?►This creates much network overhead.► It keeps the program and the IOC busy.

■ But what about a delay in the loop?►Then you increase latency when something happens.►You still have much overhead.

■ I don't understand how the monitor function gets called.►Monitors work much the same as for example mouse clicks.►On value change, monitors are called as soon as the program is idle.

Page 14: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

Problems with Tcl and EPICS

■What if package require Epics (or pvAssign) fails?►Check environment variable TCLLIBPATH

echo $TCLLIBPATH/usr/lib/tcl /work/lib/tcl

►Check that EPICS is installed in /usr/local/epics and /work or /prod is mounted.

■Why does pvmon not work in tclsh? ►Monitors need an idle loop to work, wish has one, tclsh not.►Add vwait forever to the end of the script and it works.

Page 15: Advanced EPICS Training, Dirk Zimoch 2008 Channel Access in Tcl/Tk

Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/TkChannel Access in Tcl/Tk

Where can I learn more about Tcl/Tk?

■ First try tclhelp■ Look at www.tcl.tk■ Ask one of the Tcl experts:►Werner Portmann►Elke Zimoch►Dirk Zimoch