Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions docs/reference/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,20 @@ Test Facilities`_ documentation for more details of each function.
For all of these functions any EPICS database field can be assigned a value by
passing it as a keyword argument for the corresponding field name (in upper
case) or by assigning to the corresponding field of the returned record object.
Thus the ``**fields`` argument in all of the definitions below refers to both the
optional keyword arguments listed above and record field names.
Thus the ``**fields`` argument in all of the definitions below refers to both
the optional keyword arguments listed above and record field names.

All functions return a wrapped `ProcessDeviceSupportIn` or
`ProcessDeviceSupportOut` instance.

.. function::
aIn(name, LOPR=None, HOPR=None, **fields)
aOut(name, LOPR=None, HOPR=None, **fields)
aIn(name, LOPR=None, HOPR=None, EGU=None, PREC=None, **fields)
aOut(name, DRVL=None, DRVH=None, EGU=None, PREC=None, **fields)

Create ``ai`` and ``ao`` records. The lower and upper limits for the
record can be specified, and if specified these will also be used to set the
``EGUL`` and ``EGUF`` fields.
Create ``ai`` and ``ao`` records. The lower and upper limits for the record
can be specified. For ``ao`` records the ``LOPR`` and ``HOPR`` fields will
be set by default to the values of the ``DRVL`` and ``DRVH`` fields
respectively.

.. function::
boolIn(name, ZNAM=None, ONAM=None, **fields)
Expand All @@ -255,6 +256,10 @@ All functions return a wrapped `ProcessDeviceSupportIn` or
longOut(name, DRVL=None, DRVH=None, EGU=None, **fields)

Create ``longin`` and ``longout`` records with specified limits and units.
The lower and upper display limits for the record can be specified. For
``longout`` records the ``LOPR`` and ``HOPR`` fields will be set by default
to the values of the ``DRVL`` and ``DRVH`` fields respectively.


.. function::
stringIn(name, **fields)
Expand Down
69 changes: 41 additions & 28 deletions softioc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,52 @@
# The SCAN field for all input records defaults to I/O Intr.


def _in_record(record, name, **fields):
'''For input records we provide some automatic extra features: scanning,
initialisation as appropriate, and blocking puts from outside the IOC.'''

def _set_in_defaults(fields):
fields.setdefault('SCAN', 'I/O Intr')
if 'initial_value' in fields:
fields.setdefault('PINI', 'YES')
fields.setdefault('PINI', 'YES')
fields.setdefault('DISP', 1)
return getattr(PythonDevice, record)(name, **fields)

def _set_out_defaults(fields):
Comment thread
Araneidae marked this conversation as resolved.
fields.setdefault('OMSL', 'supervisory')

# For longout and ao we want DRV{L,H} to match {L,H}OPR by default
def _set_scalar_out_defaults(fields, DRVL, DRVH):
Comment thread
Araneidae marked this conversation as resolved.
fields['DRVL'] = DRVL
fields['DRVH'] = DRVH
fields.setdefault('LOPR', DRVL)
fields.setdefault('HOPR', DRVH)


def aIn(name, LOPR=None, HOPR=None, **fields):
return _in_record(
'ai', name, LOPR = LOPR, HOPR = HOPR, **fields)
def aIn(name, LOPR=None, HOPR=None, EGU=None, PREC=None, **fields):
_set_in_defaults(fields)
return PythonDevice.ai(
name, LOPR = LOPR, HOPR = HOPR, EGU = EGU, PREC = PREC, **fields)

def aOut(name, LOPR=None, HOPR=None, **fields):
fields.setdefault('DRVL', LOPR)
fields.setdefault('DRVH', HOPR)
return PythonDevice.ao(
name, LOPR = LOPR, HOPR = HOPR, **fields)
def aOut(name, DRVL=None, DRVH=None, EGU=None, PREC=None, **fields):
_set_out_defaults(fields)
_set_scalar_out_defaults(fields, DRVL, DRVH)
return PythonDevice.ao(name, EGU = EGU, PREC = PREC, **fields)


def boolIn(name, ZNAM=None, ONAM=None, **fields):
return _in_record('bi', name, ZNAM = ZNAM, ONAM = ONAM, **fields)
_set_in_defaults(fields)
return PythonDevice.bi(name, ZNAM = ZNAM, ONAM = ONAM, **fields)

def boolOut(name, ZNAM=None, ONAM=None, **fields):
return PythonDevice.bo(
name, OMSL = 'supervisory', ZNAM = ZNAM, ONAM = ONAM, **fields)
_set_out_defaults(fields)
return PythonDevice.bo(name, ZNAM = ZNAM, ONAM = ONAM, **fields)


def longIn(name, LOPR=None, HOPR=None, EGU=None, **fields):
_set_in_defaults(fields)
fields.setdefault('MDEL', -1)
return _in_record(
'longin', name, EGU = EGU, LOPR = LOPR, HOPR = HOPR, **fields)
return PythonDevice.longin(
name, LOPR = LOPR, HOPR = HOPR, EGU = EGU, **fields)

def longOut(name, DRVL=None, DRVH=None, EGU=None, **fields):
return PythonDevice.longout(
name, OMSL = 'supervisory', DRVL = DRVL, DRVH = DRVH, EGU = EGU,
**fields)
_set_out_defaults(fields)
_set_scalar_out_defaults(fields, DRVL, DRVH)
return PythonDevice.longout(name, EGU = EGU, **fields)


# Field name prefixes for mbbi/mbbo records.
Expand Down Expand Up @@ -92,17 +99,21 @@ def process_value(prefix, value, option, severity=None):

def mbbIn(name, *options, **fields):
_process_mbb_values(options, fields)
return _in_record('mbbi', name, **fields)
_set_in_defaults(fields)
return PythonDevice.mbbi(name, **fields)

def mbbOut(name, *options, **fields):
_process_mbb_values(options, fields)
return PythonDevice.mbbo(name, OMSL = 'supervisory', **fields)
_set_out_defaults(fields)
return PythonDevice.mbbo(name, **fields)


def stringIn(name, **fields):
return _in_record('stringin', name, **fields)
_set_in_defaults(fields)
return PythonDevice.stringin(name, **fields)

def stringOut(name, **fields):
_set_out_defaults(fields)
return PythonDevice.stringout(name, **fields)

def Action(name, **fields):
Expand Down Expand Up @@ -204,7 +215,8 @@ def _waveform(value, fields):

def Waveform(name, *value, **fields):
_waveform(value, fields)
return _in_record('waveform', name, **fields)
_set_in_defaults(fields)
return PythonDevice.waveform(name, **fields)

WaveformIn = Waveform

Expand Down Expand Up @@ -232,7 +244,8 @@ def _long_string(fields):

def longStringIn(name, **fields):
_long_string(fields)
return _in_record('long_stringin', name, **fields)
_set_in_defaults(fields)
return PythonDevice.long_stringin(name, **fields)

def longStringOut(name, **fields):
_long_string(fields)
Expand Down
5 changes: 5 additions & 0 deletions tests/expected_records.db
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ record(ai, "TS-DI-TEST-01:AI")
record(ao, "TS-DI-TEST-01:AO")
{
field(DTYP, "Python")
field(OMSL, "supervisory")
field(OUT, "@TS-DI-TEST-01:AO")
}

Expand Down Expand Up @@ -107,13 +108,16 @@ record(longout, "TS-DI-TEST-01:SINN")
field(DRVH, "1024")
field(DRVL, "0")
field(DTYP, "Python")
field(HOPR, "1024")
field(LOPR, "0")
field(OMSL, "supervisory")
field(OUT, "@TS-DI-TEST-01:SINN")
}

record(ao, "TS-DI-TEST-01:SINP")
{
field(DTYP, "Python")
field(OMSL, "supervisory")
field(OUT, "@TS-DI-TEST-01:SINP")
}

Expand All @@ -129,6 +133,7 @@ record(stringin, "TS-DI-TEST-01:STRINGIN")
record(stringout, "TS-DI-TEST-01:STRINGOUT")
{
field(DTYP, "Python")
field(OMSL, "supervisory")
field(OUT, "@TS-DI-TEST-01:STRINGOUT")
}

Expand Down
10 changes: 1 addition & 9 deletions tests/test_record_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,16 +591,8 @@ def test_value_post_init_set(self):
"""Test that records provide the expected values on get calls when using
.set() before IOC initialisation and caget after initialisation"""

# Various conditions mean we cannot use the entire list of cases
filtered_list = []
for item in record_values_list:
# .set() on In records doesn't update correctly.
# pythonSoftIOC issue #67
if item[1] not in in_records:
filtered_list.append(item)

run_test_function(
filtered_list, SetValueEnum.SET_BEFORE_INIT, GetValueEnum.CAGET
record_values_list, SetValueEnum.SET_BEFORE_INIT, GetValueEnum.CAGET
)

@requires_cothread
Expand Down