|
1 | 1 | Read data from an IOC |
2 | 2 | ====================== |
3 | 3 |
|
4 | | -This guide explains how to read data from an IOC in a separate Python program. |
| 4 | +This guide explains how to read data from an IOC in a separate Python program. |
5 | 5 |
|
6 | | -.. note:: |
7 | | - Please ensure your firewall allows both TCP and UDP traffic on ports 5064 and 5065. |
| 6 | +To start, run the `cothread` IOC from `../tutorials/creating-an-ioc` or the |
| 7 | +`asyncio` IOC from `use-asyncio-in-an-ioc` and leave it running at the |
| 8 | +interactive shell. |
| 9 | + |
| 10 | +Using Channel Access |
| 11 | +-------------------- |
| 12 | + |
| 13 | +.. note:: |
| 14 | + Please ensure your firewall allows both TCP and UDP traffic on ports 5064 and 5065. |
8 | 15 | These are used by EPICS for channel access to the PVs. |
9 | 16 |
|
| 17 | +We will read data from the IOC using this script: |
10 | 18 |
|
11 | | -To start, run the `cothread` IOC from `../tutorials/creating-an-ioc` or the |
12 | | -`asyncio` IOC from `use-asyncio-in-an-ioc` and leave it running at the |
13 | | -interactive shell. |
| 19 | +.. literalinclude:: ../examples/example_read_from_ioc_ca.py |
14 | 20 |
|
15 | | -We will read data from that IOC using this script: |
| 21 | +You can run this as:: |
16 | 22 |
|
17 | | -.. literalinclude:: ../examples/example_read_from_ioc.py |
| 23 | + python -i example_read_from_ioc_ca.py |
| 24 | + |
| 25 | +From the interactive command line you can now use the ``caget`` and ``caput`` functions to operate on |
| 26 | +the PVs exposed in the IOC. Another interesting command to try is:: |
| 27 | + |
| 28 | + camonitor("MY-DEVICE-PREFIX:AI", print) |
| 29 | + |
| 30 | +You should observe the value of ``AI`` being printed out, once per second, every time the PV value |
| 31 | +updates. |
| 32 | + |
| 33 | +Using PVAccess |
| 34 | +-------------- |
18 | 35 |
|
19 | 36 | .. 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. |
| 37 | + Please ensure your firewall allows both TCP and UDP traffic on ports 5075 and 5076. |
| 38 | + These are used by EPICS for PVAccess to the PVs. |
23 | 39 |
|
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:: |
| 40 | +We will read data from the IOC using this script: |
26 | 41 |
|
27 | | - camonitor("MY-DEVICE-PREFIX:AI", lambda val: print(val)) |
| 42 | +.. literalinclude:: ../examples/example_read_from_ioc_pva.py |
28 | 43 |
|
| 44 | +You can run this as:: |
29 | 45 |
|
30 | | -You should observe the value of ``AI`` being printed out, once per second, every time the PV value |
31 | | -updates. |
| 46 | + python -i example_read_from_ioc_pva.py |
| 47 | + |
| 48 | +From the interactive command line you can now use the ``ctx.get`` and ``ctx.put`` functions to operate on |
| 49 | +the PVs exposed in the IOC. Another interesting command to try is:: |
| 50 | + |
| 51 | + ctx.monitor("MY-DEVICE-PREFIX:AI", print) |
| 52 | + |
| 53 | +You should observe the value and timestamp of ``AI`` being printed out, once per second, every time the PV value |
| 54 | +updates. |
0 commit comments