Questions about the simple example in the docs #150
-
I have some questions related to the simple example (shown below) that is given in the docs. # Import the basic framework components.
from softioc import softioc, builder
import cothread
# Set the record prefix
builder.SetDeviceName("MY-DEVICE-PREFIX")
# Create some records
ai = builder.aIn('AI', initial_value=5)
ao = builder.aOut('AO', initial_value=12.45, on_update=lambda v: ai.set(v))
# Boilerplate get the IOC started
builder.LoadDatabase()
softioc.iocInit()
# Start processes required to be run after iocInit
def update():
while True:
ai.set(ai.get() + 1)
cothread.Sleep(1)
cothread.Spawn(update)
# Finally leave the IOC running with an interactive shell.
softioc.interactive_ioc(globals()) An Also, is the use of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You are correct regarding The use of the |
Beta Was this translation helpful? Give feedback.
You are correct regarding
ao
, there is no need to assign it to a variable at all. It's a stylistic choice to keep the lines looking neater together and to indicate to users that this function does also return an object you can interact with.The use of the
globals()
function is important in making a Python interpreter that functions as one would expect. Try removing it and then inspectingai
- you'll find that the interpreter will tell you that it's undefined. By passing theglobals()
dict in here, users can access all their already defined variables in their IOC.