Read data from an IOC
This guide explains how to read data from an IOC in a separate Python program.
To start, run the Using the cothread Library IOC from Creating an IOC or the
asyncio IOC from Use asyncio in an IOC and leave it running at the
interactive shell.
Using Channel Access
Note
Please ensure your firewall allows both TCP and UDP traffic on ports 5064 and 5065. These are used by EPICS for channel access to the PVs.
We will read data from the IOC using this script:
from cothread.catools import caget, caput, camonitor
print(caget("MY-DEVICE-PREFIX:AI"))
print(caget("MY-DEVICE-PREFIX:AO"))
caput("MY-DEVICE-PREFIX:AO", "999")
print(caget("MY-DEVICE-PREFIX:AO"))
You can run this as:
python -i example_read_from_ioc_ca.py
From the interactive command line you can now use the caget and caput functions to operate on
the PVs exposed in the IOC. Another interesting command to try is:
camonitor("MY-DEVICE-PREFIX:AI", print)
You should observe the value of AI being printed out, once per second, every time the PV value
updates.
Using PVAccess
Note
Please ensure your firewall allows both TCP and UDP traffic on ports 5075 and 5076. These are used by EPICS for PVAccess to the PVs.
We will read data from the IOC using this script:
from p4p.client.cothread import Context
ctx = Context("pva")
print(ctx.get("MY-DEVICE-PREFIX:AI"))
print(ctx.get("MY-DEVICE-PREFIX:AO"))
ctx.put("MY-DEVICE-PREFIX:AO", "999")
print(ctx.get("MY-DEVICE-PREFIX:AO"))
You can run this as:
python -i example_read_from_ioc_pva.py
From the interactive command line you can now use the ctx.get and ctx.put functions to operate on
the PVs exposed in the IOC. Another interesting command to try is:
ctx.monitor("MY-DEVICE-PREFIX:AI", print)
You should observe the value and timestamp of AI being printed out, once per second, every time the PV value
updates.