|
1 | 1 | Create a Publishable IOC |
2 | | --------------------------- |
| 2 | +======================== |
3 | 3 |
|
4 | | -As the example script above shows, a single Python script can be an IOC. |
5 | | -However, to fit into the DLS framework for publishing IOCs in ``/dls_sw/prod`` a |
6 | | -bit more structure is needed. I recommend at least four files as shown: |
| 4 | +As seen in :doc:`../tutorials/creating-an-ioc`, a single Python script can be an IOC. |
| 5 | +It is also possible (and the most common situation) to have an entire Python module |
| 6 | +comprising an IOC. This guide explains both, as well as how to publish an IOC within |
| 7 | +the DLS environment. |
7 | 8 |
|
8 | | -``Makefile`` |
9 | | - This file is necessary in order to run ``dls-release.py``, and needs to have |
10 | | - both ``install`` and ``clean`` targets, but doesn't need to actually do |
11 | | - anything. Thus the following content for this file is enough:: |
12 | | - |
13 | | - install: |
14 | | - clean: |
15 | | - |
16 | | -``start-ioc`` |
17 | | - An executable file for starting the IOC needs to be created. I recommend |
18 | | - that this consist of the following boilerplate:: |
19 | | - |
20 | | - #!/bin/sh |
21 | | - |
22 | | - PYIOC_VER=2-6 |
23 | | - EPICS_VER=3.14.12.3 |
24 | | - |
25 | | - PYIOC=/dls_sw/prod/R$EPICS_VER/support/pythonSoftIoc/$PYIOC_VER/pythonIoc |
| 9 | +Single File IOC |
| 10 | +---------------- |
| 11 | +An IOC that is entirely contained within a single Python source file can be used as an |
| 12 | +IOC inside DLS simply by adding this shebang line:: |
26 | 13 |
|
27 | | - exec $PYIOC ioc_entry.py "$@" |
| 14 | + #!/dls_sw/prod/python3/RHEL7-x86_64/pythonIoc/prefix/bin/pythonIoc |
28 | 15 |
|
29 | | - Here I have given the startup script for the IOC the name ``ioc_entry.py``. |
30 | | - This name should be replaced by any appropriate name. |
31 | 16 |
|
32 | | -``ioc_entry.py`` |
33 | | - I recommend that the top level Python script used to launch the IOC contain |
34 | | - only ``pkg_resources.require`` statements, simple code to start the body |
35 | | - of the IOC, and it should end with standard code to start the IOC. The |
36 | | - following structure can be followed (here I've assumed that the rest of the |
37 | | - IOC is in a single file called ``ioc_body.py``:: |
| 17 | +IOC entry point for a module |
| 18 | +------------------------------ |
| 19 | +If your IOC is more complicated than one file, it is recommended to write a python |
| 20 | +module (including docs/tests/etc.). The Panda Blocks Client will be an example of |
| 21 | +this. |
38 | 22 |
|
39 | | - from pkg_resources import require |
40 | 23 |
|
41 | | - require('cothread==2.12') |
42 | | - require('epicsdbbuilder==1.0') |
43 | | - # Any other requires needed by this IOC |
| 24 | +Make an IOC publishable at DLS |
| 25 | +------------------------------ |
| 26 | +To make the IOC publishable, a makefile is required: |
44 | 27 |
|
45 | | - from softioc import softioc |
46 | | - |
47 | | - # Do whatever makes sense to create all the PVs and get ready to go |
48 | | - import ioc_body |
49 | | - ioc_body.initialise() |
50 | | - |
51 | | - # Start the IOC -- this is boilerplate |
52 | | - builder.LoadDatabase() |
53 | | - softioc.iocInit() |
54 | | - |
55 | | - # If activities need to be started after iocInit, now's the time |
56 | | - ioc_body.start() |
57 | | - |
58 | | - softioc.interactive_ioc(globals()) |
| 28 | +``Makefile`` |
| 29 | + This file is necessary in order to run ``dls-release.py``, and needs to have |
| 30 | + both ``install`` and ``clean`` targets, but doesn't need to actually do |
| 31 | + anything. Thus the following content for this file is enough:: |
59 | 32 |
|
60 | | - Note that *all* requires *must* occur in this initial startup file. |
| 33 | + install: |
| 34 | + clean: |
61 | 35 |
|
62 | | -The rest of the IOC |
63 | | - Of course, a Python script can be structured into any number of Python |
64 | | - modules. In the example above I have illustrated just one such module |
65 | | - called ``ioc_body.py`` with two entry points. |
0 commit comments