File tree Expand file tree Collapse file tree 2 files changed +58
-2
lines changed
Expand file tree Collapse file tree 2 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -15,10 +15,36 @@ Source code https://github.com/dls-controls/pythonIoc
1515Documentation 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
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments