Use soft records in an IOC

It is possible to use records with soft device support mixed with pythonSoftIOC records (with Python device support). This allows use of calc, fanout and other EPICS database soft records.

from softioc import builder, softioc
from softioc.builder import records

builder.SetDeviceName("XX-XX-XX-01")

py_record = builder.aOut("VAL1", initial_value=5, on_update=print)
soft_record = records.ao("VAL2", VAL=10)

calc = records.calc("CALC", CALC="A*B", INPA=builder.CP(py_record), B=1)

soft_record.OUT = builder.PP(calc.B)

builder.LoadDatabase()
softioc.iocInit()

softioc.interactive_ioc(globals())

The VAL1 record is created in the usual pythonSoftIOC way, with Python device support. You can set() it, and on_update will be called when you caput it.

The VAL2 record is created using the lower level softioc.builder.records object. You can dbpf it, and no Python will be called when you caput to it.

Note that the Device Name is shared between both kinds of records - both will have the same prefix.

We construct the calc record again using softioc.builder.records. This record will calculate A*B:

  • A is provided by the record pointed at by INPA, which is py_record, and the CP link causes it to be monitored, processing calc each time it updates.

  • B is initially set to 1. When soft_record processes, it sends its value to calc.B, and the PP link causes it to process.

Note

You could also use calc(SCAN="1 second", ...) instead of the PP and CP links, which would fetch the value periodically rather than just on change.

The output of this IOC can be examined by running this IOC in one terminal, and then modifying and running the example scripts found in Read data from an IOC. Try setting the value of either VAL1 or VAL2 and observe the effect on the CALC output.