Channel Access in TclTk Advanced EPICS Training Dirk

  • Slides: 15
Download presentation
Channel Access in Tcl/Tk Advanced EPICS Training, Dirk Zimoch 2008

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

Channel Access in Tcl/Tk Contents ■ Tcl/Tk overview ■ Graphical user interfaces ► pep

Channel Access in Tcl/Tk Contents ■ Tcl/Tk overview ■ Graphical user interfaces ► pep ► pv. Assign ► SLS widgets ■ Direct EPICS access ► pvget, pvput, pvmon ■ Problems ■ References Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk What is Tcl/Tk? ■ Tcl is a scripting programming language.

Channel 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. Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk quick start ■ Tcl is easy ■ Tk makes GUI

Channel Access in 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 Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk Graphical user interfaces in Tcl/Tk: pep ■ pep -mc X

Channel Access in Tcl/Tk Graphical user interfaces in Tcl/Tk: pep ■ pep -mc X 11 MA-ID 1 -CHU 1: I-SET ► connects magnet control widget to X 11 MA-ID 1 -CHU 1: ISET ■ pep ■ X 11 MA-ID 1 -CHU 1: I-SET ► asks what widget type to connect to X 11 MA-ID 1 -CHU 1: ISET pep –f configfile ► loads configfile. prc from. or $SLSBASE/sls/config/panel ► Try files from /work/sls/config/panel Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk Beyond pep: Write your own Tcl-GUI with pv. Assign ■

Channel Access in Tcl/Tk Beyond pep: Write your own Tcl-GUI with pv. Assign ■ Start wish and load pv. Assign package require pv. Assign ■ Create Widget label. temperature pack. temperature ■ Connect EPICS channel pv. Assign. temperature MTRT 1 -TEMP: READ ■ Enjoy the features ► See value and alarm updates ► Try right click and middle click Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk Supported widget types ■ Standard Tcl/Tk widgets ■ Special SLS

Channel Access in Tcl/Tk Supported widget types ■ Standard Tcl/Tk widgets ■ Special SLS widgets ► label ● display string/number ► entry ● set string/number ► checkbutton ● set bit ► menubutton ● set enum with menu ► scale ● set number with slider ► 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 packages Advanced EPICS Training, Dirk Zimoch 2008 package require Wheelswitch

Channel Access in Tcl/Tk SLS Widgets types: Formattedlabel ■ Use standalone Formattedlabel package require

Channel Access in Tcl/Tk SLS Widgets types: Formattedlabel ■ Use standalone Formattedlabel package require Formattedlabel formattedlabel. fl -bg pale. Green -format "%9. 4 f m. A" pack. fl set 3. 14159265359 ■ Use Formattedlabel with EPICS package require pv. Assign package require Formattedlabel formattedlabel. temp 1 -bg pale. Green pack. temp 1 pvassign. temp 1 MTRT 1 -LI-COOL: TEMP 1 Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk SLS Widgets types: Wheelswitch ■ Use standalone Wheelswitch package require

Channel Access in Tcl/Tk SLS Widgets types: Wheelswitch ■ Use standalone Wheelswitch package require Wheelswitch wheelswitch. ws -bg pale. Green -format 9. 4 -label m. A -min -100 -max -100 -command puts pack. ws set 3. 14159265359 ■ Use Wheelswitch with EPICS package require pv. Assign package require Wheelswitch wheelswitch. limit -bg pale. Green pack. limit pvassign. limit MTRT 1 -LI-COOL: LIMIT Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk SLS Widgets types: Led ■ Use standalone Led package require

Channel Access in Tcl/Tk SLS Widgets types: Led ■ Use standalone Led package require Led led -color red pack. led ■ Use Led with EPICS package require pv. Assign package require Led led. status pack. status pvassign. status MTRT 1 -LI-COOL: SW Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk Beyond pv. Assign: direct EPICS access ■ Load EPICS package

Channel Access in Tcl/Tk Beyond pv. Assign: direct EPICS access ■ Load EPICS package (which is also used by pv. Assign) package require Epics ■ Read value pvget MTRT 1 -LI-COOL: TEMP 1 -format ■ Write value pvput MTRT 1 -LI-COOL: LIMIT 10 ■ Crate monitor pvmon MTRT 1 -LI-COOL: TEMP 1 update. Temp 1 ► Monitors need a callback procedure (here: update. Temp 1) Training, Dirk Zimoch 2008 proc update. Temp 1 {iostate value. Advanced sevr. EPICS stat time}

Channel Access in Tcl/Tk Monitor example #!/usr/bin/tclsh package require Epics proc update. Value {channel

Channel Access in Tcl/Tk Monitor example #!/usr/bin/tclsh package require Epics proc update. Value {channel iostate value sevr stat time} { if {$iostate != "OK"} { puts "$channel disconnected" return } if {$sevr != "NO_ALARM"} { puts "$channel has $sevr alarm because of $status" } puts "$time $channel = $value" } set device MTEST-VME-T 1 foreach property {UPTIME LOAD WD} { set channel $device: $property pvmon $channel "update. Value $channel" } vwait forever Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk Frequently asked questions about monitors ■ Why can't I simply

Channel 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 Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk Problems with Tcl and EPICS ■ What if package require

Channel Access in Tcl/Tk Problems with Tcl and EPICS ■ What if package require Epics (or pv. Assign) 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. Advanced EPICS Training, Dirk Zimoch 2008

Channel Access in Tcl/Tk Where can I learn more about Tcl/Tk? ■ First try

Channel 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 Advanced EPICS Training, Dirk Zimoch 2008