Skip to content

Commit ebe736b

Browse files
New how-to read from an IOC. Some touchups to other work.
1 parent 4d7f891 commit ebe736b

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from softioc import softioc
2+
from cothread.catools import caget, caput, camonitor
3+
4+
print(caget("MY-DEVICE-PREFIX:AI"))
5+
print(caget("MY-DEVICE-PREFIX:AO"))
6+
print(caput("MY-DEVICE-PREFIX:AO", "999"))
7+
print(caget("MY-DEVICE-PREFIX:AO"))
8+
9+
def print_val(value: float):
10+
print(value)
11+
12+
softioc.interactive_ioc(globals())

docs/how-to/read-data-from-ioc.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Read data from an IOC
2+
======================
3+
4+
This guide explains how to read data from an IOC from a separate Python program.
5+
6+
.. note::
7+
Please ensure your firewall allows both TCP and UDP traffic on ports 5064 and 5065.
8+
These are used by EPICS for channel access to the PVs.
9+
10+
11+
To start, run the :mod:`cothread` IOC from :doc:`../tutorials/creating-an-ioc` or the
12+
:mod:`asyncio` IOC from :doc:`use-asyncio-in-an-ioc` and leave it running at the
13+
interactive shell.
14+
15+
We will read data from that IOC using this script:
16+
17+
.. literalinclude:: ../examples/example_read_from_ioc.py
18+
19+
.. note::
20+
You may see warnings regarding the missing "caRepeater" program. This is an EPICS tool
21+
that is used to track when PVs start and stop. It is not required for this simple example,
22+
and so the warning can be ignored.
23+
24+
From the interactive command line you can now use the ``caget`` and ``caput`` functions to operate on
25+
the PVs exposed in the IOC. Another interesting command to try is::
26+
27+
camonitor("MY-DEVICE-PREFIX:AI", print_val)
28+
29+
30+
You should observe the value of ``AI`` being printed out, once per second, every time the PVs value
31+
updates.

docs/how-to/use-asyncio-in-an-ioc.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ an IOC.
1313

1414

1515
The ``dispatcher`` is created and passed to :func:`~softioc.softioc.iocInit`. This is what
16-
allows the use of :mod:`asyncio` functions in this IOC.
16+
allows the use of :mod:`asyncio` functions in this IOC. It contains a new event loop to handle
17+
this.
1718

1819
The ``async update`` function will increment the value of ``ai`` once per second,
1920
sleeping that coroutine between updates.
@@ -28,5 +29,5 @@ shell open. The values of the PVs can be queried using the methods defined in th
2829
Asynchronous Channel Access
2930
---------------------------
3031

31-
PVs can be retrieved in an asynchronous manner by using the :py:mod:`aioca` module.
32-
It provides ``await``-able implementations of ``caget``, ``caput``, etc.
32+
PVs can be retrieved externally from a PV in an asynchronous manner by using the :py:mod:`aioca` module.
33+
It provides ``await``-able implementations of ``caget``, ``caput``, etc. See that module for more information.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Table Of Contents
6060

6161
how-to/use-asyncio-in-an-ioc
6262
how-to/make-publishable-ioc
63+
how-to/read-data-from-ioc
6364

6465
.. toctree::
6566
:caption: Explanations

0 commit comments

Comments
 (0)