Builder calls from module class #128
-
I'm trying to create an IOC dynamically chosen from set of device scripts. This means I'm trying to do builder calls in a module called by my main function using importlib. I can call the module to create the PVs and read the created PVs from the main function. But only before I call builder.LoadDatabase(), after which all the created PV instances are replaced with 'None.' I assume I need to pass the builder into the called module somehow, but I could use some advice as to how. I include a barebones example below. Thanks so much for any advice you might have. from softioc import softioc, builder, asyncio_dispatcher
import importlib
import asyncio
async def main():
dispatcher = asyncio_dispatcher.AsyncioDispatcher()
builder.SetDeviceName('device_name')
d = DeviceIOC()
print(d.device.pvs['Test']) # Prints the name of the PV
builder.LoadDatabase()
print(d.device.pvs['Test']) # Prints "None"
softioc.iocInit(dispatcher)
async def loop():
while True:
await d.loop()
dispatcher(loop)
softioc.interactive_ioc(globals())
class DeviceIOC():
def __init__(self):
self.module = importlib.import_module('test_module')
self.device = self.module.Device()
async def loop(self):
await asyncio.sleep(1)
if __name__ == "__main__":
asyncio.run(main()) This is an example module file it will call, 'test_module': from softioc import builder
class Device():
def __init__(self):
self.pvs = {}
self.pvs['Test'] = builder.aIn('Test') |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think you're just running into an oddity with how the When you call |
Beta Was this translation helpful? Give feedback.
I think you're just running into an oddity with how the
__str__()
method on thebuilder.aIn
(and other record types) is stringifying the object. If you doprint(repr(d.device.pvs['Test']))
you'll see that you do still have the created instance.When you call
builder.LoadDatabase()
, under the covers we set some attributes to None to indicate that no more records can be created. This is what appears to be being printed at the moment.