Skip to content

Commit f04dbc3

Browse files
Fix README. Add asyncio example.
1 parent 3708bea commit f04dbc3

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

README.rst

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,36 @@ Source code https://github.com/dls-controls/pythonIoc
1515
Documentation https://dls-controls.github.io/pythonIoc
1616
============== ==============================================================
1717

18-
A simple example of the use of this library is the following:
18+
A simple example of the use of this library:
1919

20-
.. literalinclude:: examples/example_cothread_ioc.py
20+
.. code:: python
2121
22+
# Import the basic framework components.
23+
from softioc import softioc, builder
24+
import cothread
25+
26+
# Set the record prefix
27+
builder.SetDeviceName("MY-DEVICE-PREFIX")
28+
29+
# Create some records
30+
ai = builder.aIn('AI', initial_value=5)
31+
ao = builder.aOut('AO', initial_value=12.45, on_update=lambda v: ai.set(v))
32+
33+
# Boilerplate get the IOC started
34+
builder.LoadDatabase()
35+
softioc.iocInit()
36+
37+
# Start processes required to be run after iocInit
38+
def update():
39+
while True:
40+
ai.set(ai.get() + 1)
41+
cothread.Sleep(1)
42+
43+
44+
cothread.Spawn(update)
45+
46+
# Finally leave the IOC running with an interactive shell.
47+
softioc.interactive_ioc(globals())
2248
2349
.. |code_ci| image:: https://github.com/dls-controls/pythonIoc/workflows/Code%20CI/badge.svg?branch=master
2450
:target: https://github.com/dls-controls/pythonIoc/actions?query=workflow%3A%22Code+CI%22
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Import the basic framework components.
2+
import atexit
3+
from softioc import softioc, builder
4+
from aioca import caget, caput, _catools
5+
import asyncio
6+
7+
# Set the record prefix
8+
builder.SetDeviceName("MY-DEVICE-PREFIX")
9+
10+
# Create some records
11+
ai = builder.aIn('AI', initial_value=5)
12+
13+
async def update(val):
14+
ai.set(val)
15+
16+
ao = builder.aOut('AO', initial_value=12.45, on_update=update)
17+
18+
# Boilerplate get the IOC started
19+
builder.LoadDatabase()
20+
softioc.iocInit()
21+
22+
# Perform some reading/writing to the PVs
23+
async def do_read_write():
24+
ai_val = await caget("MY-DEVICE-PREFIX:AI")
25+
await caput("MY-DEVICE-PREFIX:AO", "999")
26+
27+
28+
asyncio.run(do_read_write())
29+
30+

0 commit comments

Comments
 (0)