Files
gitea-pages/software/tclioc.html
T
2025-07-08 08:18:09 +02:00

594 lines
19 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="author" content="Dirk Zimoch">
<style type="text/css">
<!--
body { font-family:Arial,sans-serif,espy;
background:white; margin:0; }
body,p,ul,ol,dl,div,table {font-size:12pt; }
p { line-height:120%; }
pre,code,tt { font-family:"Courier New",Courier,monospace; }
code,tt { font-size:13pt; }
h1 { font-size: 24pt; margin-top:1ex; margin-bottom:0; text-align:center; }
h2 { font-size: 18pt; margin-bottom:0.5ex; }
h3 { font-size: 14pt; margin-bottom:0.5ex; }
h4 { font-size: 13pt; margin-bottom:0.5ex; }
h5 { font-size: 12pt; margin-bottom:0.5ex; }
small { font-size: 9pt; }
code { color:#0000C0; }
li { margin-top: 2pt; margin-bottom: 2pt; }
pre { font-size: 13pt;
white-space:pre; }
.box { border:1px solid #000000;
background-color:#f4f4f4;
padding:1ex;
margin: 0 2ex 1ex 2ex; font-size:90%; }
th.PageTitle {
font-size : 14pt;
font-weight : bold; }
.menuf {
font-size:11pt;
color:#333333;
font-weight:600;
text-decoration:none;
}
.menuf:link {color:#333333;}
.menuf:visited {color:#666666;}
.menuf:hover {color:#FF0000;}
.menuf:active {color:#FF0000;}
.menus, .menus a {
font-size:10pt;
color:#333333;
text-decoration:none;
}
.menus:visited, .menus a:visited {color:#666666;}
.menus:hover, .menus a:hover {color:#FF0000;}
.menus:active, .menus a:active {color:#FF0000;}
a:hover {color:#FF0000;}
.red {color:#FF0000;}
.green {color:#008000;}
.blue {color:#0000C0;}
@media screen {
.printlayout {display:none;}
}
@media print {
.screenlayout {display:none;}
code { color:#000000; }
a:link {color:#000000;text-decoration:none}
a:visited {color:#000000;text-decoration:none}
a:hover {color:#000000;text-decoration:none}
a:active {color:#000000;text-decoration:none}
}
-->
</style>
<link rel="shortcut icon" href="http://epics.web.psi.ch/images/sls_icon.ico">
<title>Tcl-IOC</title>
</head>
<body bgcolor="#FFFFFF">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr class="screenlayout">
<td bgcolor="#267ab8" colspan="5" valign="bottom" height="10">
<img
src="../images/black"
width="100%" height="1" alt=""></td>
</tr>
<tr class="screenlayout">
<td rowspan="2" colspan="2" align="center">
<a class="menuf" href="http://www.psi.ch"><img
src="../images/psi_logo" border="0"
alt="PAUL SCHERRER INSTITUT"></a></td>
<td rowspan="2"><img
src="../images/space"
width="1" height="65" alt=""></td>
<th class="PageTitle"><center>
<big>EPICS at PSI<big>
</center>
</th>
<td><img
src="../images/space"
width="10" height="1" alt=""></td>
</tr>
<tr class="screenlayout">
<th width="100%" valign="bottom" align="left">
<table border="0" cellspacing="0" cellpadding="0"><tr><td><a
href="https://www.psi.ch"
class="menuf">PSI</a></td><td><img
src="../images/space"
width="10" height="1" alt=""></td><td bgcolor="black"><img
src="../images/space"
width="1" height="1" alt=""></td><td><img
src="../images/space"
width="10" height="1" alt=""></td><td><a
href="https://www.aps.anl.gov/epics"
class="menuf">EPICS</a></td><td><img
src="../images/space"
width="10" height="1" alt=""></td><td bgcolor="black"><img
src="../images/space"
width="1" height="1" alt=""></td><td><img
src="../images/space"
width="10" height="1" alt=""></td><td><a
href="https://www.psi.ch/en/sls"
class="menuf">SLS</a></td><td><img
src="../images/space"
width="10" height="1" alt=""></td><td bgcolor="black"><img
src="../images/space"
width="1" height="1" alt=""></td><td><img
src="../images/space"
width="10" height="1" alt=""></td><td><a
href="https://www.psi.ch/en/swissfel"
class="menuf">SwissFEL</a></td><td><img
src="../images/space"
width="10" height="1" alt=""></td><td bgcolor="black"><img
src="../images/space"
width="1" height="1" alt=""></td><td><img
src="../images/space"
width="10" height="1" alt=""></td><td><a
href="https://www.psi.ch/en/protontherapy"
class="menuf">Proscan</a></td></tr></table>
</th>
</tr>
<tr class="screenlayout">
<td height="5" bgcolor="#267ab8" colspan="6" valign="bottom">
<img
src="../images/black"
width="100%" height="1" alt=""></td>
</tr>
<tr>
<td class="screenlayout" bgcolor="#e3eaf6" valign="top" align="center" width="179">
<br><a href="http://www.aps.anl.gov/epics"><img
src="../images/EPICS_small"
alt="EPICS" border=0></a><br><br>
<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td><img
src="../images/space"
width="20" height="29" alt=""></td><th width="100%" align="left"><a
href="../index.html"
class="menuf">EPICS at PSI</a>
<img
src="../images/black"
height="1" width="100%" alt=""></th></tr></table>
<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td><img
src="../images/space"
width="20" height="29" alt=""></td><th width="100%" align="left"><a
href="../software.html"
class="menuf">Software</a>
<ul style="margin:0 0 0 0; padding-left:1em;">
<li class="menus"><a href="s7plc.html"
>PLC Communication</a></li>
<li class="menus"><a href="streamdevice.html"
>StreamDevice</a></li>
<li class="menus"><a href="regDev.html"
>regDev</a></li>
<li class="menus"><a href="iocmon.html"
>IOC Monitoring</a></li>
<li class="menus"><a href="pcmon.html"
>PC Monitoring</a></li>
<li class="menus"><a href="firewire.html"
>Firewire Camera</a></li>
<li class="menus"><a href="http://dps.web.psi.ch/template.html?/psc/"
>Digital PS Control</a></li>
<li class="menus"><a href="tclioc.html"
>Tcl-IOC</a></li>
<li class="menus"><a href="iocLogBrowser.html"
>iocLogBrowser</a></li>
<li class="menus"><a href="ioc-octave.html"
>IOC-Octave</a></li>
<li class="menus"><a href="http://gfa-it.web.psi.ch/epicsSharp/"
>C# EPICS</a></li>
<li class="menus"><a href="generalTime.html"
>generalTime</a></li>
<li class="menus"><a href="GPMM.html"
>GPMM</a></li>
<li class="menus"><a href="sequencer.html"
>SNC/SEQ</a></li>
<li class="menus"><a href="caqtdm.html"
>caQtDM</a></li>
<li class="menus"><a href="CSDataQuick.html"
>CSDataQuick</a></li>
</ul>
<img
src="../images/black"
height="1" width="100%" alt=""></th></tr></table>
<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td><img
src="../images/space"
width="20" height="29" alt=""></td><th width="100%" align="left"><a
href="../training.html"
class="menuf">Training</a>
<ul style="margin:0 0 0 0; padding-left:1em;">
<li class="menus"><a href="../training/PSI-training.html"
>Courses at PSI</a></li>
<li class="menus"><a href="../training/caClientLessons.html"
>CA client lessons</a></li>
<li class="menus"><a href="../training/downloads.html"
>Downloads</a></li>
</ul>
<img
src="../images/black"
height="1" width="100%" alt=""></th></tr></table>
<form method="get" action="http://www.google.com/search">
<table border="0" cellpadding="0" cellspacing="0">
<tr><td align="center" nowrap>
<input type="search" placeholder="search" name="q" size="13" maxlength="255" value=""><br>
<input type="hidden" name="domains" value="epics.web.psi.ch">
<small>
<input type="radio" name="sitesearch" value=""> web
<input type="radio" name="sitesearch" value="epics.web.psi.ch"
checked="checked"> epics.web.psi.ch<br>
</small>
</td></tr></table>
</form><p></p><small>
Author: <a href="mailto:Dirk Zimoch &lt;dirk.zimoch&#64;psi.&#99;&#104;&gt;?subject=http://epics.web.psi.ch%2Fsoftware%2Ftclioc%2F">Dirk Zimoch</a><br>
Phone: +41 56 310 5182<br>
Updated: 02.11.2005<br>
<br><a
href="http://epics.web.psi.ch/software/tclioc/%2Fsoftware%2Ftclioc%2Findex.php?forprint"><img
src="../images/printer"
border="0" alt=""></a>
<br><a
href="http://epics.web.psi.ch/software/tclioc/%2Fsoftware%2Ftclioc%2Findex.php?forprint">Printer friendly version</a>
<br>&nbsp;</small><br><div><a href="http://validator.w3.org/check?uri=http://epics.web.psi.ch/software/tclioc/index.php&amp;ss=1"><img
border="0" src="../images/valid-html401.png"
alt="[Validate HTML]" height="31" width="88"></a><a
href="http://jigsaw.w3.org/css-validator/validator?uri=http://epics.web.psi.ch/software/tclioc/index.php"><img
style="border:0;width:88px;height:31px"
src="../images/vcss.png"
alt="[Validate CSS]"></a></div>
<br><img
src="../images/space"
width="179" height="1" alt=""></td>
<td width="1" bgcolor="#000000"><img
src="../images/space"
width="1" height="1" alt=""></td>
<td><img
src="../images/space"
width="10" height="1" alt=""></td>
<td valign="top" width="100%" colspan="2">
<a name="top"></a><center><h1>Tcl-IOC</h1></center>
<p>
Tcl-IOC provides a Tcl shell for an EPICS R3.14 IOC.
It is a replacement for <i>iocsh</i> that comes with EPICS base.
This adds the full capability of a scripting programming language
to EPICS iocCore.
Access to registered EPICS functions and variables is supported
similar to <i>iocsh</i>.
</p>
<h2>Requirements</h2>
<p>
<a href="http://tcl.sourceforge.net/" target="extern">Tcl</a>
is required and
<a href="http://tclx.sourceforge.net/" target="extern">TclX</a>
is recommended for its capability to switch from scripting mode to
interactive mode.
Alternatively, <i>wish</i>, the graphical extension to the Tcl
shell, can be used.
To build Tcl-IOC, the
<a href="http://sourceforge.net/project/showfiles.php?group_id=10894&amp;package_id=10452"
target="extern">sources</a> or the
<a href="http://www.rpmfind.net/linux/rpm2html/search.php?query=tcl-devel"
target="extern">development rpm</a> of Tcl (tcl-devel) is required
(i.e. the header file <tt>tcl.h</tt> is needed).
To run Tcl-IOC, a run time installation of
<a href="http://www.rpmfind.net/linux/rpm2html/search.php?query=tcl"
target="extern">Tcl</a> and
<a href="http://www.rpmfind.net/linux/rpm2html/search.php?query=TclX"
target="extern">TclX</a> is sufficient.
</p>
<p>
<a href="http://www.aps.anl.gov/epics/base/R3-14/7.php"
target="extern">EPICS R3.14.7</a> is required
(higher versions might also work).
</p>
<p>
Download the <a href="tclioc/tclioc.tgz">tclioc.tgz</a> package.
See below how to install it.
</p>
<p>
Tcl-IOC has been tested on the following systems:
</p>
<table border cellspacing=0 cellpadding=5>
<tr>
<th>Operating System</th>
<th>EPICS Release</th>
<th>Compiler</th>
<th>Tcl Version</th>
</tr>
<tr>
<td>Redhat Linux 6.2</td>
<td>R3.14.7</td>
<td>gcc egcs-2.91.66</td>
<td>8.0</td>
</tr>
<tr>
<td>Redhat Linux 7.3</td>
<td>R3.14.7</td>
<td>gcc 2.96</td>
<td>8.3</td>
</tr>
<tr>
<td>Scientific Linux 3.0.5</td>
<td>R3.14.7</td>
<td>gcc 3.2.3</td>
<td>8.3</td>
</tr>
<tr>
<td>Fedora Core 3</td>
<td>R3.14.7</td>
<td>gcc 3.4.3</td>
<td>8.4</td>
</tr>
</table>
<p>
It has not yet been tested on Windows systems.
If you make it run on other systems, feedback is welcome.
</p>
<h2>Features</h2>
<p>
Tcl-IOC consistes of a shared library that can be linked with an IOC
application and loaded into any Tcl shell
(<i>tclsh</i>, <i>tcl</i>, <i>wish</i>, <i>wishx</i>, <i>bltwish</i>,&nbsp;...)
with the
<a href="http://tcl.tk/man/tcl8.4/TclCmd/load.htm"
target="help"><tt>load</tt></a> command.
Loading the library automatically adds iocCore, including all EPICS
functions and variables to the Tcl shell.
</p>
<h3>Functions</h3>
<p>
For each registered EPICS function, a Tcl command with the same name
is created.
Thus, any EPICS function available in <i>iocsh</i> can be called from the
Tcl shell.
Since <i>iocsh</i> functions have <tt>void</tt> results,
the corresponding Tcl commands normally return an empty string.
Many EPICS functions write to stdout, but input and output
can be redirected:
</p>
<dl>
<dt><code>&lt; <i>filename</i></code></dt>
<dd>Stdin of the function is read from the file <i>filename</i>
which is opened for reading
</dd>
<dt><code>&gt; <i>filename</i></code></dt>
<dd>Stdout of the function is written to the file <i>filename</i>
which is opened for writing (and truncated).
</dd>
<dt><code>&gt;&gt; <i>filename</i></code></dt>
<dd>Stdout of the function is written to the file <i>filename</i>
which is opened for appending.
</dd>
<dt><code>2&gt; <i>filename</i></code></dt>
<dd>Stderr of the function is written to the file <i>filename</i>
which is opened for writing (and truncated).
</dd>
<dt><code>2&gt;&gt; <i>filename</i></code></dt>
<dd>Stderr of the function is written to the file <i>filename</i>
which is opened for appending.
</dd>
<dt><code>&lt;@ <i>fileId</i></code></dt>
<dd>Stdin of the function is read from <i>fileId</i>
which refers to a file, pipe, or socket that
must already be opened for reading.
(see <a href="http://tcl.tk/man/tcl8.4/TclCmd/open.htm"
target="help"><code>open</code></a> and
<a href="http://tcl.tk/man/tcl8.4/TclCmd/socket.htm"
target="help"><code>socket</code></a>)
</dd>
<dt><code>&gt;@ <i>fileId</i></code></dt>
<dd>Stdout of the function is written to <i>fileId</i>
which refers to a file, pipe, or socket that
must already be opened for writing or appending.
(see <a href="http://tcl.tk/man/tcl8.4/TclCmd/open.htm"
target="help"><code>open</code></a> and
<a href="http://tcl.tk/man/tcl8.4/TclCmd/socket.htm"
target="help"><code>socket</code></a>)
</dd>
<dt><code>2&gt;@ <i>fileId</i></code></dt>
<dd>Stderr of the function is written to <i>fileId</i>
which refers to a file, pipe, or socket that
must already be opened for writing or appending.
(see <a href="http://tcl.tk/man/tcl8.4/TclCmd/open.htm"
target="help"><code>open</code></a> and
<a href="http://tcl.tk/man/tcl8.4/TclCmd/socket.htm"
target="help"><code>socket</code></a>)
</dd>
<dt><code>&gt;$ <i>varName</i></code></dt>
<dd>Stdout of the function is written to the variable <i>varName</i>.
Its previous contents are cleared.
If the variable does not yet exist, it is created.
</dd>
<dt><code>&gt;&gt;$ <i>varName</i></code></dt>
<dd>Stdout of the function is appended to the variable <i>varName</i>.
If the variable does not yet exist, it is created.
</dd>
<dt><code>2&gt;$ <i>varName</i></code></dt>
<dd>Stderr of the function is written to the variable <i>varName</i>.
Its previous contents are cleared.
If the variable does not yet exist, it is created.
</dd>
<dt><code>2&gt;&gt;$ <i>varName</i></code></dt>
<dd>Stderr of the function is appended to the variable <i>varName</i>.
If the variable does not yet exist, it is created.
</dd>
<dt><code>&gt;$$</code></dt>
<dd>Stdout of the function is written to the return value.
</dd>
<dt><code>2&gt;$$</code></dt>
<dd>Stderr of the function is written to the return value.
</dd>
</dl>
<p>
Note that most EPICS functions also write error messages to stdout
instead of stderr.
</p>
<h3>Variables</h3>
<p>
Each registered EPICS variable is mapped to a global Tcl variable with
the same name.
Reading and writing of those Tcl variables is redirected
to the corresponding EPICS variable.
EPICS variables cannot be
<a href="http://tcl.tk/man/tcl8.4/TclCmd/unset.htm"
target="help"><code>unset</code></a>.
</p>
<h2>Installing Tcl-IOC</h2>
<p>
Tcl-IOC comes as a BaseApp-style EPICS R3.14 project.
It contains the following files:
</p>
<pre class="box">
tclioc
|-- Makefile
|-- myTclIocApp
| |-- Makefile
| |-- example.subs
| |-- example.template
| |-- exampleiocsh.tcl
| |-- myTclIocAppInclude.dbd
| `-- simpleiocsh.tcl
`-- src
|-- Makefile
|-- README
|-- iocUtil.c
`-- iocsh.cpp
</pre>
<p>
Unpack the project it in a <tt>&lt;TOP&gt;</tt> location and run <tt>make</tt>.
This will create a loadable library and an example application.
For further information on EPICS projects and <tt>&lt;TOP&gt;</tt> directories,
please refer to the <i>EPICS IOC Application Developer's Guide</i>
<a href="http://www.aps.anl.gov/epics/base/R3-14/7-docs/AppDevGuide.pdf">(download PDF)</a>,
Chapter 4.
</p>
<h2>Building a Tcl-IOC application</h2>
<p>
A Tcl-IOC application is similar to any other EPICS IOC application.
The differences are in the Makefile and the startup script.
An example application can be found in the <tt>myTclIocApp</tt> subdirectory.
</p>
<h3>Makefile changes</h3>
<ol>
<li>
Instead of a <code>PROD</code> executable, create a
<code>LOADABLE_LIBRARY</code>.<br>
This means, change lines like<br>
<code>PROD&nbsp;=&nbsp;<i>myApplication</i></code><br>
to<br>
<code>LOADABLE_LIBRARY&nbsp;=&nbsp;<i>myApplication</i></code><br>
Replace <code>PROD_SRCS</code>, etc. by
<code>LIBS_SRCS</code> or <code><i>myApplication</i>_SRCS</code>.
</li>
<li>
Instead of linking the application to <code>$(EPICS_BASE_IOC_LIBS)</code>,
link it to <code>tclioc</code>.<br>
That means replace<br>
<code><i>myApplication</i>_LIBS += $(EPICS_BASE_IOC_LIBS)</code><br>
with<br>
<code><i>myApplication</i>_LIBS += tclioc</code>
</li>
</ol>
<h3>Example Makefile</h3>
<p>
Differences to a standard application Makefile are marked blue.
</p>
<pre class="box">
TOP=../..
include $(TOP)/configure/CONFIG
<span class="blue">LOADABLE_LIBRARY = myApplication</span>
DBD += myApplication.dbd
myApplication_SRCS += myApplication_registerRecordDeviceDriver.cpp
<span class="blue">myApplication_LIBS += tclioc</span>
include $(TOP)/configure/RULES
</pre>
<h3>Startup script changes</h3>
<ol>
<li>
Use <code>/usr/bin/tcl</code> (or wherever TclX is installed)
as the interpreter. That means the first line should be<br>
<code>#!/usr/bin/tcl</code>
</li>
<li>
Load the application library into the Tcl interpreter and tell it
that it is a <tt>tclioc</tt> application.
Make sure that the library can be found
(e.g. set <tt>LD_LIBRARY_PATH</tt> accordingly):<br>
<code>load lib<i>myApplication</i>.so tclioc</code>
</li>
<li>
While setting up the IOC as usual (using <code>dbLoadDatabase</code>,
<code><i>myApplication</i>_registerRecordDeviceDriver</code>,
<code>dbLoadTemplate</code> or <code>dbLoadRecords</code>,
<code>iocInit</code>), it is possible to use Tcl language constructs.
This allows loops and conditionals, access to variables, etc.
</li>
<li>
At the end of the script, switch to interactive mode
(this is where TclX is required):<br>
<code>commandloop -prompt1 {puts -nonewline "epics> "}</code>
</li>
</ol>
<h3>Example startup script</h3>
<p>
</p>
<pre class="box">
#!/usr/bin/tcl
load libmyApplication.so tclioc
dbLoadDatabase myApplication.dbd
myApplication_registerRecordDeviceDriver
#create records using TCL programming
set scan "1 second"
for {set n 1} {$n <= 100} {incr n} {
dbLoadRecords example.template "number=$n,scan=$scan"
}
#set an EPICS variable
set asCaDebug 1
#some EPICS commands with output redirection
set logfile iocboot.log
iocInit > $logfile
dbnr 1 >> $logfile
dbl >> $logfile
# go interactive
commandloop -prompt1 {puts -nonewline "epics> "}
</pre>
<hr noshade size=1><small>
<span class="printlayout">Author:&nbsp;Dirk Zimoch&nbsp;&nbsp; Phone:&nbsp;+41&nbsp;56&nbsp;310&nbsp;5182&nbsp;&nbsp; Email:&nbsp;dirk.zimoch&#64;psi.&#99;&#104;&nbsp;&nbsp; Updated:&nbsp;02.11.2005&nbsp;&nbsp; </span>
Source:&nbsp;/afs/psi.ch/project/epics/webhosting/software/tclioc/index.php&nbsp;&nbsp;
</small>
</td></tr></table>
</body></html>