Skip to content

Commit 58d643e

Browse files
committed
rewrite ioc_changes2
1 parent 30a5784 commit 58d643e

File tree

2 files changed

+136
-15
lines changed

2 files changed

+136
-15
lines changed

docs/user/explanations/ioc-source.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ the following goals:
2121
they are not lost when the container is rebuilt or deleted
2222

2323
The details of which folders are mounted where in the container are
24-
shown here: `container-layout`_.
24+
shown here: `container-layout`.
2525

2626
The ioc-XXX project folder is found in the container at ``/workspaces/ioc-XXX``,
2727
along with all of it's peers (because the parent folder is mounted

docs/user/tutorials/ioc_changes2.rst

Lines changed: 135 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Some of the reasons for doing this are:
2020
want to add support for a second device, this is allowed but you should
2121
consider the alternative of creating a new Generic IOC.
2222
If you keep your Generic IOCs simple and focused on a single device, they
23-
will be smaller and there will be less of them. IOCs can still be
24-
linked via CA and this is preferable to recompiling a Generic IOC
23+
will be smaller and there will be less of them. IOCs' records can still be
24+
linked via CA links and this is preferable to recompiling a Generic IOC
2525
for every possible combination of devices. Using Kubernetes to
2626
manage multiple small services is cleaner than having a handful of
2727
monolithic services.
@@ -31,8 +31,8 @@ This tutorial will make some changes to the generic IOC ``ioc-adsimdetector``
3131
that you already used in earlier tutorials.
3232

3333
For this exercise we will work locally inside the ``ioc-adsimdetector``
34-
developer container. To discover how to fork repositories and push changes
35-
back to GitHub
34+
developer container. Following tutorials will show how to fork repositories
35+
and push changes back to GitHub
3636

3737
For this exercise we will be using an example IOC Instance to test our changes.
3838
Instead of working with a beamline repository, we will use the example ioc instance
@@ -62,14 +62,17 @@ The ``build`` script does two things.
6262
- it fetches the git submodule called ``ibek-support``. This submodule is shared
6363
between all the EPICS IOC container images and contains the support YAML files
6464
that tell ``ibek`` how to build support modules inside the container
65-
environment.
65+
environment and how to use them at runtime.
6666
- it builds the Generic IOC container image locally.
6767

6868
.. note::
6969

7070
The ``build`` script is a convenience script that is provided in the
7171
Generic IOC Template project. It is exactly equivalent to cloning
72-
with ``--recursive`` flag and then running ``ec dev build``.
72+
with ``--recursive`` flag and then running ``ec dev build``. Equally,
73+
opening a vscode dev container will also build the container for you, but it
74+
does require the ``ibek-support`` submodule to be present - using
75+
``--recursive`` flag to git clone ensures this.
7376

7477
Verify the Example IOC Instance is working
7578
------------------------------------------
@@ -81,9 +84,9 @@ that need to be done before you can run an IOC instance inside of it.
8184
- Select an IOC instance definition to run
8285

8386
The folder ``ioc`` inside of the ``ioc-adsimdetector`` is where the IOC source code
84-
resided. However the devcontainer always makes a symlink to this folder at
87+
resided. However our containers always make a symlink to this folder at
8588
``/epics/ioc``. This is so that it is always in the same place and can easily be
86-
found by ibek and the developer. Therefore you can build the binary with the
89+
found by ibek (and the developer!). Therefore you can build the binary with the
8790
following command:
8891

8992
.. code-block:: console
@@ -98,8 +101,7 @@ following command:
98101
source code built by its Dockerfile (``ioc-adsimdetector/Dockerfile``
99102
contains the same command).
100103

101-
For a detailed explanation of why this is the case see
102-
`ioc-source`
104+
For a detailed explanation of why this is the case see `ioc-source`
103105

104106
The IOC instance definition is a YAML file that tells ``ibek`` what the runtime
105107
assets (ie. EPICS DB and startup script) should look like. Previous tutorials
@@ -109,11 +111,9 @@ following command will select the example IOC instance:
109111

110112
.. code-block:: console
111113
112-
ibek dev instance /epics/ioc-adsimdetector/ioc_examples/bl01t-ea-ioc-02
114+
ibek dev instance /workspaces/ioc-adsimdetector/ioc_examples/bl01t-ea-ioc-02
113115
114-
In an earlier tutorial when learning about the dev container, we manually
115-
performed this step, see `choose-ioc-instance`. The above command does
116-
exactly the same thing: removes the existing config folder in ``/epics/ioc``
116+
The above command removes the existing config folder ``/epics/ioc/config`` and
117117
and symlinks in the chosen IOC instance definition's ``config`` folder.
118118

119119
Now run the IOC:
@@ -124,3 +124,124 @@ Now run the IOC:
124124
./start.sh
125125
126126
You should see an iocShell prompt and no error messages above.
127+
128+
Let us also make sure we can see the simulation images that the IOC is
129+
producing. For this we need the ``cd2v`` tool that we used earlier. You
130+
can use the same virtual environment that you created earlier, or create
131+
a new one and install again. Note that these commands are to be run
132+
in a terminal outside of the developer container.
133+
134+
.. code-block:: console
135+
136+
python3 -m venv cd2v
137+
source ~/cd2v/bin/activate
138+
pip install c2dataviewer
139+
140+
Run the ``cd2v`` tool and connect it to our IOCs PVA output:
141+
142+
.. code-block:: console
143+
144+
cd2v --pv BL01T-EA-TST-02:PVA:OUTPUT &
145+
146+
147+
Back inside the developer container, you can now start the detector and
148+
the PVA plugin, by opening a new terminal and running the following:
149+
150+
.. code-block:: console
151+
152+
caput BL01T-EA-TST-02:PVA:EnableCallbacks 1
153+
caput BL01T-EA-TST-02:CAM:Acquire 1
154+
155+
You should see the moving image in the ``cd2v`` window. We now have a working
156+
IOC instance that we can use to test our changes.
157+
158+
Making a change to the Generic IOC
159+
----------------------------------
160+
161+
One interesting way of changing a Generic IOC is to modify the support YAML
162+
for one of the support modules. The support YAML describes the ``entities`` that
163+
an IOC instance can make use of in its instance YAML file. This will be
164+
covered in much more detail in `generic_ioc`.
165+
166+
For this exercise we will make a change to the ``ioc-adsimdetector`` support
167+
YAML file. We will change the startup script that it generates so that the
168+
simulation detector is automatically started when the IOC starts.
169+
170+
To make this change we just need to have the startup script set the values
171+
of the records ``BL01T-EA-TST-02:CAM:Acquire`` and
172+
``BL01T-EA-TST-02:PVA:EnableCallbacks`` to 1.
173+
174+
To make this change, open the file
175+
``ibek-support/ADSimDetector/ADSimDetector.ibek.support.yaml``
176+
and add a ``post_init`` section just after the ``pre_init`` section:
177+
178+
.. code-block:: yaml
179+
180+
post_init:
181+
- type: text
182+
value: |
183+
dbpf {{P}}{{R}}Acquire 1
184+
185+
Next make a change to the file ``ibek-support/ADCore/ADCore.ibek.support.yaml``.
186+
Find the NDPvaPlugin section and also add a ``post_init`` section:
187+
188+
.. code-block:: yaml
189+
190+
post_init:
191+
- type: text
192+
value: |
193+
dbpf {{P}}{{R}}EnableCallbacks 1
194+
195+
196+
If you now go to the terminal where you ran your IOC, you can stop it with
197+
``Ctrl+C`` and then start it again with ``./start.sh``. You should see the
198+
following output at the end of the startup log:
199+
200+
.. code-block:: console
201+
202+
dbpf BL01T-EA-TST-02:CAM:Acquire 1
203+
DBF_STRING: "Acquire"
204+
dbpf BL01T-EA-TST-02:PVA:EnableCallbacks 1
205+
DBF_STRING: "Enable"
206+
epics>
207+
208+
You should also see the ``cd2v`` window update with the moving image again.
209+
210+
If you wanted to publish these changes you would have to commit both the
211+
``ibek-support`` submodule and the ``ioc-adsimdetector`` repository and push
212+
them in that order because of the sub-module dependency. But we won't be
213+
pushing these changes as they are just for demonstration purposes. In later
214+
tutorials we will cover making forks and doing pull requests for when you have
215+
changes to share back with the community.
216+
217+
Note: this is a slightly artificial example, as it would change the behaviour
218+
for all instances of a PVA plugin and a simDetector. In a real IOC you would
219+
do this on a per instance basis.
220+
221+
Let us quickly do the instance YAML change to demonstrate the correct approach
222+
to this auto-starting detector.
223+
224+
Undo the support yaml changes:
225+
226+
.. code-block:: console
227+
228+
cd /workspaces/ioc-adsimdetector/ibek-support
229+
git reset --hard
230+
231+
Add the following to
232+
``/workspaces/ioc-adsimdetector/ioc_examples/bl01t-ea-ioc-02/config/ioc.yaml``:
233+
234+
.. code-block:: yaml
235+
236+
- type: epics.dbpf
237+
pv: BL01T-EA-TST-02:CAM:Acquire
238+
value: "1"
239+
240+
- type: epics.dbpf
241+
pv: BL01T-EA-TST-02:PVA:EnableCallbacks
242+
value: "1"
243+
244+
Now restart the IOC and you should see the same behaviour as before. Here
245+
we have made the change on a per instance basis, and used the ``dbpf`` entity
246+
declared globally in ``ibek-support/_global/epics.ibek.support.yaml``.
247+

0 commit comments

Comments
 (0)